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" ;
22import { join , resolve } from "path" ;
33import { writeJSONSync , readJSONSync , existsSync , mkdirSync } from "fs-extra" ;
44import chokidar from "chokidar" ;
@@ -11,6 +11,8 @@ import defaultUserConfig from "../data/config.json";
1111
1212let tray : Tray , win : BrowserWindow ;
1313
14+ const schemeReg = new RegExp ( `^${ config . scheme } :\/\/` ) ;
15+
1416const userConfigPath = app . getPath ( "userData" ) ;
1517const userConfigFile = join ( userConfigPath , "config.json" ) ;
1618if ( ! 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])]);
195202if ( ! 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
203211app . 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