2019-08-23 11:28:54 +00:00
|
|
|
const { app, BrowserWindow, Menu } = require('electron')
|
2019-08-16 09:27:23 +00:00
|
|
|
const path = require('path')
|
|
|
|
|
2019-09-04 05:08:32 +00:00
|
|
|
// 单例应用程序
|
|
|
|
if (!app.requestSingleInstanceLock()) {
|
|
|
|
app.quit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
app.on('second-instance', (event, argv, cwd) => {
|
|
|
|
if (mainWindow) {
|
|
|
|
if (mainWindow.isMinimized()) mainWindow.restore()
|
|
|
|
mainWindow.focus()
|
|
|
|
} else {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-27 13:42:19 +00:00
|
|
|
require('../common/error')
|
2019-08-16 09:27:23 +00:00
|
|
|
require('./events')
|
|
|
|
const autoUpdate = require('./utils/autoUpdate')
|
2019-08-23 11:28:54 +00:00
|
|
|
const { isLinux, isMac } = require('../common/utils')
|
2019-10-21 17:25:03 +00:00
|
|
|
const { getWindowSizeInfo } = require('./utils')
|
2019-08-16 09:27:23 +00:00
|
|
|
|
|
|
|
const isDev = process.env.NODE_ENV !== 'production'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set `__static` path to static files in production
|
|
|
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
let mainWindow
|
|
|
|
let winURL
|
2019-09-10 01:03:57 +00:00
|
|
|
let isFirstCheckedUpdate = true
|
2019-08-16 09:27:23 +00:00
|
|
|
|
|
|
|
if (isDev) {
|
|
|
|
global.__static = path.join(__dirname, '../static')
|
2019-09-08 17:05:30 +00:00
|
|
|
winURL = 'http://localhost:9080'
|
2019-08-16 09:27:23 +00:00
|
|
|
} else {
|
|
|
|
global.__static = path.join(__dirname, '/static')
|
|
|
|
winURL = `file://${__dirname}/index.html`
|
|
|
|
}
|
|
|
|
|
|
|
|
function createWindow() {
|
2019-10-21 17:25:03 +00:00
|
|
|
let windowSizeInfo = getWindowSizeInfo()
|
2019-08-16 09:27:23 +00:00
|
|
|
/**
|
|
|
|
* Initial window options
|
|
|
|
*/
|
2019-09-09 18:03:09 +00:00
|
|
|
mainWindow = global.mainWindow = new BrowserWindow({
|
2019-10-21 17:25:03 +00:00
|
|
|
height: windowSizeInfo.height,
|
2019-08-16 09:27:23 +00:00
|
|
|
useContentSize: true,
|
2019-10-21 17:25:03 +00:00
|
|
|
width: windowSizeInfo.width,
|
2019-08-16 09:27:23 +00:00
|
|
|
frame: false,
|
2019-08-23 11:28:54 +00:00
|
|
|
transparent: !isLinux,
|
2019-11-03 01:53:19 +00:00
|
|
|
enableRemoteModule: false,
|
2019-08-23 11:28:54 +00:00
|
|
|
// icon: path.join(global.__static, isWin ? 'icons/256x256.ico' : 'icons/512x512.png'),
|
2019-08-16 09:27:23 +00:00
|
|
|
resizable: false,
|
|
|
|
maximizable: false,
|
|
|
|
fullscreenable: false,
|
|
|
|
webPreferences: {
|
|
|
|
// contextIsolation: true,
|
|
|
|
webSecurity: !isDev,
|
|
|
|
nodeIntegration: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.loadURL(winURL)
|
|
|
|
|
2019-09-10 01:03:57 +00:00
|
|
|
mainWindow.on('close', () => {
|
|
|
|
mainWindow.setProgressBar(-1)
|
|
|
|
})
|
2019-08-16 09:27:23 +00:00
|
|
|
mainWindow.on('closed', () => {
|
2019-09-09 18:03:09 +00:00
|
|
|
mainWindow = global.mainWindow = null
|
2019-08-16 09:27:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// mainWindow.webContents.openDevTools()
|
|
|
|
|
2019-09-10 01:03:57 +00:00
|
|
|
if (!isDev) {
|
|
|
|
autoUpdate(isFirstCheckedUpdate)
|
|
|
|
isFirstCheckedUpdate = false
|
2019-09-09 18:03:09 +00:00
|
|
|
}
|
2019-08-16 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 11:28:54 +00:00
|
|
|
if (isMac) {
|
|
|
|
const template = [
|
|
|
|
{
|
|
|
|
label: app.getName(),
|
2019-09-11 12:50:34 +00:00
|
|
|
submenu: [
|
2019-09-11 13:43:30 +00:00
|
|
|
{ label: '关于洛雪音乐', role: 'about' },
|
|
|
|
{ type: 'separator' },
|
2019-09-11 12:50:34 +00:00
|
|
|
{ label: '隐藏', role: 'hide' },
|
|
|
|
{ label: '显示其他', role: 'hideothers' },
|
|
|
|
{ label: '显示全部', role: 'unhide' },
|
|
|
|
{ type: 'separator' },
|
2019-09-11 13:43:30 +00:00
|
|
|
{ label: '退出', accelerator: 'Command+Q', click: () => app.quit() },
|
2019-09-11 12:50:34 +00:00
|
|
|
],
|
2019-08-23 11:28:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '窗口',
|
|
|
|
role: 'window',
|
2019-09-11 12:50:34 +00:00
|
|
|
submenu: [
|
|
|
|
{ label: '最小化', role: 'minimize' },
|
|
|
|
{ label: '关闭', role: 'close' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '编辑',
|
|
|
|
submenu: [
|
|
|
|
{ label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo' },
|
|
|
|
{ label: '恢复', accelerator: 'Shift+CmdOrCtrl+Z', role: 'redo' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
|
|
|
|
{ label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
|
|
|
|
{ label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' },
|
|
|
|
{ label: '选择全部', accelerator: 'CmdOrCtrl+A', role: 'selectAll' },
|
|
|
|
],
|
2019-08-23 11:28:54 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
|
|
|
|
} else {
|
|
|
|
Menu.setApplicationMenu(null)
|
|
|
|
}
|
|
|
|
|
2019-09-05 14:41:10 +00:00
|
|
|
app.on('ready', createWindow)
|
2019-08-16 09:27:23 +00:00
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
2019-09-06 03:47:39 +00:00
|
|
|
if (!isMac) app.quit()
|
2019-08-16 09:27:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (mainWindow === null) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|