-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackground.js
105 lines (98 loc) · 3.27 KB
/
background.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
const startNeteaseMusicApi = require('./src/electron/services')
const IpcMainEvent = require('./src/electron/ipcMain')
const MusicDownload = require('./src/electron/download')
const LocalFiles = require('./src/electron/localmusic')
const InitTray = require('./src/electron/tray')
const registerShortcuts = require('./src/electron/shortcuts')
const { app, BrowserWindow, globalShortcut } = require('electron')
const Winstate = require('electron-win-state').default
const { autoUpdater } = require("electron-updater");
const path = require('path')
const Store = require('electron-store');
const settingsStore = new Store({name: 'settings'});
let myWindow = null
//electron单例
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
if (myWindow) {
if (myWindow.isMinimized()) myWindow.restore()
if (!myWindow.isVisible()) myWindow.show()
myWindow.focus()
}
})
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
app.on('will-quit', () => {
// 注销所有快捷键
globalShortcut.unregisterAll()
})
}
const createWindow = () => {
process.env.DIST = path.join(__dirname, './')
const indexHtml = path.join(process.env.DIST, 'dist/index.html')
const winstate = new Winstate({
//自定义默认窗口大小
defaultWidth: 1024,
defaultHeight: 672,
})
const win = new BrowserWindow({
minWidth: 1024,
minHeight: 672,
frame: false,
title: "Helium Music",
icon: path.resolve(__dirname, './src/assets/icon/icon.ico'),
backgroundColor: '#fff',
//记录窗口大小
...winstate.winOptions,
show: false,
webPreferences: {
//预加载脚本
preload: path.resolve(__dirname, './src/electron/preload.js'),
webSecurity: false,
}
})
myWindow = win
if(process.resourcesPath.indexOf('\\node_modules\\') != -1)
win.loadURL('http://localhost:5173/')
else
win.loadFile(indexHtml)
win.once('ready-to-show', () => {
win.show()
if(process.resourcesPath.indexOf('\\node_modules\\') == -1) {
autoUpdater.autoDownload = false
autoUpdater.on('update-available', info => {
win.webContents.send('check-update', info.version)
});
autoUpdater.checkForUpdatesAndNotify()
}
})
winstate.manage(win)
win.on('close', async (event) => {
event.preventDefault()
const settings = await settingsStore.get('settings')
if(settings.other.quitApp == 'minimize') {
win.hide()
} else if(settings.other.quitApp == 'quit') {
win.webContents.send('player-save')
}
})
//api初始化
startNeteaseMusicApi()
//ipcMain初始化
IpcMainEvent(win, app)
MusicDownload(win)
LocalFiles(win, app)
InitTray(win, app, path.resolve(__dirname, './src/assets/icon/icon.ico'))
registerShortcuts(win)
}
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';