Merge branch 'master' into dev
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
exports.tray = {
|
||||
create: 'create',
|
||||
destroy: 'destroy',
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
global.lx_event = {}
|
||||
|
||||
require('./request')
|
||||
// require('./appName')
|
||||
require('./progressBar')
|
||||
require('./trafficLight')
|
||||
require('./musicMeta')
|
||||
require('./selectDir')
|
||||
require('./setWindowSize')
|
||||
require('./showSaveDialog')
|
||||
require('./clearCache')
|
||||
require('./getCacheSize')
|
||||
require('./setIgnoreMouseEvent')
|
||||
require('./getEnvParams')
|
||||
const Tray = require('./tray')
|
||||
|
||||
if (!global.lx_event.setting) global.lx_event.tray = new Tray()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const { EventEmitter } = require('events')
|
||||
const { tray: TRAY_EVENT_NAME } = require('./_name')
|
||||
|
||||
class Tray extends EventEmitter {
|
||||
create() {
|
||||
this.emit(TRAY_EVENT_NAME.create)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.emit(TRAY_EVENT_NAME.destroy)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Tray
|
||||
+25
-59
@@ -1,4 +1,4 @@
|
||||
const { app, BrowserWindow, Menu, shell } = require('electron')
|
||||
const { app, BrowserWindow, shell } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
// 单例应用程序
|
||||
@@ -15,7 +15,7 @@ app.on('second-instance', (event, argv, cwd) => {
|
||||
}
|
||||
})
|
||||
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
const isDev = global.isDev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
app.on('web-contents-created', (event, contents) => {
|
||||
contents.on('will-navigate', (event, navigationUrl) => {
|
||||
@@ -34,23 +34,23 @@ app.on('web-contents-created', (event, contents) => {
|
||||
// https://github.com/electron/electron/issues/18397
|
||||
app.allowRendererProcessReuse = !isDev
|
||||
|
||||
const { getWindowSizeInfo, parseEnv } = require('./utils')
|
||||
const { getAppSetting, parseEnv, getWindowSizeInfo } = require('./utils')
|
||||
|
||||
global.envParams = parseEnv()
|
||||
|
||||
require('../common/error')
|
||||
require('./events')
|
||||
const winEvent = require('./events/winEvent')
|
||||
require('./rendererEvents')
|
||||
const winEvent = require('./rendererEvents/winEvent')
|
||||
const autoUpdate = require('./utils/autoUpdate')
|
||||
const { isLinux, isMac } = require('../common/utils')
|
||||
|
||||
const { isMac, isLinux } = require('../common/utils')
|
||||
|
||||
let mainWindow
|
||||
let winURL
|
||||
let isFirstCheckedUpdate = true
|
||||
|
||||
if (isDev) {
|
||||
global.__static = path.join(__dirname, '../static')
|
||||
// eslint-disable-next-line no-undef
|
||||
global.__static = __static
|
||||
winURL = 'http://localhost:9080'
|
||||
} else {
|
||||
global.__static = path.join(__dirname, '/static')
|
||||
@@ -58,7 +58,7 @@ if (isDev) {
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
let windowSizeInfo = getWindowSizeInfo()
|
||||
const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
@@ -86,61 +86,27 @@ function createWindow() {
|
||||
winEvent(mainWindow)
|
||||
// mainWindow.webContents.openDevTools()
|
||||
|
||||
if (!isDev) {
|
||||
autoUpdate(isFirstCheckedUpdate)
|
||||
isFirstCheckedUpdate = false
|
||||
}
|
||||
if (!isDev) autoUpdate()
|
||||
}
|
||||
|
||||
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: '退出', accelerator: 'Command+Q', click: () => app.quit() },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '窗口',
|
||||
role: 'window',
|
||||
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' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
|
||||
} else {
|
||||
Menu.setApplicationMenu(null)
|
||||
function init() {
|
||||
global.appSetting = getAppSetting()
|
||||
createWindow()
|
||||
global.lx_event.tray.create()
|
||||
}
|
||||
|
||||
app.on('ready', createWindow)
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (!isMac) app.quit()
|
||||
})
|
||||
app.on('ready', init)
|
||||
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) {
|
||||
createWindow()
|
||||
if (mainWindow === null) return init()
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (isMac) {
|
||||
global.lx_event.tray.destroy()
|
||||
} else {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
require('./modules')
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
const { app, Menu } = require('electron')
|
||||
const { isMac } = require('../../common/utils')
|
||||
|
||||
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: '退出', accelerator: 'Command+Q', click: () => app.quit() },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '窗口',
|
||||
role: 'window',
|
||||
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' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
|
||||
} else {
|
||||
Menu.setApplicationMenu(null)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
require('./appMenu')
|
||||
require('./tray')
|
||||
@@ -0,0 +1,42 @@
|
||||
const { Tray, Menu } = require('electron')
|
||||
const { isMac, isWin } = require('../../common/utils')
|
||||
const { tray: TRAY_EVENT_NAME } = require('../events/_name')
|
||||
const path = require('path')
|
||||
global.lx_event.tray.on(TRAY_EVENT_NAME.create, () => {
|
||||
createTray()
|
||||
})
|
||||
global.lx_event.tray.on(TRAY_EVENT_NAME.destroy, () => {
|
||||
destroyTray()
|
||||
})
|
||||
|
||||
let tray
|
||||
function createTray() {
|
||||
if (tray && !tray.isDestroyed() && global.appSetting.tray && global.appSetting.tray.isShow) return
|
||||
|
||||
const iconPath = path.join(global.__static, 'images/tray', isWin ? '256x256.ico' : isMac ? '512x512.icns' : '512x512.png')
|
||||
|
||||
// 托盘
|
||||
tray = new Tray(iconPath)
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '退出',
|
||||
role: 'quit',
|
||||
},
|
||||
])
|
||||
tray.setToolTip('洛雪音乐助手')
|
||||
tray.setContextMenu(contextMenu)
|
||||
tray.on('click', () => {
|
||||
const mainWindow = global.mainWindow
|
||||
if (!mainWindow) return
|
||||
mainWindow.isVisible()
|
||||
? mainWindow.focus()
|
||||
: mainWindow.show()
|
||||
})
|
||||
}
|
||||
|
||||
function destroyTray() {
|
||||
if (!tray) return
|
||||
tray.destroy()
|
||||
tray = null
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
require('./request')
|
||||
// require('./appName')
|
||||
require('./progressBar')
|
||||
require('./trafficLight')
|
||||
require('./musicMeta')
|
||||
require('./selectDir')
|
||||
require('./setWindowSize')
|
||||
require('./showSaveDialog')
|
||||
require('./clearCache')
|
||||
require('./getCacheSize')
|
||||
require('./setIgnoreMouseEvent')
|
||||
require('./getEnvParams')
|
||||
require('./tray')
|
||||
@@ -1,7 +1,6 @@
|
||||
// const { app } = require('electron')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
|
||||
mainOn('min', event => {
|
||||
if (global.mainWindow) {
|
||||
global.mainWindow.minimize()
|
||||
@@ -12,10 +11,11 @@ mainOn('max', event => {
|
||||
global.mainWindow.maximize()
|
||||
}
|
||||
})
|
||||
mainOn('close', event => {
|
||||
mainOn('close', (event, params) => {
|
||||
if (global.mainWindow) {
|
||||
// console.log('close', params)
|
||||
if (params && params.isToTray) return global.mainWindow.hide()
|
||||
// global.mainWindowdow.destroy()
|
||||
// console.log('close')
|
||||
// app.quit()
|
||||
global.mainWindow.close()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// const { app } = require('electron')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
mainOn('changeTray', (event, params) => {
|
||||
switch (params.action) {
|
||||
case 'create':
|
||||
global.lx_event.tray.create()
|
||||
break
|
||||
case 'destroy':
|
||||
global.lx_event.tray.destroy()
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
@@ -5,6 +5,9 @@ const { mainOn } = require('../../common/ipc')
|
||||
autoUpdater.logger = log
|
||||
// autoUpdater.autoDownload = false
|
||||
autoUpdater.logger.transports.file.level = 'info'
|
||||
|
||||
let isFirstCheckedUpdate = true
|
||||
|
||||
log.info('App starting...')
|
||||
|
||||
|
||||
@@ -67,7 +70,7 @@ const handleSendEvent = action => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = isFirstCheckedUpdate => {
|
||||
module.exports = () => {
|
||||
if (!isFirstCheckedUpdate) {
|
||||
if (waitEvent.length) {
|
||||
waitEvent.forEach((event, index) => {
|
||||
@@ -79,6 +82,8 @@ module.exports = isFirstCheckedUpdate => {
|
||||
}
|
||||
return
|
||||
}
|
||||
isFirstCheckedUpdate = false
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
sendStatusToWindow('Checking for update...')
|
||||
})
|
||||
|
||||
+13
-3
@@ -1,12 +1,22 @@
|
||||
const Store = require('electron-store')
|
||||
const { windowSizeList } = require('../../common/config')
|
||||
|
||||
exports.getWindowSizeInfo = () => {
|
||||
let electronStore = new Store()
|
||||
const { windowSizeId = 1 } = electronStore.get('setting') || {}
|
||||
exports.getWindowSizeInfo = ({ windowSizeId = 1 } = {}) => {
|
||||
return windowSizeList.find(i => i.id === windowSizeId) || windowSizeList[0]
|
||||
}
|
||||
|
||||
exports.getAppSetting = () => {
|
||||
let electronStore = new Store()
|
||||
const defaultSetting = {
|
||||
windowSizeId: 1,
|
||||
tray: {
|
||||
isShow: false,
|
||||
isToTray: false,
|
||||
},
|
||||
}
|
||||
return Object.assign(defaultSetting, electronStore.get('setting') || {})
|
||||
}
|
||||
|
||||
exports.parseEnv = () => {
|
||||
const params = {}
|
||||
const rx = /^-\w+/
|
||||
|
||||
Reference in New Issue
Block a user