Skip to content

Commit 857ddb7

Browse files
committed
feat:scheme处理
1 parent 05f2ac8 commit 857ddb7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

electron/main/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, SaveDialogOptions, Tray, Notification, shell } from "electron";
1+
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, SaveDialogOptions, Tray, Notification, shell, dialog } from "electron";
22
import { join, resolve } from "path";
33
import { writeJSONSync, readJSONSync, existsSync, mkdirSync } from "fs-extra";
44
import chokidar from "chokidar";
@@ -11,6 +11,8 @@ import defaultUserConfig from "../data/config.json";
1111

1212
let tray: Tray, win: BrowserWindow;
1313

14+
const schemeReg = new RegExp(`^${config.scheme}:\/\/`);
15+
1416
const userConfigPath = app.getPath("userData");
1517
const userConfigFile = join(userConfigPath, "config.json");
1618
if (!existsSync(userConfigPath)) {
@@ -128,7 +130,13 @@ function createWindow() {
128130
win.setIcon(config.icon);
129131
win.removeMenu();
130132

131-
win.loadURL(config.url).then(() => {
133+
let { url } = config;
134+
const schemeUrl = process.argv[process.argv.length - 1];
135+
if (schemeReg.test(schemeUrl)) {
136+
url = schemeUrl.replace(schemeReg, config.url + "/");
137+
}
138+
139+
win.loadURL(url).then(() => {
132140
loading.hide();
133141
loading.close();
134142
});
@@ -191,14 +199,14 @@ app
191199
});
192200

193201
// 设置注册表
194-
// app.removeAsDefaultProtocolClient(config.scheme, process.execPath, [resolve(process.argv[1])]);
195202
if (!app.isDefaultProtocolClient(config.scheme)) {
196203
if (app.isPackaged) {
197204
app.setAsDefaultProtocolClient(config.scheme);
198205
} else {
199206
app.setAsDefaultProtocolClient(config.scheme, process.execPath, [resolve(process.argv[1])]);
200207
}
201208
}
209+
// app.removeAsDefaultProtocolClient(config.scheme, process.execPath, [resolve(process.argv[1])]);
202210

203211
app.on("window-all-closed", () => {
204212
if (process.platform !== "darwin") {
@@ -212,9 +220,8 @@ if (!gotTheLock) {
212220
} else {
213221
app.on("second-instance", (e, args) => {
214222
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 + "/"));
223+
if (schemeReg.test(schemeUrl)) {
224+
win.loadURL(schemeUrl.replace(schemeReg, config.url + "/"));
218225
}
219226
showWin();
220227
});

0 commit comments

Comments
 (0)