Skip to content

Commit 05f2ac8

Browse files
committed
feat:注册scheme
1 parent d209ec3 commit 05f2ac8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

electron/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export default {
1111
url: isDev ? "http://127.0.0.1:3030" : "https://tool.hellowmonkey.cc",
1212
youdaoAppId: "4942fc478d27c774",
1313
youdaoKey: "qLDdY5g9qUNQN8WV1WBSVOGYjRfug0mq",
14+
scheme: "tool-box",
1415
};

electron/main/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, SaveDialogOptions, Tray, Notification, shell } from "electron";
2-
import { join } from "path";
2+
import { join, resolve } from "path";
33
import { writeJSONSync, readJSONSync, existsSync, mkdirSync } from "fs-extra";
44
import chokidar from "chokidar";
55
import { compressImage, pngToIco } from "./image";
@@ -190,6 +190,16 @@ app
190190
}
191191
});
192192

193+
// 设置注册表
194+
// app.removeAsDefaultProtocolClient(config.scheme, process.execPath, [resolve(process.argv[1])]);
195+
if (!app.isDefaultProtocolClient(config.scheme)) {
196+
if (app.isPackaged) {
197+
app.setAsDefaultProtocolClient(config.scheme);
198+
} else {
199+
app.setAsDefaultProtocolClient(config.scheme, process.execPath, [resolve(process.argv[1])]);
200+
}
201+
}
202+
193203
app.on("window-all-closed", () => {
194204
if (process.platform !== "darwin") {
195205
destroyApp();
@@ -200,7 +210,12 @@ const gotTheLock = app.requestSingleInstanceLock();
200210
if (!gotTheLock) {
201211
destroyApp();
202212
} else {
203-
app.on("second-instance", () => {
213+
app.on("second-instance", (e, args) => {
214+
const schemeUrl = args[args.length - 1];
215+
const reg = new RegExp(`^${config.scheme}:\/\/`);
216+
if (reg.test(schemeUrl)) {
217+
win.loadURL(schemeUrl.replace(reg, config.url + "/"));
218+
}
204219
showWin();
205220
});
206221
}

0 commit comments

Comments
 (0)