refactor: improve code formatting and consistency across components

- Updated button and span elements in ThemeToggle.vue and TopActions.vue for better readability.
- Enhanced UninstallConfirmModal.vue and UpdateAppsModal.vue with consistent indentation and spacing.
- Refactored downloadStatus.ts and storeConfig.ts for improved code clarity.
- Standardized string quotes and spacing in typedefinition.ts and processInstall.ts.
- Ensured consistent use of arrow functions and improved variable declarations throughout the codebase.
This commit is contained in:
Elysia
2026-02-12 18:32:41 +08:00
parent e11740ad4c
commit 6622e70033
29 changed files with 1681 additions and 1042 deletions

View File

@@ -1,24 +1,23 @@
import { app, BrowserWindow, ipcMain, Menu, shell, Tray } from 'electron'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs'
import pino from 'pino'
import { handleCommandLine } from './deeplink.js'
import { isLoaded } from '../global.js'
import { tasks } from './backend/install-manager.js'
import { app, BrowserWindow, ipcMain, Menu, shell, Tray } from "electron";
import { fileURLToPath } from "node:url";
import path from "node:path";
import os from "node:os";
import fs from "node:fs";
import pino from "pino";
import { handleCommandLine } from "./deeplink.js";
import { isLoaded } from "../global.js";
import { tasks } from "./backend/install-manager.js";
// Assure single instance application
if (!app.requestSingleInstanceLock()) {
app.exit(0);
}
import './backend/install-manager.js'
import './handle-url-scheme.js'
import "./backend/install-manager.js";
import "./handle-url-scheme.js";
const logger = pino({ 'name': 'index.ts' });
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const logger = pino({ name: "index.ts" });
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// The built directory structure
//
@@ -30,38 +29,38 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//
process.env.APP_ROOT = path.join(__dirname, '../..')
process.env.APP_ROOT = path.join(__dirname, "../..");
export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron')
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist')
export const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL
export const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron");
export const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist");
export const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL;
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
? path.join(process.env.APP_ROOT, 'public')
: RENDERER_DIST
? path.join(process.env.APP_ROOT, "public")
: RENDERER_DIST;
// Disable GPU Acceleration for Windows 7
if (os.release().startsWith('6.1')) app.disableHardwareAcceleration()
if (os.release().startsWith("6.1")) app.disableHardwareAcceleration();
// Set application name for Windows 10+ notifications
if (process.platform === 'win32') app.setAppUserModelId(app.getName())
if (process.platform === "win32") app.setAppUserModelId(app.getName());
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
app.quit();
process.exit(0);
}
let win: BrowserWindow | null = null
const preload = path.join(__dirname, '../preload/index.mjs')
const indexHtml = path.join(RENDERER_DIST, 'index.html')
let win: BrowserWindow | null = null;
const preload = path.join(__dirname, "../preload/index.mjs");
const indexHtml = path.join(RENDERER_DIST, "index.html");
async function createWindow() {
win = new BrowserWindow({
title: 'APM AppStore',
title: "APM AppStore",
width: 1366,
height: 768,
autoHideMenuBar: true,
icon: path.join(process.env.VITE_PUBLIC, 'favicon.ico'),
icon: path.join(process.env.VITE_PUBLIC, "favicon.ico"),
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
@@ -71,30 +70,31 @@ async function createWindow() {
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
// contextIsolation: false,
},
})
});
if (VITE_DEV_SERVER_URL) { // #298
win.loadURL(VITE_DEV_SERVER_URL)
if (VITE_DEV_SERVER_URL) {
// #298
win.loadURL(VITE_DEV_SERVER_URL);
// Open devTool if the app is not packaged
win.webContents.openDevTools({mode:'detach'})
win.webContents.openDevTools({ mode: "detach" });
} else {
win.loadFile(indexHtml)
win.loadFile(indexHtml);
}
// Test actively push message to the Electron-Renderer
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
logger.info('Renderer process is ready.');
})
win.webContents.on("did-finish-load", () => {
win?.webContents.send("main-process-message", new Date().toLocaleString());
logger.info("Renderer process is ready.");
});
// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('https:')) shell.openExternal(url)
return { action: 'deny' }
})
if (url.startsWith("https:")) shell.openExternal(url);
return { action: "deny" };
});
// win.webContents.on('will-navigate', (event, url) => { }) #344
win.on('close', (event) => {
win.on("close", (event) => {
// 截获 close 默认行为
event.preventDefault();
// 点击关闭时触发close事件我们按照之前的思路在关闭时隐藏窗口隐藏任务栏窗口
@@ -103,50 +103,52 @@ async function createWindow() {
win.setSkipTaskbar(true);
} else {
// 如果没有下载任务,才允许关闭窗口
win.destroy()
win.destroy();
}
})
});
}
ipcMain.on('renderer-ready', (event, args) => {
logger.info('Received renderer-ready event with args: ' + JSON.stringify(args));
ipcMain.on("renderer-ready", (event, args) => {
logger.info(
"Received renderer-ready event with args: " + JSON.stringify(args),
);
isLoaded.value = args.status;
logger.info(`isLoaded set to: ${isLoaded.value}`);
})
});
app.whenReady().then(() => {
createWindow()
handleCommandLine(process.argv)
})
createWindow();
handleCommandLine(process.argv);
});
app.on('window-all-closed', () => {
win = null
if (process.platform !== 'darwin') app.quit()
})
app.on("window-all-closed", () => {
win = null;
if (process.platform !== "darwin") app.quit();
});
app.on('second-instance', () => {
app.on("second-instance", () => {
if (win) {
// Focus on the main window if the user tried to open another
if (win.isMinimized()) win.restore()
win.focus()
if (win.isMinimized()) win.restore();
win.focus();
}
})
});
app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
app.on("activate", () => {
const allWindows = BrowserWindow.getAllWindows();
if (allWindows.length) {
allWindows[0].focus()
allWindows[0].focus();
} else {
createWindow()
createWindow();
}
})
});
// 设置托盘
// 获取图标路径
function getIconPath() {
let iconPath = "";
const iconFile = process.platform === "win32" ? "amber-pm-logo.ico" : "amber-pm-logo.png"; // 图标文件名linux下需要png格式不然会不显示
const iconFile =
process.platform === "win32" ? "amber-pm-logo.ico" : "amber-pm-logo.png"; // 图标文件名linux下需要png格式不然会不显示
// 判断是否在打包模式
if (app.isPackaged) {
// 打包模式
@@ -170,31 +172,35 @@ function getIconPath() {
let tray = null;
app.whenReady().then(() => {
tray = new Tray(getIconPath());
const contextMenu = Menu.buildFromTemplate([{
label: '显示主界面',
click: () => { win.show() }
tray = new Tray(getIconPath());
const contextMenu = Menu.buildFromTemplate([
{
label: "显示主界面",
click: () => {
win.show();
},
},
{
label: '退出程序',
click: () => { win.destroy() }
label: "退出程序",
click: () => {
win.destroy();
},
},
]);
tray.setToolTip("APM 应用商店");
tray.setContextMenu(contextMenu);
// 双击触发
tray.on("click", () => {
// 双击通知区图标实现应用的显示或隐藏
if (win.isVisible()) {
win.hide();
win.setSkipTaskbar(true);
} else {
win.show();
win.setSkipTaskbar(false);
}
]);
tray.setToolTip('APM 应用商店')
tray.setContextMenu(contextMenu)
// 双击触发
tray.on('click', () => {
// 双击通知区图标实现应用的显示或隐藏
if (win.isVisible()) {
win.hide();
win.setSkipTaskbar(true);
} else {
win.show();
win.setSkipTaskbar(false);
}
});
})
});
});
// New window example arg: new windows url
// ipcMain.handle('open-win', (_, arg) => {