chore: 初始化仓库(零源工具箱 0.1.0 基线)
- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎) - Wails v3 设置进程 cmd/settings(独立 module) - 监督进程 cmd/watchdog(-supervise 异常重启) - 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/ - 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
This commit is contained in:
commit
0a1c1e82ea
188 files changed
+19926
No files matched your search
@@ -0,0 +1,5 @@
|
||||
# Refuse to install package versions published less than 7 days (10080 minutes)
|
||||
# ago, reducing exposure to freshly compromised or malicious releases.
|
||||
# Honoured by pnpm and bun; npm currently has no native support and ignores it,
|
||||
# so this is harmless today and forward-compatible.
|
||||
minimum-release-age=10080
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -0,0 +1,18 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
|
||||
|
||||
## Type Support For `.vue` Imports in TS
|
||||
|
||||
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
|
||||
|
||||
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
|
||||
|
||||
1. Disable the built-in TypeScript Extension
|
||||
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
|
||||
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
|
||||
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
|
||||
@@ -0,0 +1,9 @@
|
||||
//@ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Create as $Create } from "@wailsio/runtime";
|
||||
|
||||
Object.freeze($Create.Events);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
@@ -0,0 +1,37 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* ConfigService 为前端提供配置读写能力。
|
||||
* 通过 Wails 绑定,前端可直接调用其导出方法。
|
||||
* @module
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Call as $Call, CancellablePromise as $CancellablePromise } from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
/**
|
||||
* Load 读取当前配置。配置文件缺失时返回错误,前端引导用户先运行主程序。
|
||||
*/
|
||||
export function Load(): $CancellablePromise<$models.AppConfig | null> {
|
||||
return $Call.ByID(1374598707);
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta 返回静态元数据(触发器/动作类型清单)。
|
||||
*/
|
||||
export function Meta(): $CancellablePromise<$models.Meta | null> {
|
||||
return $Call.ByID(3472161870);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save 校验并原子保存配置。返回校验警告(不阻塞保存)与错误。
|
||||
*/
|
||||
export function Save(cfg: $models.Config | null): $CancellablePromise<string[] | null> {
|
||||
return $Call.ByID(2730444782, cfg);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
import * as ConfigService from "./configservice.js";
|
||||
export {
|
||||
ConfigService
|
||||
};
|
||||
|
||||
export type {
|
||||
ActionConfig,
|
||||
AppConfig,
|
||||
ConditionConfig,
|
||||
Config,
|
||||
GlobalConfig,
|
||||
Meta,
|
||||
Rule,
|
||||
TriggerConfig
|
||||
} from "./models.js";
|
||||
@@ -0,0 +1,77 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* ActionConfig 为动作配置。
|
||||
*/
|
||||
export interface ActionConfig {
|
||||
"type": string;
|
||||
"params": { [_ in string]?: any } | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* AppConfig 为返回给前端的完整配置视图(含可选元数据)。
|
||||
*/
|
||||
export interface AppConfig {
|
||||
"config": Config | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionConfig 为条件配置(MVP 仅空列表)。
|
||||
*/
|
||||
export interface ConditionConfig {
|
||||
"type": string;
|
||||
"params": { [_ in string]?: any } | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Config 为配置根结构(版本 1),与主进程一致。
|
||||
*/
|
||||
export interface Config {
|
||||
"version": number;
|
||||
"global": GlobalConfig;
|
||||
"rules": Rule[] | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* GlobalConfig 为全局设置。
|
||||
*/
|
||||
export interface GlobalConfig {
|
||||
"enabled": boolean;
|
||||
"theme": string;
|
||||
"log_level": string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta 为前端下拉与展示所需的静态元数据。
|
||||
*/
|
||||
export interface Meta {
|
||||
"trigger_types": { [_ in string]?: string } | null;
|
||||
"action_types": { [_ in string]?: string } | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rule 为一条规则。
|
||||
*/
|
||||
export interface Rule {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"enabled": boolean;
|
||||
"priority": number;
|
||||
"trigger": TriggerConfig;
|
||||
"conditions"?: ConditionConfig[] | null;
|
||||
"actions": ActionConfig[] | null;
|
||||
"cooldown_ms": number;
|
||||
|
||||
/**
|
||||
* Fullscreen 全屏行为:"" / "ignore"(默认,全屏前台窗口时忽略)/ "allow"(豁免)。
|
||||
*/
|
||||
"fullscreen"?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TriggerConfig 为触发器配置。JSON 采用扁平形式(与主进程一致):
|
||||
*
|
||||
* {"type": "mouse_corner", "corner": "bottom_left", "screen": "all"}
|
||||
*/
|
||||
export type TriggerConfig = any;
|
||||
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/png" href="/logo.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<link rel="stylesheet" href="/style.css" />
|
||||
<title>零源工具箱设置</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
// npm EPERM 诊断:直接测试 node 写文件
|
||||
const fs = require('fs');
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
const r = fn();
|
||||
console.log(`${name}: OK ${r ? JSON.stringify(r) : ''}`);
|
||||
} catch (e) {
|
||||
console.log(`${name}: FAIL ${e.code || ''} ${e.message.split('\n')[0]}`);
|
||||
}
|
||||
}
|
||||
|
||||
test('open package-lock.json (r+)', () => { const fd = fs.openSync('package-lock.json', 'r+'); fs.closeSync(fd); return 'opened'; });
|
||||
test('write package-lock.json (w)', () => { fs.writeFileSync('package-lock.json', fs.readFileSync('package-lock.json')); return 'written'; });
|
||||
test('open package.json (r+)', () => { const fd = fs.openSync('package.json', 'r+'); fs.closeSync(fd); return 'opened'; });
|
||||
test('write new file _node_test.tmp', () => { fs.writeFileSync('_node_test.tmp', 'x'); fs.unlinkSync('_node_test.tmp'); return 'written+deleted'; });
|
||||
test('rename package-lock.json', () => { fs.renameSync('package-lock.json', 'package-lock.json.bak'); fs.renameSync('package-lock.json.bak', 'package-lock.json'); return 'renamed'; });
|
||||
Generated
+1286
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build:dev": "vue-tsc && vite build --minify false --mode development",
|
||||
"build": "vue-tsc && vite build --mode production",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wailsio/runtime": "latest",
|
||||
"vue": "^3.2.45"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"typescript": "^4.9.3",
|
||||
"vite": "^8.0.5",
|
||||
"vue-tsc": "^1.0.11"
|
||||
}
|
||||
}
|
||||
test
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 187 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
@@ -0,0 +1,31 @@
|
||||
:root {
|
||||
--bg: #f6f7f9;
|
||||
--bg-top: #ffffff;
|
||||
--bg-side: #fafbfc;
|
||||
--card: #ffffff;
|
||||
--input-bg: #ffffff;
|
||||
--border: #d9dde3;
|
||||
--text: #24292f;
|
||||
--muted: #6a737d;
|
||||
--accent: #1f6feb;
|
||||
}
|
||||
[data-theme='dark'] {
|
||||
--bg: #1b1f24;
|
||||
--bg-top: #21262d;
|
||||
--bg-side: #1e2329;
|
||||
--card: #262c33;
|
||||
--input-bg: #2d333b;
|
||||
--border: #3d444d;
|
||||
--text: #e6edf3;
|
||||
--muted: #8b949e;
|
||||
--accent: #4c8dff;
|
||||
}
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
font-family: 'Segoe UI', 'Microsoft YaHei', system-ui, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
#app { height: 100%; }
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
@@ -0,0 +1,394 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ConfigService, Config, Rule, ActionConfig, GlobalConfig } from '../bindings/zerorigin-settings'
|
||||
import { ACTION_DEFAULTS, ACTION_SCHEMA, TRIGGER_DEFAULTS, TRIGGER_SCHEMA, ParamField } from './types'
|
||||
|
||||
const loading = ref(true)
|
||||
const errorMsg = ref('')
|
||||
const notice = ref('')
|
||||
const warnings = ref<string[]>([])
|
||||
|
||||
const config = reactive<Config>({
|
||||
version: 1,
|
||||
global: { enabled: true, theme: 'system', log_level: 'info' },
|
||||
rules: [],
|
||||
})
|
||||
const meta = reactive<{ trigger_types: Record<string, string>; action_types: Record<string, string> }>({
|
||||
trigger_types: {},
|
||||
action_types: {},
|
||||
})
|
||||
|
||||
const selectedId = ref<string | null>(null)
|
||||
const editing = reactive<{ rule: Rule | null }>({ rule: null })
|
||||
|
||||
const selected = computed(() => (config.rules ?? []).find(r => r.id === selectedId.value) ?? null)
|
||||
const rules = computed(() => config.rules ?? [])
|
||||
|
||||
// 主题(跟随系统/浅色/深色)
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
function applyTheme(theme: string) {
|
||||
let dark = theme === 'dark'
|
||||
if (theme === 'system') dark = prefersDark.matches
|
||||
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const appCfg = await ConfigService.Load()
|
||||
if (appCfg && appCfg.config) {
|
||||
Object.assign(config, appCfg.config)
|
||||
applyTheme(config.global.theme)
|
||||
if ((config.rules ?? []).length > 0) {
|
||||
selectedId.value = (config.rules ?? [])[0].id
|
||||
editing.rule = { ...(config.rules ?? [])[0] }
|
||||
}
|
||||
}
|
||||
const m = await ConfigService.Meta()
|
||||
if (m) Object.assign(meta, m)
|
||||
} catch (e: any) {
|
||||
errorMsg.value = String(e?.message ?? e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
onMounted(load)
|
||||
|
||||
function selectRule(id: string) {
|
||||
selectedId.value = id
|
||||
const r = (config.rules ?? []).find(x => x.id === id)
|
||||
editing.rule = r ? JSON.parse(JSON.stringify(r)) : null
|
||||
}
|
||||
|
||||
function newRule() {
|
||||
const id = 'rule-' + Date.now().toString(36)
|
||||
const rule: Rule = {
|
||||
id,
|
||||
name: '新规则',
|
||||
enabled: true,
|
||||
priority: 100,
|
||||
trigger: { type: 'mouse_corner', params: { ...TRIGGER_DEFAULTS.mouse_corner } },
|
||||
actions: [{ type: 'volume_up', params: { ...ACTION_DEFAULTS.volume_up } }],
|
||||
cooldown_ms: 800,
|
||||
}
|
||||
config.rules = [...(config.rules ?? []), rule]
|
||||
selectRule(id)
|
||||
}
|
||||
|
||||
function removeRule(id: string) {
|
||||
config.rules = (config.rules ?? []).filter(r => r.id !== id)
|
||||
if (selectedId.value === id) {
|
||||
selectedId.value = null
|
||||
editing.rule = null
|
||||
}
|
||||
}
|
||||
|
||||
function onTriggerTypeChange() {
|
||||
if (!editing.rule) return
|
||||
const t = editing.rule!.trigger.type
|
||||
editing.rule!.trigger.params = { ...(TRIGGER_DEFAULTS[t] ?? {}) }
|
||||
}
|
||||
|
||||
function addAction() {
|
||||
if (!editing.rule) return
|
||||
const type = 'volume_up'
|
||||
editing.rule!.actions = [...(editing.rule!.actions ?? []), { type, params: { ...ACTION_DEFAULTS[type] } }]
|
||||
}
|
||||
|
||||
function onActionTypeChange(a: ActionConfig) {
|
||||
a.params = { ...(ACTION_DEFAULTS[a.type] ?? {}) }
|
||||
}
|
||||
|
||||
function removeAction(idx: number) {
|
||||
if (!editing.rule) return
|
||||
if (editing.rule!.actions) editing.rule!.actions.splice(idx, 1)
|
||||
}
|
||||
|
||||
function paramVal(rule: Rule | null, field: ParamField): any {
|
||||
return rule?.trigger.params?.[field.key]
|
||||
}
|
||||
function setParam(rule: Rule | null, field: ParamField, val: string | number | boolean) {
|
||||
if (!rule) return
|
||||
if (!rule.trigger.params) rule.trigger.params = {}
|
||||
rule.trigger.params[field.key] = field.type === 'number' ? Number(val) : val
|
||||
}
|
||||
function actionParam(a: ActionConfig, key: string): any {
|
||||
return a?.params?.[key]
|
||||
}
|
||||
function setActionParam(a: ActionConfig, field: ParamField, val: string | number | boolean) {
|
||||
if (!a.params) a.params = {}
|
||||
a.params[field.key] = field.type === 'number' ? Number(val) : val
|
||||
}
|
||||
|
||||
function triggerDesc(r: Rule): string {
|
||||
const label = meta.trigger_types[r.trigger.type] ?? r.trigger.type
|
||||
const p = r.trigger.params ?? {}
|
||||
const extra: string[] = []
|
||||
if (r.trigger.type === 'mouse_corner' && p.corner) extra.push(String(p.corner))
|
||||
if (r.trigger.type === 'mouse_edge_wheel' && p.edge) extra.push(String(p.edge) + (p.direction ? '/' + p.direction : ''))
|
||||
if (r.trigger.type === 'hotkey' && p.hotkey) extra.push(String(p.hotkey))
|
||||
return extra.length ? `${label}(${extra.join(',')})` : label
|
||||
}
|
||||
|
||||
function actionDesc(a: ActionConfig): string {
|
||||
return meta.action_types[a.type] ?? a.type
|
||||
}
|
||||
|
||||
async function save() {
|
||||
notice.value = ''
|
||||
warnings.value = []
|
||||
// 把编辑中的规则回写
|
||||
if (editing.rule && selectedId.value) {
|
||||
const idx = (config.rules ?? []).findIndex(r => r.id === selectedId.value)
|
||||
if (idx >= 0 && config.rules) config.rules[idx] = JSON.parse(JSON.stringify(editing.rule))
|
||||
}
|
||||
try {
|
||||
warnings.value = (await ConfigService.Save({ ...config, global: { ...config.global } })) ?? []
|
||||
notice.value = warnings.value.length ? '已保存(有警告,见下方)' : '已保存,主进程将自动生效'
|
||||
} catch (e: any) {
|
||||
notice.value = '保存失败:' + String(e?.message ?? e)
|
||||
}
|
||||
}
|
||||
|
||||
function setGlobalEnabled(v: boolean) {
|
||||
config.global.enabled = v
|
||||
}
|
||||
function setTheme(v: string) {
|
||||
config.global.theme = v
|
||||
applyTheme(v)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app">
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<h1>零源工具箱</h1>
|
||||
<span class="subtitle">设置</span>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label class="switch-label">
|
||||
<span>已启用</span>
|
||||
<input type="checkbox" :checked="config.global.enabled" @change="e => setGlobalEnabled((e.target as HTMLInputElement).checked)" />
|
||||
</label>
|
||||
<select :value="config.global.theme" @change="e => setTheme((e.target as HTMLSelectElement).value)" title="主题">
|
||||
<option value="system">跟随系统</option>
|
||||
<option value="light">浅色</option>
|
||||
<option value="dark">深色</option>
|
||||
</select>
|
||||
<button class="primary" :disabled="loading" @click="save">保存</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="errorMsg" class="error-banner">{{ errorMsg }}</div>
|
||||
<div v-if="notice" class="notice-banner">{{ notice }}</div>
|
||||
<div v-if="warnings.length" class="warn-banner">
|
||||
<div v-for="w in warnings" :key="w">{{ w }}</div>
|
||||
</div>
|
||||
|
||||
<main v-if="!loading" class="content">
|
||||
<!-- 规则列表 -->
|
||||
<section class="rules-pane">
|
||||
<div class="pane-head">
|
||||
<h2>规则({{ rules.length }})</h2>
|
||||
<button class="ghost" @click="newRule">+ 新建</button>
|
||||
</div>
|
||||
<ul class="rule-list">
|
||||
<li
|
||||
v-for="r in rules"
|
||||
:key="r.id"
|
||||
:class="['rule-card', { active: r.id === selectedId }]"
|
||||
@click="selectRule(r.id)"
|
||||
>
|
||||
<div class="rule-main">
|
||||
<div class="rule-name">
|
||||
<span :class="['dot', r.enabled ? 'on' : 'off']"></span>
|
||||
<span class="name">{{ r.name || r.id }}</span>
|
||||
</div>
|
||||
<div class="rule-desc">{{ triggerDesc(r) }} → {{ (r.actions ?? []).map(actionDesc).join('、') }}</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="删除" @click.stop="removeRule(r.id)">✕</button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="rules.length === 0" class="empty">还没有规则,点击“新建”添加。</p>
|
||||
</section>
|
||||
|
||||
<!-- 编辑面板 -->
|
||||
<section v-if="selected && editing.rule" class="editor-pane">
|
||||
<h2>编辑规则</h2>
|
||||
|
||||
<div class="field-grid">
|
||||
<label class="field">
|
||||
<span>名称</span>
|
||||
<input v-model="editing.rule!.name" type="text" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>优先级</span>
|
||||
<input v-model.number="editing.rule!.priority" type="number" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>冷却 (ms)</span>
|
||||
<input v-model.number="editing.rule!.cooldown_ms" type="number" min="0" />
|
||||
</label>
|
||||
<label class="field check">
|
||||
<input type="checkbox" v-model="editing.rule!.enabled" />
|
||||
<span>启用此规则</span>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>全屏行为</span>
|
||||
<select v-model="editing.rule!.fullscreen">
|
||||
<option value="">全屏下忽略(默认)</option>
|
||||
<option value="allow">全屏下仍触发</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<h3>触发器</h3>
|
||||
<div class="section-box">
|
||||
<label class="field">
|
||||
<span>类型</span>
|
||||
<select v-model="editing.rule!.trigger.type" @change="onTriggerTypeChange">
|
||||
<option v-for="(label, type) in meta.trigger_types" :key="type" :value="type">{{ label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div v-for="f in TRIGGER_SCHEMA[editing.rule!.trigger.type] ?? []" :key="f.key" class="field">
|
||||
<span>{{ f.label }}</span>
|
||||
<select v-if="f.type === 'select'" :value="paramVal(editing.rule, f)" @change="e => setParam(editing.rule, f, (e.target as HTMLSelectElement).value)">
|
||||
<option v-for="o in f.options" :key="o.value" :value="o.value">{{ o.label }}</option>
|
||||
</select>
|
||||
<input v-else-if="f.type === 'number'" type="number" :min="f.min" :placeholder="f.placeholder" :value="paramVal(editing.rule, f)" @input="e => setParam(editing.rule, f, (e.target as HTMLInputElement).value)" />
|
||||
<input v-else type="text" :placeholder="f.placeholder" :value="paramVal(editing.rule, f)" @input="e => setParam(editing.rule, f, (e.target as HTMLInputElement).value)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>动作({{ (editing.rule!.actions ?? []).length }})</h3>
|
||||
<div class="section-box">
|
||||
<div v-for="(a, idx) in editing.rule!.actions" :key="idx" class="action-item">
|
||||
<div class="action-head">
|
||||
<select v-model="a.type" @change="onActionTypeChange(a)">
|
||||
<option v-for="(label, type) in meta.action_types" :key="type" :value="type">{{ label }}</option>
|
||||
</select>
|
||||
<button class="icon-btn" title="删除动作" @click="removeAction(idx)">✕</button>
|
||||
</div>
|
||||
<div v-for="f in ACTION_SCHEMA[a.type] ?? []" :key="f.key" class="field">
|
||||
<span>{{ f.label }}</span>
|
||||
<select v-if="f.type === 'select'" :value="actionParam(a, f.key)" @change="e => setActionParam(a, f, (e.target as HTMLSelectElement).value)">
|
||||
<option v-for="o in f.options" :key="o.value" :value="o.value">{{ o.label }}</option>
|
||||
</select>
|
||||
<input v-else-if="f.type === 'number'" type="number" :min="f.min" :placeholder="f.placeholder" :value="actionParam(a, f.key)" @input="e => setActionParam(a, f, (e.target as HTMLInputElement).value)" />
|
||||
<input v-else type="text" :placeholder="f.placeholder" :value="actionParam(a, f.key)" @input="e => setActionParam(a, f, (e.target as HTMLInputElement).value)" />
|
||||
</div>
|
||||
</div>
|
||||
<button class="ghost" @click="addAction">+ 添加动作</button>
|
||||
</div>
|
||||
</section>
|
||||
<section v-else class="editor-pane empty-pane">
|
||||
<p>选择一条规则进行编辑,或新建规则。</p>
|
||||
</section>
|
||||
</main>
|
||||
<div v-else class="loading">加载中…</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.app {
|
||||
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
|
||||
min-height: 100vh;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 20px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--bg-top);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
}
|
||||
.brand { display: flex; align-items: baseline; gap: 8px; }
|
||||
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; }
|
||||
.subtitle { color: var(--muted); font-size: 13px; }
|
||||
.controls { display: flex; align-items: center; gap: 14px; }
|
||||
.switch-label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: 320px 1fr;
|
||||
gap: 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.rules-pane {
|
||||
border-right: 1px solid var(--border);
|
||||
padding: 16px;
|
||||
overflow-y: auto;
|
||||
background: var(--bg-side);
|
||||
}
|
||||
.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
|
||||
.pane-head h2 { font-size: 14px; margin: 0; }
|
||||
.rule-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
|
||||
.rule-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
background: var(--card);
|
||||
transition: border-color .12s;
|
||||
}
|
||||
.rule-card:hover { border-color: var(--accent); }
|
||||
.rule-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
||||
.rule-main { min-width: 0; }
|
||||
.rule-name { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; }
|
||||
.rule-desc { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
|
||||
.dot.on { background: #2ea043; }
|
||||
.dot.off { background: var(--muted); }
|
||||
.editor-pane { padding: 20px 24px; overflow-y: auto; }
|
||||
.editor-pane h2 { font-size: 16px; margin: 0 0 14px; }
|
||||
.editor-pane h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
|
||||
.section-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
|
||||
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
|
||||
.field input, .field select {
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--input-bg);
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
|
||||
.field.check { flex-direction: row; align-items: center; gap: 6px; }
|
||||
.action-item { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.action-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.action-head select { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text); }
|
||||
button.primary {
|
||||
padding: 6px 16px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.primary:disabled { opacity: .5; cursor: default; }
|
||||
button.ghost { padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; font-size: 13px; }
|
||||
button.ghost:hover { border-color: var(--accent); }
|
||||
button.icon-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; }
|
||||
button.icon-btn:hover { color: #d1242f; }
|
||||
.error-banner, .notice-banner, .warn-banner { padding: 8px 20px; font-size: 13px; }
|
||||
.error-banner { background: #fdecec; color: #b91c1c; }
|
||||
.notice-banner { background: #e8f5ec; color: #1a7f37; }
|
||||
.warn-banner { background: #fef6e6; color: #9a6700; }
|
||||
.empty { color: var(--muted); font-size: 13px; }
|
||||
.empty-pane { display: flex; align-items: center; justify-content: center; color: var(--muted); }
|
||||
.loading { padding: 40px; color: var(--muted); }
|
||||
</style>
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
@@ -0,0 +1,98 @@
|
||||
// 触发器/动作的参数表单 schema(驱动动态表单渲染)。
|
||||
|
||||
export interface ParamField {
|
||||
key: string
|
||||
label: string
|
||||
type: 'text' | 'number' | 'select' | 'bool'
|
||||
options?: { value: string; label: string }[]
|
||||
placeholder?: string
|
||||
required?: boolean
|
||||
min?: number
|
||||
}
|
||||
|
||||
export const TRIGGER_SCHEMA: Record<string, ParamField[]> = {
|
||||
mouse_corner: [
|
||||
{ key: 'corner', label: '角落', type: 'select', required: true, options: [
|
||||
{ value: 'top_left', label: '左上角' },
|
||||
{ value: 'top_right', label: '右上角' },
|
||||
{ value: 'bottom_left', label: '左下角' },
|
||||
{ value: 'bottom_right', label: '右下角' },
|
||||
]},
|
||||
{ key: 'screen', label: '屏幕', type: 'select', options: [
|
||||
{ value: 'all', label: '所有屏幕' },
|
||||
{ value: 'primary', label: '主屏幕' },
|
||||
]},
|
||||
{ key: 'threshold_px', label: '触发范围 (px)', type: 'number', min: 4, placeholder: '32' },
|
||||
],
|
||||
mouse_edge_wheel: [
|
||||
{ key: 'edge', label: '边缘', type: 'select', required: true, options: [
|
||||
{ value: 'top', label: '顶部' },
|
||||
{ value: 'bottom', label: '底部' },
|
||||
{ value: 'left', label: '左侧' },
|
||||
{ value: 'right', label: '右侧' },
|
||||
]},
|
||||
{ key: 'direction', label: '滚轮方向', type: 'select', options: [
|
||||
{ value: 'up', label: '向上(增大)' },
|
||||
{ value: 'down', label: '向下(减小)' },
|
||||
]},
|
||||
{ key: 'threshold_px', label: '边缘范围 (px)', type: 'number', min: 4, placeholder: '32' },
|
||||
],
|
||||
hotkey: [
|
||||
{ key: 'hotkey', label: '快捷键', type: 'text', required: true, placeholder: 'ctrl+alt+d' },
|
||||
],
|
||||
}
|
||||
|
||||
export const ACTION_SCHEMA: Record<string, ParamField[]> = {
|
||||
switch_virtual_desktop: [
|
||||
{ key: 'mode', label: '模式', type: 'select', required: true, options: [
|
||||
{ value: 'alternate', label: '往返(alternate)' },
|
||||
{ value: 'left', label: '向左' },
|
||||
{ value: 'right', label: '向右' },
|
||||
]},
|
||||
{ key: 'method', label: '切换方式', type: 'select', options: [
|
||||
{ value: 'com', label: 'COM 直调(推荐)' },
|
||||
{ value: 'taskview', label: '任务视图导航' },
|
||||
{ value: 'hotkey', label: '系统快捷键' },
|
||||
]},
|
||||
{ key: 'taskview_delay_ms', label: '任务视图等待 (ms)', type: 'number', min: 0, placeholder: '400' },
|
||||
],
|
||||
volume_up: [
|
||||
{ key: 'steps', label: '步进(百分比)', type: 'number', min: 1, placeholder: '1' },
|
||||
],
|
||||
volume_down: [
|
||||
{ key: 'steps', label: '步进(百分比)', type: 'number', min: 1, placeholder: '1' },
|
||||
],
|
||||
toggle_mute: [],
|
||||
show_notification: [
|
||||
{ key: 'title', label: '标题', type: 'text', required: true },
|
||||
{ key: 'text', label: '内容', type: 'text', required: true },
|
||||
],
|
||||
delay: [
|
||||
{ key: 'ms', label: '毫秒', type: 'number', required: true, min: 0 },
|
||||
],
|
||||
launch_application: [
|
||||
{ key: 'path', label: '程序路径', type: 'text', required: true, placeholder: 'C:\\Windows\\System32\\notepad.exe' },
|
||||
{ key: 'args', label: '参数', type: 'text' },
|
||||
],
|
||||
open_url: [
|
||||
{ key: 'url', label: '链接', type: 'text', required: true, placeholder: 'https://example.com' },
|
||||
],
|
||||
}
|
||||
|
||||
// 默认参数(新建动作时填充)。
|
||||
export const ACTION_DEFAULTS: Record<string, Record<string, unknown>> = {
|
||||
switch_virtual_desktop: { mode: 'alternate', method: 'com' },
|
||||
volume_up: { steps: 1 },
|
||||
volume_down: { steps: 1 },
|
||||
toggle_mute: {},
|
||||
show_notification: { title: '', text: '' },
|
||||
delay: { ms: 500 },
|
||||
launch_application: { path: '', args: '' },
|
||||
open_url: { url: '' },
|
||||
}
|
||||
|
||||
export const TRIGGER_DEFAULTS: Record<string, Record<string, unknown>> = {
|
||||
mouse_corner: { corner: 'bottom_left', screen: 'all', threshold_px: 32 },
|
||||
mouse_edge_wheel: { edge: 'top', direction: 'up', threshold_px: 32 },
|
||||
hotkey: { hotkey: 'ctrl+alt+d' },
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"noUnusedParameters": false,
|
||||
"noImplicitAny": false,
|
||||
"jsx": "preserve",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "bindings"],
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import wails from "@wailsio/runtime/plugins/vite";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
server: {
|
||||
host: "127.0.0.1",
|
||||
port: Number(process.env.WAILS_VITE_PORT) || 9245,
|
||||
strictPort: true,
|
||||
},
|
||||
plugins: [vue(), wails("./bindings")],
|
||||
});
|
||||
Reference in new issue
Block a user