新增桌面歌词

This commit is contained in:
lyswhut
2020-06-11 21:16:59 +08:00
parent 25fc0226aa
commit 2a81d41c2c
107 changed files with 6935 additions and 1543 deletions
+12 -10
View File
@@ -1,6 +1,6 @@
const { log } = require('../../common/utils')
const { autoUpdater } = require('electron-updater')
const { mainOn } = require('../../common/ipc')
const { mainOn, mainSend, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
autoUpdater.logger = log
// autoUpdater.autoDownload = false
@@ -61,9 +61,10 @@ function sendStatusToWindow(text) {
let waitEvent = []
const handleSendEvent = action => {
if (global.mainWindow) {
if (global.modals.mainWindow) {
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
global.mainWindow.webContents.send(action.type, action.info)
if (!global.modals.mainWindow) return
mainSend(global.modals.mainWindow, action.type, action.info)
}, 2000)
} else {
waitEvent.push(action)
@@ -75,7 +76,8 @@ module.exports = () => {
if (waitEvent.length) {
waitEvent.forEach((event, index) => {
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
global.mainWindow.webContents.send(event.type, event.info)
if (!global.modals.mainWindow) return
mainSend(global.modals.mainWindow, event.type, event.info)
}, 2000 * (index + 1))
})
waitEvent = []
@@ -89,28 +91,28 @@ module.exports = () => {
})
autoUpdater.on('update-available', info => {
sendStatusToWindow('Update available.')
handleSendEvent({ type: 'update-available', info })
handleSendEvent({ type: ipcMainWindowNames.update_available, info })
})
autoUpdater.on('update-not-available', info => {
sendStatusToWindow('Update not available.')
handleSendEvent({ type: 'update-not-available', info })
handleSendEvent({ type: ipcMainWindowNames.update_not_available, info })
})
autoUpdater.on('error', err => {
sendStatusToWindow('Error in auto-updater.')
handleSendEvent({ type: 'update-error', info: err.message })
handleSendEvent({ type: ipcMainWindowNames.update_error, info: err.message })
})
autoUpdater.on('download-progress', progressObj => {
let log_message = 'Download speed: ' + progressObj.bytesPerSecond
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'
log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')'
sendStatusToWindow(log_message)
handleSendEvent({ type: 'update-progress', info: progressObj })
handleSendEvent({ type: ipcMainWindowNames.update_progress, info: progressObj })
})
autoUpdater.on('update-downloaded', info => {
sendStatusToWindow('Update downloaded.')
handleSendEvent({ type: 'update-downloaded', info })
handleSendEvent({ type: ipcMainWindowNames.update_downloaded, info })
})
mainOn('quit-update', () => {
mainOn(ipcMainWindowNames.quit_update, () => {
global.isQuitting = true
setTimeout(() => {
+8 -24
View File
@@ -1,35 +1,19 @@
const Store = require('electron-store')
const { windowSizeList } = require('../../common/config')
const { objectDeepMerge } = require('../../common/utils')
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') || {})
const electronStore_config = new Store({
name: 'config',
})
return electronStore_config.get('setting')
}
exports.parseEnv = () => {
const params = {}
const rx = /^-\w+/
for (let param of process.argv) {
if (!rx.test(param)) continue
param = param.substring(1)
let index = param.indexOf('=')
if (index < 0) {
params[param] = true
} else {
params[param.substring(0, index)] = param.substring(index + 1)
}
}
return params
}
exports.updateSetting = settings => {
objectDeepMerge(global.appSetting, settings)
}