|
|
@@ -7,6 +7,7 @@ import {BrightnessService} from "../bindings/TengTuToolbox/index.js"; // 显示
|
|
|
import {ProxyService} from "../bindings/TengTuToolbox/index.js"; // 网络代理服务(设置/启用/禁用 Windows 系统代理)
|
|
|
import {YTDLPService} from "../bindings/TengTuToolbox/index.js"; // yt-dlp 服务(视频下载)
|
|
|
import {LocalService} from "../bindings/TengTuToolbox/index.js"; // 本地资源启动服务(「本地」页)
|
|
|
+import {QuickService} from "../bindings/TengTuToolbox/index.js"; // 快捷启动服务(「快捷」页,含程序图标提取)
|
|
|
import {UDPService} from "../bindings/TengTuToolbox/index.js"; // UDP 键值服务(工具页 UDP 服务器)
|
|
|
import {getCalendarInfo} from "./lunar.js"; // 农历与节日计算
|
|
|
|
|
|
@@ -38,6 +39,7 @@ const FALLBACK_SETTINGS = {
|
|
|
alwaysOnTop: false,
|
|
|
startCompact: false, // 启动时自动收拢为圆点
|
|
|
hotkey: 'CmdOrCtrl+Shift+G',
|
|
|
+ quickHotkey: 'Ctrl+Shift+H', // 「快捷」菜单全局热键(在鼠标位置弹出)
|
|
|
tabOrder: ['links', 'news', 'github', 'stock', 'todo', 'record', 'tools', 'locals', 'control', 'host', 'settings'],
|
|
|
stockCodes: ['sh000001', 'sh600519', 'sz000001'],
|
|
|
links: [{name: '煎蛋', url: 'https://jandan.net/'}],
|
|
|
@@ -46,6 +48,7 @@ const FALLBACK_SETTINGS = {
|
|
|
githubRepos: [{url: 'https://github.com/wailsapp/wails', desc: 'Wails 框架'}],
|
|
|
customTabs: [], // 用户自定义 Tab 页面(名字 + 地址;http/https 为网页,其余为本地文件)
|
|
|
localTools: [], // 「本地」页资源(标题 + 启动命令 + 说明)
|
|
|
+ quickGroups: [], // 「快捷」页分组(缩进分层:组名 + 名称|路径|说明 条目)
|
|
|
apiAddr: '127.0.0.1:17890',
|
|
|
serviceAddr: '0.0.0.0:9090', // 服务模式(--service)API 地址,仅电源类接口,其余转发给界面
|
|
|
apiAutoStart: true, // 应用启动时自动启动内置 API 服务(默认开启)
|
|
|
@@ -188,9 +191,11 @@ async function applyCustomTabs(tabs) {
|
|
|
modeGroup.className = 'custom-file-mode';
|
|
|
const editBtn = document.createElement('button');
|
|
|
editBtn.className = 'custom-file-mode-btn is-active';
|
|
|
+ editBtn.dataset.mode = 'edit';
|
|
|
editBtn.textContent = '编辑';
|
|
|
const previewBtn = document.createElement('button');
|
|
|
previewBtn.className = 'custom-file-mode-btn';
|
|
|
+ previewBtn.dataset.mode = 'preview';
|
|
|
previewBtn.textContent = '预览';
|
|
|
modeGroup.appendChild(editBtn);
|
|
|
modeGroup.appendChild(previewBtn);
|
|
|
@@ -221,6 +226,16 @@ async function applyCustomTabs(tabs) {
|
|
|
backupCustomFileTab(t);
|
|
|
});
|
|
|
|
|
|
+ // 隐藏/显示乒乓键:隐藏编辑框与预览容器(保留工具栏),再点恢复
|
|
|
+ const hideBtn = document.createElement('button');
|
|
|
+ hideBtn.className = 'btn-ghost';
|
|
|
+ hideBtn.textContent = t.hidden ? '显示' : '隐藏';
|
|
|
+ hideBtn.title = t.hidden ? '显示此页面内容' : '隐藏此页面内容(按钮保留,可再次点击显示)';
|
|
|
+ hideBtn.addEventListener('click', (e) => {
|
|
|
+ e.stopPropagation();
|
|
|
+ t.hidden = !t.hidden; // 会话级状态:跨 Tab 切换保持,刷新页面重置
|
|
|
+ applyQuickHideState(t, hideBtn);
|
|
|
+ });
|
|
|
bar.appendChild(modeGroup);
|
|
|
// 状态提示(保存/备份/刷新结果),margin-right:auto 推到最左,编辑模式下也可见
|
|
|
const status = document.createElement('span');
|
|
|
@@ -230,6 +245,7 @@ async function applyCustomTabs(tabs) {
|
|
|
bar.appendChild(saveBtn);
|
|
|
bar.appendChild(refreshBtn);
|
|
|
bar.appendChild(backupBtn);
|
|
|
+ bar.appendChild(hideBtn);
|
|
|
panel.appendChild(bar);
|
|
|
|
|
|
// 编辑框(Markdown 源码)
|
|
|
@@ -261,6 +277,9 @@ async function applyCustomTabs(tabs) {
|
|
|
previewBtn.addEventListener('click', () => setFileMode('preview'));
|
|
|
// 编辑框为纯文本编辑:输入时不触发 Markdown 渲染(避免编辑态出现 markdown 副作用),
|
|
|
// 预览容器仅在切到「预览」模式时渲染(见 setFileMode)。
|
|
|
+
|
|
|
+ // 若上次会话中该页面被隐藏(t.hidden),初始隐藏内容并让按钮显示「显示」
|
|
|
+ applyQuickHideState(t, hideBtn);
|
|
|
}
|
|
|
content.insertBefore(panel, settingsPanel);
|
|
|
}
|
|
|
@@ -270,6 +289,30 @@ async function applyCustomTabs(tabs) {
|
|
|
return customTabs.length > 0;
|
|
|
}
|
|
|
|
|
|
+// 应用「隐藏/显示」乒乓状态:隐藏时编辑框与预览容器都不显示(工具栏保留),
|
|
|
+// 显示时恢复为当前编辑/预览模式(由高亮按钮判定)。
|
|
|
+function applyQuickHideState(t, hideBtn) {
|
|
|
+ const editor = document.getElementById(`editor-${t.id}`);
|
|
|
+ const md = document.getElementById(`md-${t.id}`);
|
|
|
+ const panel = document.getElementById(`tab-${t.id}`);
|
|
|
+ if (!editor || !md || !panel) return;
|
|
|
+
|
|
|
+ if (t.hidden) {
|
|
|
+ // 隐藏内容(保留工具栏)
|
|
|
+ editor.style.display = 'none';
|
|
|
+ md.style.display = 'none';
|
|
|
+ if (hideBtn) hideBtn.textContent = '显示';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示:恢复为当前模式(高亮按钮的 data-mode 判定,默认编辑)
|
|
|
+ const active = panel.querySelector('.custom-file-mode-btn.is-active');
|
|
|
+ const isPreview = active && active.dataset.mode === 'preview';
|
|
|
+ editor.style.display = isPreview ? 'none' : '';
|
|
|
+ md.style.display = isPreview ? '' : 'none';
|
|
|
+ if (hideBtn) hideBtn.textContent = '隐藏';
|
|
|
+}
|
|
|
+
|
|
|
// 加载文件类自定义 Tab 内容:读取文本填入编辑框,并刷新预览
|
|
|
async function loadCustomFileTab(t) {
|
|
|
const editor = document.getElementById(`editor-${t.id}`);
|
|
|
@@ -482,8 +525,9 @@ function applyTabOrder(order) {
|
|
|
});
|
|
|
// 分组容器:系统在前,其后按 Tab 顺序;未对应 Tab 的组(如 poem)追加到末尾
|
|
|
const groupOrder = ['system', ...allOrdered];
|
|
|
- // 补全未出现在 Tab 顺序中的组(例如 poem),保持首次出现顺序
|
|
|
- const named = new Map([['system', '系统'], ['poem', '古诗'], ['mouse', '鼠标提醒'], ['update', '升级']]);
|
|
|
+ // 补全未出现在 Tab 顺序中的组(例如 poem),保持首次出现顺序。
|
|
|
+ // 「升级」「快捷」设置项已并入「系统」组(data-tab-group=system),不再作为独立分组。
|
|
|
+ const named = new Map([['system', '系统'], ['poem', '古诗'], ['mouse', '鼠标提醒']]);
|
|
|
Object.keys(grouped).forEach(g => {
|
|
|
if (!groupOrder.includes(g)) groupOrder.push(g);
|
|
|
});
|
|
|
@@ -696,6 +740,8 @@ const autostartToggle = document.getElementById('autostart'); // 开机启
|
|
|
const topToggle = document.getElementById('always-on-top'); // 窗口置顶开关
|
|
|
const startCompactToggle = document.getElementById('start-compact'); // 启动时缩小开关
|
|
|
const hotkeyInput = document.getElementById('hotkey'); // 热键输入框
|
|
|
+const quickHotkeyInput = document.getElementById('quickhotkey'); // 「快捷」菜单热键输入框
|
|
|
+const proxyHotkeyInput = document.getElementById('proxyhotkey'); // 「网络代理」开关热键输入框
|
|
|
const tabOrderText = document.getElementById('tab-order'); // Tab 显示顺序(每行一个 id)
|
|
|
const stockCodesInput = document.getElementById('stock-codes'); // 股票代码
|
|
|
const linksText = document.getElementById('links-text'); // 常用网址(每行 名称|网址)
|
|
|
@@ -712,14 +758,13 @@ const todoPathInput = document.getElementById('todo-path'); // 待办(
|
|
|
const recordDBPathInput = document.getElementById('record-db-path'); // 记录(Record)数据库路径
|
|
|
const backupDirInput = document.getElementById('backup-dir'); // 文本备份目录(文件类自定义 Tab「备份」按钮使用)
|
|
|
const browserPathInput = document.getElementById('browser-path'); // 指定浏览器 exe 路径(空=系统默认)
|
|
|
-const gitlabUrlInput = document.getElementById('gitlab-base-url'); // GitLab 根地址
|
|
|
-const gitlabProjectInput = document.getElementById('gitlab-project'); // GitLab 项目路径
|
|
|
-const gitlabTokenInput = document.getElementById('gitlab-token'); // GitLab 访问令牌(masked)
|
|
|
-const gitlabBranchInput = document.getElementById('gitlab-branch'); // 版本清单分支 / Tag
|
|
|
const browserPickBtn = document.getElementById('browser-pick'); // 选择浏览器按钮
|
|
|
const browserClearBtn = document.getElementById('browser-clear'); // 清除浏览器按钮
|
|
|
const customTabsText = document.getElementById('custom-tabs'); // 自定义 Tab(每行 名称|地址|备注)
|
|
|
const localToolsText = document.getElementById('local-tools'); // 本地资源/工具(每行 标题|命令|说明)
|
|
|
+const quickToolsText = document.getElementById('quick-tools'); // 快捷启动(缩进分层:组名 + 缩进 名称|路径|说明)
|
|
|
+const quickImportBiniwareBtn = document.getElementById('quick-import-biniware'); // 从 Biniware Run brun.cfg 导入快捷启动
|
|
|
+const quickMenu = document.getElementById('quick-menu'); // 句柄右键弹出的快捷菜单容器
|
|
|
const controlKeysText = document.getElementById('control-keys'); // 控制页按键(每行 图标|命令URL)
|
|
|
const controlRepeatInput = document.getElementById('control-repeat'); // 控制页长按连发频率(秒)
|
|
|
const saveButton = document.getElementById('save-settings'); // 保存按钮
|
|
|
@@ -826,6 +871,8 @@ async function syncForm(settings) {
|
|
|
topToggle.checked = settings.alwaysOnTop;
|
|
|
if (startCompactToggle) startCompactToggle.checked = !!settings.startCompact;
|
|
|
hotkeyInput.value = settings.hotkey;
|
|
|
+ if (quickHotkeyInput) quickHotkeyInput.value = settings.quickHotkey || FALLBACK_SETTINGS.quickHotkey;
|
|
|
+ if (proxyHotkeyInput) proxyHotkeyInput.value = settings.proxyHotkey || ''; // 代理热键允许留空(不设热键)
|
|
|
// 先重建自定义 Tab(供顺序文本框解析名称与 applyTabOrder 使用)
|
|
|
await applyCustomTabs(settings.customTabs);
|
|
|
// 完整 Tab 顺序文本:内置 + 自定义,按 settings.tabOrder 排序,未列出的追加(设置恒在最后)
|
|
|
@@ -850,6 +897,8 @@ async function syncForm(settings) {
|
|
|
customTabsText.value = (settings.customTabs || []).map(t => `${t.name}|${t.url}${t.desc ? '|' + t.desc : ''}`).join('\n');
|
|
|
localToolsText.value = (settings.localTools || []).map(t => `${t.title}|${t.cmd}${t.desc ? '|' + t.desc : ''}`).join('\n');
|
|
|
renderLocals(settings.localTools || []); // 「本地」页卡片按最新配置重建
|
|
|
+ // 「快捷」项:仅回填设置文本,菜单在句柄右键时按最新配置实时构建
|
|
|
+ quickToolsText.value = quickGroupsToText(settings.quickGroups || []);
|
|
|
// 控制页按键:回填设置表单并刷新方向盘按钮
|
|
|
const cKeys = settings.controlKeys || FALLBACK_SETTINGS.controlKeys;
|
|
|
controlKeysText.value = cKeys.map(k => `${k.icon || ''}|${k.cmd || ''}`).join('\n');
|
|
|
@@ -869,11 +918,6 @@ async function syncForm(settings) {
|
|
|
recordDBPathInput.value = settings.recordDBPath;
|
|
|
backupDirInput.value = settings.backupDir;
|
|
|
browserPathInput.value = settings.browserPath || '';
|
|
|
- const gl = settings.gitLab || {};
|
|
|
- gitlabUrlInput.value = gl.baseUrl || 'https://git.scwy.net';
|
|
|
- gitlabProjectInput.value = gl.projectPath || 'ease/toolbox';
|
|
|
- gitlabTokenInput.value = gl.privateToken || '';
|
|
|
- gitlabBranchInput.value = gl.branch || 'main';
|
|
|
stockUpColorInput.value = settings.stockUpColor || FALLBACK_SETTINGS.stockUpColor;
|
|
|
stockDownColorInput.value = settings.stockDownColor || FALLBACK_SETTINGS.stockDownColor;
|
|
|
stockRefreshSecsInput.value = settings.stockRefreshSecs || FALLBACK_SETTINGS.stockRefreshSecs;
|
|
|
@@ -961,26 +1005,41 @@ function syncMouseAlertForm(cfg) {
|
|
|
// ------------------------------------------------------------------------
|
|
|
const MODIFIER_KEYS = ['Control', 'Shift', 'Alt', 'Meta'];
|
|
|
|
|
|
-hotkeyInput.addEventListener('keydown', (event) => {
|
|
|
- event.preventDefault(); // 阻止输入框写入原始字符
|
|
|
+// 热键输入框通用绑定:点击后按下组合键,显示为 Ctrl+Shift+X 形式(支持 Ctrl/Shift/Alt/Meta)
|
|
|
+// 按 Backspace / Delete 清空(用于「留空=不设热键」,如代理开关热键)
|
|
|
+function bindHotkeyInput(input) {
|
|
|
+ if (!input) return;
|
|
|
+ input.addEventListener('keydown', (event) => {
|
|
|
+ event.preventDefault(); // 阻止输入框写入原始字符
|
|
|
|
|
|
- if (MODIFIER_KEYS.includes(event.key)) {
|
|
|
- return; // 只按下修饰键时,等待主键
|
|
|
- }
|
|
|
+ if (MODIFIER_KEYS.includes(event.key)) {
|
|
|
+ return; // 只按下修饰键时,等待主键
|
|
|
+ }
|
|
|
+ // Backspace / Delete:清空热键(不设热键)
|
|
|
+ if (event.key === 'Backspace' || event.key === 'Delete') {
|
|
|
+ input.value = '';
|
|
|
+ markDirty();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- const parts = [];
|
|
|
- if (event.ctrlKey || event.metaKey) parts.push('CmdOrCtrl'); // Windows 下对应 Ctrl
|
|
|
- if (event.altKey) parts.push('Alt');
|
|
|
- if (event.shiftKey) parts.push('Shift');
|
|
|
- parts.push(event.key.length === 1 ? event.key.toUpperCase() : event.key); // 主键统一大写
|
|
|
+ const parts = [];
|
|
|
+ if (event.ctrlKey || event.metaKey) parts.push('CmdOrCtrl'); // Windows 下对应 Ctrl
|
|
|
+ if (event.altKey) parts.push('Alt');
|
|
|
+ if (event.shiftKey) parts.push('Shift');
|
|
|
+ parts.push(event.key.length === 1 ? event.key.toUpperCase() : event.key); // 主键统一大写
|
|
|
|
|
|
- hotkeyInput.value = parts.join('+');
|
|
|
- markDirty();
|
|
|
-});
|
|
|
+ input.value = parts.join('+');
|
|
|
+ markDirty();
|
|
|
+ });
|
|
|
|
|
|
-hotkeyInput.addEventListener('focus', () => {
|
|
|
- hotkeyInput.select(); // 聚焦时全选,方便重新录入
|
|
|
-});
|
|
|
+ input.addEventListener('focus', () => {
|
|
|
+ input.select(); // 聚焦时全选,方便重新录入
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+bindHotkeyInput(hotkeyInput);
|
|
|
+bindHotkeyInput(quickHotkeyInput);
|
|
|
+bindHotkeyInput(proxyHotkeyInput);
|
|
|
|
|
|
// 指定浏览器:选择按钮弹出文件选择框,清除按钮恢复系统默认
|
|
|
browserPickBtn.addEventListener('click', async () => {
|
|
|
@@ -998,6 +1057,28 @@ browserClearBtn.addEventListener('click', () => {
|
|
|
markDirty();
|
|
|
});
|
|
|
|
|
|
+// 从 Biniware Run 的 brun.cfg 导入快捷启动:弹出文件选择框,后端解析并立即保存
|
|
|
+// (含托盘「快捷」子菜单重建),成功后把导入的分组回填到「快捷」文本域并同步内存配置。
|
|
|
+// 用户此后编辑文本域会进入「待保存」状态,点「保存」再持久化后续改动。
|
|
|
+quickImportBiniwareBtn.addEventListener('click', async () => {
|
|
|
+ try {
|
|
|
+ const groups = await QuickService.ImportBiniwareRun();
|
|
|
+ if (!groups || !groups.length) return; // 用户取消
|
|
|
+ currentSettings.quickGroups = groups; // 同步内存配置,避免 syncForm 回退旧值
|
|
|
+ quickToolsText.value = quickGroupsToText(groups);
|
|
|
+ isDirty = false; // 后端已保存,无需再触发自动保存
|
|
|
+ renderQuickMenu(groups); // 立即刷新句柄右键「快捷」菜单
|
|
|
+ saveStatus.textContent = `已导入 ${groups.length} 组快捷项`;
|
|
|
+ saveStatus.classList.remove('is-error');
|
|
|
+ saveStatus.classList.add('is-ok');
|
|
|
+ } catch (err) {
|
|
|
+ console.warn('导入 BiniwareRun 配置失败:', err);
|
|
|
+ saveStatus.textContent = '导入失败:' + (err?.message || err);
|
|
|
+ saveStatus.classList.remove('is-ok');
|
|
|
+ saveStatus.classList.add('is-error');
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
// ------------------------------------------------------------------------
|
|
|
// 读取 / 保存配置
|
|
|
// ------------------------------------------------------------------------
|
|
|
@@ -1106,6 +1187,211 @@ function renderLocals(tools) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ------------------------------------------------------------------------
|
|
|
+// 快捷页:缩进分层配置(组名 + 名称|路径|说明),自动识别程序图标并启动
|
|
|
+// ------------------------------------------------------------------------
|
|
|
+
|
|
|
+// 缩进识别:行首空格/制表符数量。>=2 个空格或 >=1 个制表符视为缩进条目。
|
|
|
+const QUICK_INDENT = /^(?: {2,}|\t)/;
|
|
|
+
|
|
|
+// 解析缩进分层文本为分组数组:
|
|
|
+// 顶层无缩进且不含 | 的行 = 分组名;缩进条目 = 名称|路径|说明;
|
|
|
+// 顶层无缩进但含 | 的行 = 未分组条目(不归任何组),集中到结尾的「未分组」组。
|
|
|
+function parseQuickText(text) {
|
|
|
+ const groups = [];
|
|
|
+ const ungrouped = []; // 未分组条目(顶层含 | 的行 + 无分组标题的缩进条目)
|
|
|
+ let cur = {name: '', items: []};
|
|
|
+ const flushCur = () => {
|
|
|
+ if (cur.items.length) {
|
|
|
+ if (cur.name) groups.push(cur);
|
|
|
+ else ungrouped.push(...cur.items); // 无标题的缩进条目并入未分组
|
|
|
+ }
|
|
|
+ cur = {name: '', items: []};
|
|
|
+ };
|
|
|
+ for (const raw of (text || '').split('\n')) {
|
|
|
+ const line = raw.replace(/\r$/, '');
|
|
|
+ const trimmed = line.trim();
|
|
|
+ if (!trimmed) continue; // 跳过空行
|
|
|
+ if (QUICK_INDENT.test(line)) {
|
|
|
+ // 缩进条目:名称|路径|说明(说明可省略)
|
|
|
+ const parts = trimmed.split('|');
|
|
|
+ const item = {
|
|
|
+ title: (parts[0] || '').trim(),
|
|
|
+ path: (parts[1] || '').trim(),
|
|
|
+ desc: (parts[2] || '').trim(),
|
|
|
+ };
|
|
|
+ if (item.title && item.path) cur.items.push(item);
|
|
|
+ } else if (trimmed.includes('|')) {
|
|
|
+ // 顶层条目(未分层):结束当前组,条目直接进未分组
|
|
|
+ flushCur();
|
|
|
+ const parts = trimmed.split('|');
|
|
|
+ const item = {
|
|
|
+ title: (parts[0] || '').trim(),
|
|
|
+ path: (parts[1] || '').trim(),
|
|
|
+ desc: (parts[2] || '').trim(),
|
|
|
+ };
|
|
|
+ if (item.title && item.path) ungrouped.push(item);
|
|
|
+ } else {
|
|
|
+ // 顶层分组名:结束当前组,开启新分组
|
|
|
+ flushCur();
|
|
|
+ cur = {name: trimmed, items: []};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ flushCur();
|
|
|
+ if (ungrouped.length) groups.push({name: '', items: ungrouped}); // 未分组条目集中到结尾
|
|
|
+ return groups.filter(g => g.items.length > 0);
|
|
|
+}
|
|
|
+
|
|
|
+// 把分组数组编码为缩进分层文本(回填设置表单用)。
|
|
|
+// 未分组(name 为空)条目直接输出,其余组先输出组名再输出缩进条目。
|
|
|
+function quickGroupsToText(groups) {
|
|
|
+ return (groups || []).map(g => {
|
|
|
+ const lines = [];
|
|
|
+ if (g.name) lines.push(g.name);
|
|
|
+ for (const it of g.items) {
|
|
|
+ // 未分组条目不带缩进(否则重新解析会被归入最近的分组,丢失「未分组」语义)
|
|
|
+ const prefix = g.name ? ' ' : '';
|
|
|
+ lines.push(`${prefix}${it.title}|${it.path}${it.desc ? '|' + it.desc : ''}`);
|
|
|
+ }
|
|
|
+ return lines.join('\n');
|
|
|
+ }).join('\n');
|
|
|
+}
|
|
|
+
|
|
|
+// 构建「句柄右键 → 快捷启动」菜单:按分组嵌套,条目带图标 + 名称,
|
|
|
+// 点击即启动。无条目时显示「未配置快捷项」提示。
|
|
|
+// 层级结构:命名分组作为可展开/收起的节点(标题行点击切换,箭头 ▸/▾ 指示),
|
|
|
+// 未分组条目直接平铺在顶层。
|
|
|
+function renderQuickMenu(groups) {
|
|
|
+ if (!quickMenu) return;
|
|
|
+ quickMenu.innerHTML = '';
|
|
|
+ const list = groups || [];
|
|
|
+ if (!list.length) {
|
|
|
+ const empty = document.createElement('div');
|
|
|
+ empty.className = 'quick-menu-empty';
|
|
|
+ empty.textContent = '未配置快捷项:到 设置 → 快捷 添加';
|
|
|
+ quickMenu.appendChild(empty);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (const g of list) {
|
|
|
+ if (g.name) {
|
|
|
+ // 分组标题:点击展开/收起
|
|
|
+ const groupHead = document.createElement('button');
|
|
|
+ groupHead.type = 'button';
|
|
|
+ groupHead.className = 'quick-menu-group';
|
|
|
+ const arrow = document.createElement('span');
|
|
|
+ arrow.className = 'quick-menu-arrow';
|
|
|
+ arrow.textContent = '▸';
|
|
|
+ const gname = document.createElement('span');
|
|
|
+ gname.className = 'quick-menu-name';
|
|
|
+ gname.textContent = g.name;
|
|
|
+ const gcount = document.createElement('span');
|
|
|
+ gcount.className = 'quick-menu-count';
|
|
|
+ gcount.textContent = g.items.length;
|
|
|
+ groupHead.appendChild(arrow);
|
|
|
+ groupHead.appendChild(gname);
|
|
|
+ groupHead.appendChild(gcount);
|
|
|
+ quickMenu.appendChild(groupHead);
|
|
|
+
|
|
|
+ // 分组条目容器:默认收起(点击标题展开)
|
|
|
+ const groupBody = document.createElement('div');
|
|
|
+ groupBody.className = 'quick-menu-body';
|
|
|
+ groupHead.addEventListener('click', () => {
|
|
|
+ const isOpen = groupBody.classList.toggle('is-open');
|
|
|
+ arrow.textContent = isOpen ? '▾' : '▸';
|
|
|
+ });
|
|
|
+ appendQuickItems(groupBody, g.items);
|
|
|
+ quickMenu.appendChild(groupBody);
|
|
|
+ } else {
|
|
|
+ // 未分组条目:直接平铺在顶层
|
|
|
+ appendQuickItems(quickMenu, g.items);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 向容器追加一组快捷条目(图标 + 名称,点击即启动)
|
|
|
+function appendQuickItems(container, items) {
|
|
|
+ for (const it of items) {
|
|
|
+ const row = document.createElement('button');
|
|
|
+ row.type = 'button';
|
|
|
+ row.className = 'quick-menu-item';
|
|
|
+ row.title = it.desc || it.path;
|
|
|
+
|
|
|
+ const icon = document.createElement('img');
|
|
|
+ icon.className = 'quick-menu-icon';
|
|
|
+ icon.alt = '';
|
|
|
+ icon.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; // 占位,加载后替换
|
|
|
+ // 自动识别程序图标:路径非空才请求,失败/无图标时回退通用图标
|
|
|
+ if (it.path) {
|
|
|
+ const src = it.path;
|
|
|
+ Promise.resolve()
|
|
|
+ .then(() => typeof QuickService?.GetIcon === 'function' ? QuickService.GetIcon(src) : Promise.resolve(''))
|
|
|
+ .then(uri => { icon.src = uri || quickFallbackIcon(); })
|
|
|
+ .catch(() => { icon.src = quickFallbackIcon(); });
|
|
|
+ }
|
|
|
+ row.appendChild(icon);
|
|
|
+
|
|
|
+ const name = document.createElement('span');
|
|
|
+ name.className = 'quick-menu-name';
|
|
|
+ name.textContent = it.title;
|
|
|
+ row.appendChild(name);
|
|
|
+
|
|
|
+ row.addEventListener('click', () => {
|
|
|
+ hideQuickMenu();
|
|
|
+ if (row.disabled) return;
|
|
|
+ const label = row.textContent;
|
|
|
+ row.disabled = true;
|
|
|
+ QuickService.Launch(it.title, it.path)
|
|
|
+ .then(() => { row.textContent = '已启动 ' + (it.title || ''); })
|
|
|
+ .catch(err => { row.textContent = '失败 ' + (it.title || ''); row.title = `启动失败:${err?.message || err}`; })
|
|
|
+ .finally(() => setTimeout(() => { row.textContent = label; row.disabled = false; }, 1200));
|
|
|
+ });
|
|
|
+ container.appendChild(row);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 通用图标:后端 GetIcon 失败/无图标时回退为通用程序图形(SVG data URI)
|
|
|
+function quickFallbackIcon() {
|
|
|
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="rgba(128,128,128,.18)"/><rect x="9" y="13" width="14" height="10" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><rect x="12" y="8" width="8" height="5" rx="1" fill="none" stroke="currentColor" stroke-width="2"/></svg>`;
|
|
|
+ return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
|
|
|
+}
|
|
|
+
|
|
|
+// 显示句柄右键快捷菜单:定位到句柄下方,先构建再展示
|
|
|
+function showQuickMenu(anchor) {
|
|
|
+ if (!quickMenu) return;
|
|
|
+ renderQuickMenu(currentSettings.quickGroups || []);
|
|
|
+ const r = anchor.getBoundingClientRect();
|
|
|
+ // 贴住句柄左下角
|
|
|
+ positionQuickMenu(r.left, r.bottom + 4);
|
|
|
+}
|
|
|
+
|
|
|
+// 在指定 viewport 坐标处弹出快捷菜单(全局热键用,坐标已由后端换算)
|
|
|
+function showQuickMenuAt(x, y) {
|
|
|
+ if (!quickMenu) return;
|
|
|
+ renderQuickMenu(currentSettings.quickGroups || []);
|
|
|
+ positionQuickMenu(x, y);
|
|
|
+}
|
|
|
+
|
|
|
+// 统一菜单定位:先解除 hidden 使其可测量,再贴住给定坐标,超出视口时收回到边界内
|
|
|
+function positionQuickMenu(x, y) {
|
|
|
+ if (!quickMenu) return;
|
|
|
+ quickMenu.hidden = false; // 先解除 hidden,使测量尺寸可用
|
|
|
+ quickMenu.classList.add('is-open');
|
|
|
+ const menuRect = quickMenu.getBoundingClientRect();
|
|
|
+ let px = Math.min(x, window.innerWidth - menuRect.width - 8);
|
|
|
+ let py = Math.min(y, window.innerHeight - menuRect.height - 8);
|
|
|
+ px = Math.max(8, px);
|
|
|
+ py = Math.max(8, py);
|
|
|
+ quickMenu.style.left = px + 'px';
|
|
|
+ quickMenu.style.top = py + 'px';
|
|
|
+}
|
|
|
+
|
|
|
+// 隐藏句柄右键快捷菜单
|
|
|
+function hideQuickMenu() {
|
|
|
+ if (!quickMenu) return;
|
|
|
+ quickMenu.classList.remove('is-open');
|
|
|
+ quickMenu.hidden = true;
|
|
|
+}
|
|
|
+
|
|
|
function collectForm() {
|
|
|
// 数组字段:表单为空时回退到当前生效配置,避免保存时用空值覆盖已有数据。
|
|
|
// 用户可能在设置页修改单个字段后保存,此时未触碰的 textarea 若为空不能清空原配置。
|
|
|
@@ -1146,6 +1432,8 @@ function collectForm() {
|
|
|
alwaysOnTop: topToggle.checked,
|
|
|
startCompact: !!startCompactToggle?.checked,
|
|
|
hotkey: hotkeyInput.value.trim() || FALLBACK_SETTINGS.hotkey,
|
|
|
+ quickHotkey: quickHotkeyInput ? (quickHotkeyInput.value.trim() || FALLBACK_SETTINGS.quickHotkey) : FALLBACK_SETTINGS.quickHotkey,
|
|
|
+ proxyHotkey: proxyHotkeyInput ? proxyHotkeyInput.value.trim() : '', // 代理热键:留空=不设热键
|
|
|
tabOrder: collectTabOrder(),
|
|
|
stockCodes,
|
|
|
links: parsePipeLines(fallbackArr(linksText, 'links'), 'name', 'url').filter(l => l.name && l.url),
|
|
|
@@ -1154,6 +1442,14 @@ function collectForm() {
|
|
|
githubRepos: parsePipeLines3(fallbackArr(githubReposText, 'githubRepos'), 'url', 'desc', 'version').filter(r => r.url),
|
|
|
customTabs: parsePipeLines3(fallbackArr(customTabsText, 'customTabs'), 'name', 'url', 'desc').filter(t => t.name && t.url),
|
|
|
localTools: parsePipeLines3(fallbackArr(localToolsText, 'localTools'), 'title', 'cmd', 'desc').filter(t => t.title && t.cmd),
|
|
|
+ // 「快捷」页:缩进分层解析(组名 + 名称|路径|说明 条目),表单为空时回退已有配置
|
|
|
+ quickGroups: (() => {
|
|
|
+ const v = quickToolsText.value.trim();
|
|
|
+ if (v) return parseQuickText(v);
|
|
|
+ const cur = currentSettings.quickGroups;
|
|
|
+ if (Array.isArray(cur) && cur.length) return cur;
|
|
|
+ return [];
|
|
|
+ })(),
|
|
|
// 控制页按键:前 5 键固定(顺序 上/下/左/右/休眠),第 6 键起为额外按键;
|
|
|
// 固定键图标空回填默认、命令可空;额外键图标空 = 跳过该行,命令可空
|
|
|
controlKeys: (() => {
|
|
|
@@ -1184,12 +1480,7 @@ function collectForm() {
|
|
|
recordDBPath: recordDBPathInput.value.trim(),
|
|
|
backupDir: backupDirInput.value.trim(),
|
|
|
browserPath: browserPathInput.value.trim(), // 指定浏览器 exe 路径(空=系统默认)
|
|
|
- gitLab: { // 私有 GitLab 自动升级配置
|
|
|
- baseUrl: gitlabUrlInput.value.trim(),
|
|
|
- projectPath: gitlabProjectInput.value.trim(),
|
|
|
- privateToken: gitlabTokenInput.value.trim(),
|
|
|
- branch: gitlabBranchInput.value.trim(),
|
|
|
- },
|
|
|
+ gitLab: currentSettings.gitLab || {}, // 升级源配置仅存于配置文件(设置界面已移除该行),此处透传保留,需修改时手动编辑 settings.json
|
|
|
stockUpColor: fallbackColor(stockUpColorInput, currentSettings.stockUpColor, FALLBACK_SETTINGS.stockUpColor),
|
|
|
stockDownColor: fallbackColor(stockDownColorInput, currentSettings.stockDownColor, FALLBACK_SETTINGS.stockDownColor),
|
|
|
stockRefreshSecs: parseInt(stockRefreshSecsInput.value, 10) || FALLBACK_SETTINGS.stockRefreshSecs,
|
|
|
@@ -1909,11 +2200,13 @@ function setFeedbackStatus(text, ok) {
|
|
|
|
|
|
// 推送到 ntfy:POST https://ntfy.sh/ease,带标题与优先级
|
|
|
async function sendFeedback(text) {
|
|
|
+ // HTTP Header 值仅允许 ISO-8859-1 字节,中文标题必须 URL 编码为 ASCII;
|
|
|
+ // ntfy 会解码 `Title=...` 形式的编码(如 %E8%85%BE...)后显示
|
|
|
const title = `腾图工具箱反馈 ${new Date().toLocaleString('zh-CN', { hour12: false })}`;
|
|
|
const res = await fetch(`https://ntfy.sh/${FEEDBACK_TOPIC}`, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
- 'Title': title,
|
|
|
+ 'Title': encodeURIComponent(title),
|
|
|
'Priority': 'default',
|
|
|
'Tags': 'mega', // 大写字母标签,便于手机端识别
|
|
|
'Content-Type': 'text/plain; charset=utf-8',
|
|
|
@@ -5683,6 +5976,17 @@ Events.On('windowCompact', (event) => {
|
|
|
setCompactUI(!!event.data);
|
|
|
});
|
|
|
|
|
|
+// 「快捷」菜单全局热键:后端已在鼠标位置弹出原生菜单,前端无需定位。
|
|
|
+// (原生 TrackPopupMenu 由后端直接显示在屏幕坐标处,不受 Webview 裁剪)
|
|
|
+Events.On('showQuickMenuAt', (event) => {
|
|
|
+ showNativeQuick();
|
|
|
+});
|
|
|
+
|
|
|
+// 「代理开关」全局热键:后端已切换系统代理,同步刷新工具页「网络代理」卡片状态
|
|
|
+Events.On('proxyChanged', (event) => {
|
|
|
+ renderProxyStatus(event?.data || null);
|
|
|
+});
|
|
|
+
|
|
|
// 托盘菜单点击某个 Tab 同名项:切换到对应页面(后端已先显示窗口)
|
|
|
Events.On('switchTab', (event) => {
|
|
|
const tabId = event?.data;
|
|
|
@@ -5697,6 +6001,46 @@ tabDragHandle?.addEventListener('dblclick', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+// 句柄右键:弹出快捷启动菜单(类似 Biniware Run),条目来自 设置→快捷。
|
|
|
+// 句柄已设为 --wails-draggable: no-drag(style.css),contextmenu 可正常触发;
|
|
|
+// 窗口拖动由父级 .tab-buttons / .win-spacer 承担,不受影响。
|
|
|
+// 注意:句柄仅在「全尺寸」窗口可见(收拢态被 #compact-restore 圆点覆盖),
|
|
|
+// 此时 Webview 足够大,HTML 菜单不会被裁剪,故直接走可靠的 HTML 菜单;
|
|
|
+// 原生 TrackPopupMenu 留给收拢态圆点/全局热键(Webview 太小、HTML 会被裁剪)。
|
|
|
+tabDragHandle?.addEventListener('contextmenu', (e) => {
|
|
|
+ e.preventDefault(); // 屏蔽系统默认右键菜单
|
|
|
+ e.stopPropagation();
|
|
|
+ showQuickMenu(tabDragHandle);
|
|
|
+});
|
|
|
+
|
|
|
+// 兜底:句柄/圆点区域的系统默认右键菜单一律屏蔽,避免弹出无关的 Webview 默认菜单。
|
|
|
+document.addEventListener('contextmenu', (e) => {
|
|
|
+ if (e.target === tabDragHandle || e.target === document.getElementById('compact-restore') ||
|
|
|
+ tabDragHandle?.contains(e.target)) {
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+// 调用后端原生快捷菜单:Wails 环境走后端 TrackPopupMenu(支持分组子菜单 + 程序图标);
|
|
|
+// 浏览器预览无后端或后端调用失败时回退 HTML 菜单(定位到锚点)。
|
|
|
+function showNativeQuick(anchor) {
|
|
|
+ if (typeof QuickService?.ShowQuickMenu === 'function') {
|
|
|
+ QuickService.ShowQuickMenu()
|
|
|
+ .catch(() => { if (anchor) showQuickMenu(anchor); }); // 后端失败回退 HTML 菜单,保证右键有反馈
|
|
|
+ } else if (anchor) {
|
|
|
+ showQuickMenu(anchor);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 点击/滚动/按 Esc 关闭句柄右键菜单;点击菜单内不关闭(由条目自身处理)
|
|
|
+document.addEventListener('mousedown', (e) => {
|
|
|
+ if (quickMenu?.classList.contains('is-open') && !quickMenu.contains(e.target) && e.target !== tabDragHandle && e.target !== compactRestore) {
|
|
|
+ hideQuickMenu();
|
|
|
+ }
|
|
|
+});
|
|
|
+document.addEventListener('wheel', () => hideQuickMenu(), {passive: true});
|
|
|
+document.addEventListener('keydown', (e) => { if (e.key === 'Escape') hideQuickMenu(); });
|
|
|
+
|
|
|
// 居中还原圆点:双击还原窗口大小(紧凑状态下手柄不可见,用此兜底)
|
|
|
const compactRestore = document.getElementById('compact-restore');
|
|
|
compactRestore?.addEventListener('dblclick', () => {
|
|
|
@@ -5706,6 +6050,13 @@ compactRestore?.addEventListener('dblclick', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+// 圆点右键:与句柄一致,弹出快捷启动菜单(收拢后句柄不可见,圆点即交互区)
|
|
|
+compactRestore?.addEventListener('contextmenu', (e) => {
|
|
|
+ e.preventDefault(); // 屏蔽系统默认右键菜单
|
|
|
+ e.stopPropagation();
|
|
|
+ showNativeQuick(compactRestore);
|
|
|
+});
|
|
|
+
|
|
|
// ------------------------------------------------------------------------
|
|
|
// 拖动手柄圆点闪烁:API POST /api/handle/flash 触发,颜色+大小变化动画
|
|
|
// 后端广播 handleFlash 事件(payload 为闪烁次数),前端播放 keyframes 动画
|