Merge branch 'master' into dev
commit
d625b0d567
|
@ -9,6 +9,8 @@ module.exports = {
|
|||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.join(__dirname, '../../src/main'),
|
||||
events: path.join(__dirname, '../../src/main/events'),
|
||||
common: path.join(__dirname, '../../src/common'),
|
||||
},
|
||||
extensions: ['*', '.js', '.json', '.node'],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lx-music-desktop",
|
||||
"version": "0.18.0",
|
||||
"version": "0.17.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -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
|
|
@ -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...')
|
||||
})
|
||||
|
|
|
@ -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+/
|
||||
|
|
|
@ -119,7 +119,9 @@ export default {
|
|||
rendererSend('max')
|
||||
},
|
||||
close() {
|
||||
rendererSend('close')
|
||||
rendererSend('close', {
|
||||
isToTray: this.setting.tray.isToTray,
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
"basic_window_size_medium": "中",
|
||||
"basic_window_size_big": "大",
|
||||
"basic_window_size_larger": "较大",
|
||||
"basic_to_tray_title": "关闭时不退出软件将其最小化到系统托盘",
|
||||
"basic_to_tray": "关闭时最小化到系统托盘",
|
||||
"basic_lang_title": "软件显示的语言",
|
||||
"basic_lang": "语言",
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
"basic_window_size_medium": "中",
|
||||
"basic_window_size_big": "大",
|
||||
"basic_window_size_larger": "較大",
|
||||
"basic_to_tray_title": "關閉時不退出軟件將其最小化到系統托盤",
|
||||
"basic_to_tray": "關閉時最小化到系統托盤",
|
||||
"basic_lang_title": "軟件顯示的語言",
|
||||
"basic_lang": "語言",
|
||||
"play": "播放設置",
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
"basic_window_size_medium": "Medium",
|
||||
"basic_window_size_big": "Large",
|
||||
"basic_window_size_larger": "Larger",
|
||||
"basic_to_tray_title": "Minimize it to the system tray without closing the software when closing",
|
||||
"basic_to_tray": "Minimize to system tray when closing",
|
||||
"basic_lang_title": "The language displayed in the software",
|
||||
"basic_lang": "Language",
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ export const objectDeepMerge = (target, source) => {
|
|||
* @param {*} setting
|
||||
*/
|
||||
export const updateSetting = (setting, version) => {
|
||||
const defaultVersion = '1.0.20'
|
||||
const defaultVersion = '1.0.22'
|
||||
if (!version) {
|
||||
if (setting) {
|
||||
version = setting.version
|
||||
|
@ -237,6 +237,10 @@ export const updateSetting = (setting, version) => {
|
|||
password: '',
|
||||
},
|
||||
},
|
||||
tray: {
|
||||
isShow: false,
|
||||
isToTray: false,
|
||||
},
|
||||
windowSizeId: 2,
|
||||
themeId: 0,
|
||||
langId: 'cns',
|
||||
|
@ -263,6 +267,7 @@ export const updateSetting = (setting, version) => {
|
|||
setting = defaultSetting
|
||||
}
|
||||
if (setting.apiSource != 'temp') setting.apiSource = 'test' // 强制设置回 test 接口源
|
||||
|
||||
return { setting, version: defaultVersion }
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@ div.scroll(:class="$style.setting")
|
|||
material-checkbox(v-for="(item, index) in windowSizeList" :id="`setting_window_size_${item.id}`" name="setting_window_size" @change="handleWindowSizeChange" :class="$style.gapLeft"
|
||||
need v-model="current_setting.windowSizeId" :value="item.id" :label="$t('view.setting.basic_window_size_' + item.name)" :key="item.id")
|
||||
|
||||
dd(:title="$t('view.setting.basic_to_tray_title')")
|
||||
h3 {{$t('view.setting.basic_to_tray')}}
|
||||
div
|
||||
material-checkbox(id="setting_to_tray" v-model="current_setting.tray.isToTray" @change="handleToTrayChange" :label="$t('view.setting.is_enable')")
|
||||
|
||||
dd(:title="$t('view.setting.basic_lang_title')")
|
||||
h3 {{$t('view.setting.basic_lang')}}
|
||||
div
|
||||
|
@ -366,7 +371,11 @@ export default {
|
|||
themeId: 0,
|
||||
sourceId: 0,
|
||||
randomAnimate: true,
|
||||
apiSource: 'messoer',
|
||||
tray: {
|
||||
isShow: false,
|
||||
isToTray: false,
|
||||
},
|
||||
apiSource: 'temp',
|
||||
},
|
||||
languageList,
|
||||
cacheSize: '0 B',
|
||||
|
@ -617,6 +626,10 @@ export default {
|
|||
handleMediaDeviceChange(audioDevice) {
|
||||
this.setMediaDeviceId(audioDevice.deviceId)
|
||||
},
|
||||
handleToTrayChange(isToTray) {
|
||||
this.current_setting.tray.isShow = isToTray
|
||||
rendererSend('changeTray', { action: isToTray ? 'create' : 'destroy' })
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue