-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
908 lines (860 loc) · 22.3 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
/* eslint-disable no-unused-expressions */
const {
app,
BrowserWindow, // 窗口
ipcMain, // 主进程
Tray, // 小图标托盘
dialog, // 对话框
session, // 浏览器下载功能实现
Menu, // 菜单
globalShortcut, // 全局快捷键
clipboard, // 剪切板
Notification, // 通知
nativeImage, // 原生图片对象
} = require('electron');
const path = require('path');
const db = require('./src/datastore');
const { getPicBeds } = require('./src/mainUtils/getPicBeds');
const pkg = require('./package.json');
const Uploader = require('./src/mainUtils/upload');
const pasteTemplate = require('./src/mainUtils/pasteTemplate');
let TransDownFolder = '/Users/hdd/Project/pomelo-upload/downloadFiles'; // 下载文件保存地址
let DownloadList = {}; // 下载文件列表
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') {
global.__static = path.join(__dirname, './build').replace(/\\/g, '\\\\');
}
if (process.env.NODE_ENV === 'development') {
global.__static = path.join(__dirname, '/public').replace(/\\/g, '\\\\');
}
const winURL =
process.env.NODE_ENV === 'development'
? `http://localhost:3000/#/tray-page`
: `file://${__dirname}/build/index.html#/tray-page`;
const settingWinURL =
process.env.NODE_ENV === 'development'
? `http://localhost:3000/#setting/upload`
: `file://${__dirname}/build/index.html#/upload`;
const miniWinURL =
process.env.NODE_ENV === 'development'
? `http://localhost:3000/#mini-page`
: `file://${__dirname}/build/index.html#/mini-page`;
// 保持一个对于 window 对象的全局引用,如果你不这样做,
// 当 JavaScript 对象被垃圾回收, window 会被自动地关闭
let miniWindow;
let settingWindow;
let window;
let tray;
let contextMenu;
let MusicPlayer;
let VideoPlayer;
let PdfWindow;
let FileWindow;
let ZipWindow;
let PictureViewer;
let menu;
let DiskInfo;
/*播放按钮*/
let PlayerIcon = path.join(__static, '/asset/player');
let NextBtn = nativeImage.createFromPath(path.join(PlayerIcon, 'next.png'));
let PlayBtn = nativeImage.createFromPath(path.join(PlayerIcon, 'play.png'));
let PauseBtn = nativeImage.createFromPath(path.join(PlayerIcon, 'pause.png'));
let PrevBtn = nativeImage.createFromPath(path.join(PlayerIcon, 'prev.png'));
let MusicButtons = [
{
tooltip: '上一首',
icon: PrevBtn,
click: () => {
MusicPlayer.webContents.send('Prev');
},
},
{
tooltip: '播放',
icon: PlayBtn,
click: () => {
MusicPlayer.webContents.send('Play');
},
},
{
tooltip: '下一首',
icon: NextBtn,
click: () => {
MusicPlayer.webContents.send('Next');
},
},
];
let VideoButtons = [
/*{
tooltip: '上一个',
icon: PrevBtn,
click: () => {
VideoPlayer.webContents.send('video-Prev');
}
},*/
{
tooltip: '播放',
icon: PlayBtn,
click: () => {
VideoPlayer.webContents.send('video-Play');
},
},
/*{
tooltip: '下一个',
icon:NextBtn,
click: () => {
VideoPlayer.webContents.send('video-Next');
}
}*/
];
// function createWindow () {
// // 创建浏览器窗口。
// window = new BrowserWindow({
// width: 800,
// height: 600,
// autoHideMenuBar: true,
// fullscreenable: false,
// webPreferences: {
// javascript: true,
// plugins: true,
// nodeIntegration: false, // 不集成 Nodejs
// webSecurity: false,
// preload: path.join(__dirname, './public/renderer.js') // 但预加载的 js 文件内仍可以使用 Nodejs 的 API
// }
// })
// // 然后加载应用的 index.html。
// // package中的DEV为true时,开启调试窗口。为false时使用编译发布版本
// if(process.env.NODE_ENV === 'development'){
// window.loadURL('http://localhost:3000/')
// }else{
// window.loadURL(url.format({
// pathname: path.join(__dirname, './build/index.html'),
// protocol: 'file:',
// slashes: true
// }))
// }
/*窗口控制函数*/
let WindowControl = {
New: (options) => {
let win = new BrowserWindow({
width: options.width || 800,
height: options.height || 600,
minWidth: options.minWidth,
minHeight: options.minHeight,
title: options.title || 'pomelo-upload',
frame: true,
useContentSize: options.useContentSize || false,
transparent: options.transparent || false,
x: options.x,
y: options.y,
minimizable:
options.minimizable === undefined ? true : options.minimizable,
maximizable:
options.maximizable === undefined ? true : options.maximizable,
resizable: options.resizable === undefined ? true : options.resizable,
alwaysOnTop:
options.alwaysOnTop === undefined ? false : options.alwaysOnTop,
show: false,
webPreferences: {
webSecurity: process.env.NODE_ENV === 'development' ? false : true,
preload: path.join(__dirname, './public/renderer.js'),
},
});
options.backgroundColor && (win.backgroundColor = options.backgroundColor);
win.name = options.url;
if (options.title === 'PDF阅读器') {
win.loadURL(
process.env.NODE_ENV === 'development'
? `http://localhost:3000/` + options.url
: `file://${__dirname}/build/${options.url}`
);
} else {
win.loadURL(WindowControl.CheckRouter(options.url));
}
win.callback = (data) => {
win.webContents.send('win-data', data);
typeof options.callback === 'function' ? options.callback() : '';
};
win.on('closed', (event) => {
win = null;
typeof options.onclose === 'function' ? options.onclose(event) : '';
});
win.on('ready-to-show', (event) => {
win.show();
win.focus();
typeof options.ready === 'function' ? options.ready(event) : '';
});
win.webContents.on('did-finish-load', () => {
win.setTitle(options.title || 'pomelo-upload');
win.callback(options.data || '无数据');
});
return win;
},
CheckRouter: (router) => {
return process.env.NODE_ENV === 'development'
? `http://localhost:3000/#/` + router
: `file://${__dirname}/build/index.html#/${router}`;
},
Active: (win, data) => {
if (win) {
win.show();
win.focus();
win.callback(data);
}
},
};
/*文件窗口函数*/
let FileViewer = {
Music: (data) => {
if (MusicPlayer) {
return WindowControl.Active(MusicPlayer, data);
}
MusicPlayer = WindowControl.New({
url: 'music-player',
data: data,
title: '音乐播放器',
width: 350,
height: 535,
// maximizable: false,
// minimizable: false,
// resizable: false,
onclose: () => {
MusicPlayer = null;
},
callback: () => {
MusicPlayer.setThumbarButtons(MusicButtons);
},
});
},
Video: (data) => {
if (VideoPlayer) {
return WindowControl.Active(VideoPlayer, data);
}
VideoPlayer = WindowControl.New({
url: 'video-player',
data: data,
title: '视频播放器',
width: 750,
height: 500,
minHeight: 350,
minWidth: 500,
onclose: () => {
VideoPlayer = null;
},
callback: () => {
VideoPlayer.setThumbarButtons(VideoButtons);
},
});
},
Image: (data) => {
if (PictureViewer) {
return WindowControl.Active(PictureViewer, data);
}
PictureViewer = WindowControl.New({
url: 'picture-shower',
data: data,
title: '图片查看',
width: 750,
height: 500,
minHeight: 350,
minWidth: 500,
backgroundColor: '#4f4f4f',
onclose: () => {
PictureViewer = null;
},
});
},
Pdf: (data) => {
if (PdfWindow) {
return WindowControl.Active(PdfWindow, data);
}
PdfWindow = WindowControl.New({
url: `pdf/web/viewer.html?file=${data.downloadUrl}`,
data: data,
title: 'PDF阅读器',
width: 750,
height: 500,
minHeight: 350,
minWidth: 500,
backgroundColor: '#4f4f4f',
onclose: () => {
PdfWindow = null;
},
});
},
Text: (data) => {
if (FileWindow) {
return WindowControl.Active(FileWindow, data);
}
FileWindow = WindowControl.New({
url: 'text-viewer',
data: data,
title: '文件查看',
width: 750,
height: 500,
minHeight: 350,
minWidth: 500,
onclose: () => {
FileWindow = null;
},
});
},
Zip: (data) => {
if (ZipWindow) {
return WindowControl.Active(ZipWindow, data);
}
ZipWindow = WindowControl.New({
url: 'zip-viewer',
data: data,
title: '压缩文件查看',
width: 750,
height: 500,
minHeight: 350,
minWidth: 500,
onclose: () => {
ZipWindow = null;
},
});
},
Attributes: (data) => {
if (DiskInfo) {
return WindowControl.Active(DiskInfo, data);
}
DiskInfo = WindowControl.New({
url: 'info',
data: data,
width: 600,
height: 390,
title: '文件属性',
maximizable: false,
minimizable: false,
resizable: false,
onclose: () => {
DiskInfo = null;
},
});
},
};
/**
* 创建初始窗口
*/
const createWindow = () => {
if (process.platform !== 'darwin' && process.platform !== 'win32') {
return;
}
window = new BrowserWindow({
height: 350,
width: 196, // 196
show: false,
frame: false,
fullscreenable: false,
resizable: true,
transparent: true,
vibrancy: 'ultra-dark',
webPreferences: {
backgroundThrottling: false,
preload: path.join(__dirname, './public/renderer.js'),
},
});
window.loadURL(winURL);
window.on('closed', () => {
window = null;
});
window.on('blur', () => {
window.hide();
});
};
/**
* 创建小窗口
*/
const createMiniWidow = () => {
if (miniWindow) {
return false;
}
let obj = {
height: 64,
width: 64,
show: true,
frame: false,
fullscreenable: false,
skipTaskbar: true,
resizable: false,
transparent: true,
icon: `/public/logo.png`,
webPreferences: {
backgroundThrottling: false,
preload: path.join(__dirname, './public/renderer.js'),
},
};
if (process.platform === 'linux') {
obj.transparent = false;
}
if (process.platform === 'darwin') {
obj.show = false;
}
if (
db
.read()
.get('settings.miniWindowOntop')
.value()
) {
obj.alwaysOnTop = true;
}
miniWindow = new BrowserWindow(obj);
miniWindow.loadURL(miniWinURL);
miniWindow.on('closed', () => {
miniWindow = null;
});
};
/**
* 创建详细窗口
*/
const createSettingWindow = () => {
const options = {
height: 450,
width: 800,
show: false,
frame: true,
center: true,
fullscreenable: true,
resizable: false,
title: 'pomelo-upload',
vibrancy: 'ultra-dark',
transparent: true,
titleBarStyle: 'hidden',
webPreferences: {
backgroundThrottling: false,
javascript: true,
nodeIntegration: false, // 不集成 Nodejs
webSecurity: false,
preload: path.join(__dirname, './public/renderer.js'),
},
};
settingWindow = new BrowserWindow(options);
settingWindow.loadURL(settingWinURL);
settingWindow.on('closed', () => {
settingWindow = null;
if (process.platform === 'linux') {
app.quit();
}
});
/**
*
* electron下载功能
*/
session.defaultSession.removeAllListeners('will-download');
session.defaultSession.on('will-download', (event, item, webContents) => {
console.log('item', TransDownFolder, item.getFilename());
let name = item.getFilename();
item.fileName = name;
item.path = TransDownFolder + '/' + name;
item.setSavePath(TransDownFolder + '/' + name); // 设置保存路径,使Electron不提示保存对话框。
item.on('updated', (event, state) => {
DownloadList[Math.round(item.getStartTime())] = item;
let file = FileObject(item, item.isPaused() ? 'interrupted' : false);
webContents && webContents.send('download', file);
});
item.once('done', (event, state) => {
let file = FileObject(item, item.isPaused() ? 'interrupted' : false);
webContents && webContents.send('download', file);
if (state === 'completed') {
delete DownloadList[Math.round(item.getStartTime())];
} else {
console.log(`Download failed: ${state}`);
}
});
});
createMenu();
createMiniWidow();
};
/**
* 创建菜单
*/
const createMenu = () => {
if (process.env.NODE_ENV !== 'development') {
const template = [
{
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
selector: 'redo:',
},
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
selector: 'selectAll:',
},
{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click() {
app.quit();
},
},
],
},
];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
};
function createContextMenu() {
const picBeds = getPicBeds(app);
const submenu = picBeds.map((item) => {
return {
label: item.name,
type: 'radio',
checked:
db
.read()
.get('picBed.current')
.value() === item.type,
click() {
db.read()
.set('picBed.current', item.type)
.write();
if (settingWindow) {
settingWindow.webContents.send('syncPicBed');
}
},
};
});
contextMenu = Menu.buildFromTemplate([
{
label: '关于',
click() {
dialog.showMessageBox({
title: 'Pomelo Upload',
message: 'Pomelo Upload',
detail: `Version: ${
pkg.version
}\nAuthor: Yurisa\nGithub: https://github.com/Yurisa/pomelo-upload`,
});
},
},
{
label: '打开详细窗口',
click() {
if (settingWindow === null) {
createSettingWindow();
settingWindow.show();
} else {
settingWindow.show();
settingWindow.focus();
}
if (miniWindow) {
miniWindow.hide();
}
},
},
{
label: '重启应用',
click() {
app.relaunch();
app.exit(0);
},
},
{
role: 'quit',
label: '退出',
},
]);
}
function createTray() {
const menubarPic =
process.platform === 'darwin' ? `${__static}/asset/logo.png` : '';
tray = new Tray(menubarPic);
tray.on('right-click', () => {
if (window) {
window.hide();
}
createContextMenu();
tray.popUpContextMenu(contextMenu);
});
// 打开tray时进行剪切板的图片预览
tray.on('click', (event, bounds) => {
if (process.platform === 'darwin') {
let img = clipboard.readImage();
let obj = [];
if (!img.isEmpty()) {
// 从剪贴板来的图片默认转为png
const imgUrl =
'data:image/png;base64,' +
Buffer.from(img.toPNG(), 'binary').toString('base64');
obj.push({
width: img.getSize().width,
height: img.getSize().height,
imgUrl,
});
}
toggleWindow(bounds);
setTimeout(() => {
window.webContents.send('clipboardFiles', obj);
}, 0);
} else {
if (window) {
window.hide();
}
if (settingWindow === null) {
createSettingWindow();
settingWindow.show();
} else {
settingWindow.show();
settingWindow.focus();
}
if (miniWindow) {
miniWindow.hide();
}
}
});
tray.on('drag-enter', () => {
tray.setImage(`${__static}/asset/upload.png`);
});
tray.on('drag-end', () => {
tray.setImage(`${__static}/asset/logo.png`);
});
/**
* 小图标拖拽上传
*/
tray.on('drop-files', async (event, files) => {
const pasteStyle =
db
.read()
.get('settings.pasteStyle')
.value() || 'markdown';
const imgs = await new Uploader(files, window.webContents).upload();
if (imgs !== false) {
for (let i in imgs) {
const url = imgs[i].url || imgs[i].imgUrl;
clipboard.writeText(pasteTemplate(db, pasteStyle, url));
const notification = new Notification({
title: '上传成功',
body: imgs[i].imgUrl,
icon: files[i],
});
setTimeout(() => {
notification.show();
}, i * 100);
db.read()
.get('uploaded')
.insert(imgs[i])
.write();
}
window.webContents.send('dragFiles', imgs);
}
});
// toggleWindow()
}
ipcMain.on('uploadClipboardFiles', () => {
uploadClipboardFiles();
});
/**
* 上传剪切板文件
*/
const uploadClipboardFiles = async () => {
let win;
if (miniWindow.isVisible()) {
win = miniWindow;
} else {
win = settingWindow || window;
}
let img = await new Uploader(undefined, win.webContents).upload();
if (img !== false) {
if (img.length > 0) {
const pasteStyle =
db
.read()
.get('settings.pasteStyle')
.value() || 'markdown';
const url = img[0].url || img[0].imgUrl;
clipboard.writeText(pasteTemplate(db, pasteStyle, url));
const notification = new Notification({
title: '上传成功',
body: img[0].imgUrl,
icon: img[0].imgUrl, // 此处有区别
});
notification.show();
db.read()
.get('uploaded')
.insert(img[0])
.write();
window.webContents.send('clipboardFiles', []); // 将traypage等待上传的文件数组清空
window.webContents.send('uploadFiles', img);
if (settingWindow) {
settingWindow.webContents.send('updateGallery');
}
} else {
const notification = new Notification({
title: '上传不成功',
body: '你剪贴板最新的一条记录不是图片哦',
});
notification.show();
}
}
};
/*播放器操作事件*/
ipcMain.on('player-control', (event, type, data) => {
switch (type) {
case 'audio':
if (data === 'pause') {
MusicButtons[1].icon = PauseBtn;
MusicButtons[1].tooltip = '暂停';
} else {
MusicButtons[1].icon = PlayBtn;
MusicButtons[1].tooltip = '播放';
}
MusicPlayer.setThumbarButtons(MusicButtons);
break;
case 'video':
if (data === 'pause') {
VideoButtons[0].icon = PauseBtn;
VideoButtons[0].tooltip = '暂停';
} else {
VideoButtons[0].icon = PlayBtn;
VideoButtons[0].tooltip = '播放';
}
VideoPlayer.setThumbarButtons(VideoButtons);
break;
}
});
/*下载事件控制*/
ipcMain.on('download', (event, type, data) => {
let downloadItem = DownloadList[data];
if (downloadItem === undefined) {
return;
}
switch (type) {
case 'pause':
downloadItem.pause();
break;
case 'cancel':
downloadItem.cancel();
break;
case 'resume':
if (downloadItem.canResume()) {
downloadItem.resume();
}
break;
}
});
/*网盘文件操作事件*/
ipcMain.on('file-control', (event, type, data) => {
switch (type) {
case 'audio': //音频
FileViewer.Music(data);
break;
case 'video': //视频
FileViewer.Video(data);
break;
case 'image': //图片
FileViewer.Image(data);
break;
case 'pdf':
FileViewer.Pdf(data);
break;
case 'zip':
FileViewer.Zip(data);
break;
case 'text': //文本
FileViewer.Text(data);
break;
case 'attributes': //属性
FileViewer.Attributes(data);
break;
}
});
/*网盘函数*/
function FileObject(item, state) {
return {
id: Math.round(item.getStartTime()),
url: item.getURLChain(),
time: item.getStartTime(),
name: item.fileName,
path: item.path,
chunk: item.getReceivedBytes(),
size: item.getTotalBytes(),
trans_type: 'download',
state: state || item.getState(),
disk_main: item.getURL(),
canResume: item.canResume(),
shows: true,
};
}
const toggleWindow = (bounds) => {
if (window.isVisible()) {
window.hide();
} else {
showWindow(bounds);
}
};
const showWindow = (bounds) => {
window.setPosition(bounds.x - 98 + 11, bounds.y, false);
window.webContents.send('updateFiles');
window.show();
window.focus();
};
// 打开开发者工具。
// window.webContents.openDevTools()
// Electron 会在初始化后并准备
// 创建浏览器窗口时,调用这个函数。
// 部分 API 在 ready 事件触发后才能使用。
app.on('ready', () => {
createWindow();
createSettingWindow();
if (process.platform === 'darwin' || process.platform === 'win32') {
createTray();
}
db.read()
.set('needReload', false)
.write();
globalShortcut.register(
db
.read()
.get('settings.shortKey.upload')
.value(),
() => {
uploadClipboardFiles();
}
);
});
// 当全部窗口关闭时退出。
app.on('window-all-closed', () => {
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
// 否则绝大部分应用及其菜单栏会保持激活。
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (window === null) {
createWindow();
}
if (settingWindow === null) {
createSettingWindow();
}
});
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});
app.setLoginItemSettings({
openAtLogin:
db
.read()
.get('settings.autoStart')
.value() || false,
});
// 在这文件,你可以续写应用剩下主进程代码。
// 也可以拆分成几个文件,然后用 require 导入。
// 在这里可以添加一些electron相关的其他模块,比如nodejs的一些原生模块
// 文件模块
// const BTFile = require('./sys_modules/BTFile')
// BTFile.getAppPath()