mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-13 12:52:10 +08:00
160 lines
4.4 KiB
TypeScript
160 lines
4.4 KiB
TypeScript
import { app, BrowserWindow, dialog } from "electron";
|
|
import { release } from "node:os";
|
|
import { join, dirname } from "node:path";
|
|
import indexIpcEvent from "./main/ipcEvent";
|
|
import classificationIpcEvent from "./classification/ipcEvent";
|
|
import { init as classificationDataInit } from "./classification/data";
|
|
import { init as itemDataInit } from "./item/data";
|
|
import { initSystemItem } from "./item/commons/data";
|
|
import commonIpcEvent from "./commons/ipcEvent";
|
|
import itemIpcEvent from "./item/ipcEvent";
|
|
import settingIpcEvent from "./setting/ipcEvent";
|
|
import { init as settingDataInit } from "./setting/data";
|
|
import { setShortcutKey } from "./setting";
|
|
import searchIpcEvent from "./search/ipcEvent";
|
|
import { createMainWindow } from "./main";
|
|
import { closeAllChildProcess } from "./commons";
|
|
import { createQuickSearchWindow } from "./search";
|
|
import { getLanguage } from "../../commons/data/languages";
|
|
import aboutIpcEvent from "./about/ipcEvent";
|
|
import dataIpcEvent from "./data/ipcEvent";
|
|
|
|
// 数据存储目录
|
|
if (
|
|
process.env.NODE_ENV !== "development" &&
|
|
import.meta.env.VITE_INSTALL === "false"
|
|
) {
|
|
app.setPath("appData", join(dirname(process.execPath), "data"));
|
|
app.setPath("userData", join(dirname(process.execPath), "data"));
|
|
}
|
|
|
|
process.env.DIST_ELECTRON = join(__dirname, "..");
|
|
process.env.DIST = join(process.env.DIST_ELECTRON, "../dist");
|
|
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
|
|
? join(process.env.DIST_ELECTRON, "../public")
|
|
: process.env.DIST;
|
|
|
|
// Disable GPU Acceleration for Windows 7
|
|
if (release().startsWith("6.1")) app.disableHardwareAcceleration();
|
|
|
|
// Set application name for Windows 10+ notifications
|
|
if (process.platform === "win32") app.setAppUserModelId(app.getName());
|
|
|
|
if (!app.requestSingleInstanceLock()) {
|
|
app.quit();
|
|
process.exit(0);
|
|
}
|
|
|
|
// Remove electron security warnings
|
|
// This warning only shows in development mode
|
|
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
|
|
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
|
app.whenReady().then(() => {
|
|
try {
|
|
// addon
|
|
global.addon = require("../../native/addon.node");
|
|
// 初始化数据
|
|
settingDataInit();
|
|
// 获取语言
|
|
global.language = getLanguage(global.setting.general.language);
|
|
// 禁用debugtron
|
|
for (let i = 0; i < process.argv.length; i++) {
|
|
const arg = process.argv[i];
|
|
if (
|
|
arg.indexOf("--inspect") !== -1 ||
|
|
arg.indexOf("--remote-debugging-port") !== -1
|
|
) {
|
|
dialog.showMessageBoxSync(null, {
|
|
message: "达咩呦达咩达咩~",
|
|
buttons: [global.language.ok],
|
|
type: "error",
|
|
noLink: true,
|
|
});
|
|
app.quit();
|
|
return;
|
|
}
|
|
}
|
|
// 禁止多开
|
|
const instanceLock = app.requestSingleInstanceLock();
|
|
if (!instanceLock) {
|
|
app.quit();
|
|
return;
|
|
}
|
|
// 初始化数据
|
|
classificationDataInit();
|
|
itemDataInit();
|
|
initSystemItem();
|
|
// 初始化监听
|
|
indexIpcEvent();
|
|
commonIpcEvent();
|
|
classificationIpcEvent();
|
|
itemIpcEvent();
|
|
settingIpcEvent();
|
|
searchIpcEvent();
|
|
aboutIpcEvent();
|
|
dataIpcEvent();
|
|
// 创建主窗口
|
|
createMainWindow();
|
|
if (global.setting.quickSearch.enable) {
|
|
// 创建快速搜索窗口
|
|
createQuickSearchWindow();
|
|
}
|
|
// 设置快捷键
|
|
setShortcutKey();
|
|
} catch (e) {
|
|
if (process.env.NODE_ENV === "development") {
|
|
console.log(e);
|
|
} else {
|
|
dialog.showMessageBoxSync({
|
|
type: "error",
|
|
title: "Dawn Launcher",
|
|
message: e.stack,
|
|
});
|
|
app.quit();
|
|
}
|
|
}
|
|
});
|
|
|
|
// 全局异常
|
|
process.on("uncaughtException", (err) => {
|
|
dialog.showMessageBoxSync({
|
|
type: "error",
|
|
title: "Dawn Launcher",
|
|
message: err.stack,
|
|
});
|
|
// 关闭所有子进程
|
|
closeAllChildProcess();
|
|
// 退出
|
|
app.quit();
|
|
});
|
|
|
|
app.on("before-quit", () => {
|
|
// 关闭所有子进程
|
|
closeAllChildProcess();
|
|
});
|
|
|
|
app.on("window-all-closed", () => {
|
|
if (process.platform !== "darwin") app.quit();
|
|
});
|
|
|
|
app.on("second-instance", () => {
|
|
if (mainWindow) {
|
|
if (!mainWindow.isVisible()) {
|
|
mainWindow.show();
|
|
mainWindow.focus();
|
|
global.blurHide = true;
|
|
} else {
|
|
mainWindow.focus();
|
|
}
|
|
}
|
|
});
|
|
|
|
app.on("activate", () => {
|
|
const allWindows = BrowserWindow.getAllWindows();
|
|
if (allWindows.length) {
|
|
allWindows[0].focus();
|
|
} else {
|
|
createMainWindow();
|
|
}
|
|
});
|