lx-music-desktop/src/main/index.js

94 lines
2.3 KiB
JavaScript
Raw Normal View History

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')
require('./events')
const progressBar = require('./events/progressBar')
const trafficLight = require('./events/trafficLight')
const autoUpdate = require('./utils/autoUpdate')
2019-08-23 11:28:54 +00:00
const { isLinux, isMac } = require('../common/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
if (isDev) {
global.__static = path.join(__dirname, '../static')
winURL = `http://localhost:9080`
} else {
global.__static = path.join(__dirname, '/static')
winURL = `file://${__dirname}/index.html`
}
function createWindow() {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 590,
useContentSize: true,
width: 920,
frame: false,
2019-08-23 11:28:54 +00:00
transparent: !isLinux,
// 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)
mainWindow.on('closed', () => {
mainWindow = null
})
// mainWindow.webContents.openDevTools()
trafficLight(mainWindow)
progressBar(mainWindow)
if (!isDev) autoUpdate(mainWindow)
}
2019-08-23 11:28:54 +00:00
if (isMac) {
const template = [
{
label: app.getName(),
submenu: [{ label: '关于洛雪音乐', role: 'about' }, { type: 'separator' }, { label: '隐藏', role: 'hide' }, { label: '显示其他', role: 'hideothers' }, { label: '显示全部', role: 'unhide' }, { type: 'separator' }, { label: '退出', click: () => app.quit() }],
},
{
label: '窗口',
role: 'window',
submenu: [{ label: '最小化', role: 'minimize' }, { label: '关闭', role: 'close' }],
},
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
} else {
Menu.setApplicationMenu(null)
}
2019-08-16 09:27:23 +00:00
app.once('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})