更新electron到 10.1.0

This commit is contained in:
lyswhut
2020-08-29 14:44:37 +08:00
parent b453a8934f
commit 86478c0268
21 changed files with 228 additions and 157 deletions
+8
View File
@@ -43,6 +43,14 @@ const names = {
hide_toggle: 'hide_toggle',
get_data_path: 'get_data_path',
show_dialog: 'show_dialog',
get_setting: 'get_setting',
get_playlist: 'get_playlist',
save_playlist: 'save_playlist',
get_data: 'get_data',
set_data: 'set_data',
save_data: 'save_data',
get_hot_key: 'get_hot_key',
},
winLyric: {
close: 'close',
+1 -1
View File
@@ -188,7 +188,7 @@ exports.initSetting = () => {
// newSetting.controlBtnPosition = 'right'
electronStore_config.set('version', settingVersion)
electronStore_config.set('setting', newSetting)
return newSetting
return { version: settingVersion, setting: newSetting }
}
/**
+4 -2
View File
@@ -35,7 +35,7 @@ app.commandLine.appendSwitch('wm-window-animations-disabled')
// https://github.com/electron/electron/issues/18397
// 开发模式下为true时 多次引入native模块会导致渲染进程卡死
// https://github.com/electron/electron/issues/22791
app.allowRendererProcessReuse = !isDev
// app.allowRendererProcessReuse = !isDev
app.on('web-contents-created', (event, contents) => {
@@ -124,7 +124,9 @@ global.appHotKey = {
}
function init() {
global.appSetting = initSetting()
const info = initSetting()
global.appSetting = info.setting
global.appSettingVersion = info.version
global.appHotKey.config = initHotKey()
global.lx_event.common.initSetting()
global.lx_event.hotKey.init()
@@ -1,7 +1,9 @@
const { mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../events/_name')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc')
mainOn(ipcMainWindowNames.set_app_setting, (event, config) => {
if (!config) return
global.lx_event.common.setAppConfig(config, MAIN_WINDOW_EVENT_NAME.name)
})
mainHandle(ipcMainWindowNames.get_setting, async() => ({ setting: global.appSetting, version: global.appSettingVersion }))
@@ -1,7 +1,11 @@
const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
mainHandle(ipcMainWindowNames.clear_cache, async(event, options) => {
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
return global.modules.mainWindow.webContents.session.clearCache()
})
mainHandle(ipcMainWindowNames.get_cache_size, async(event, options) => {
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
return global.modules.mainWindow.webContents.session.getCacheSize()
})
-8
View File
@@ -1,8 +0,0 @@
const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
mainHandle(ipcMainWindowNames.clear_cache, async(event, options) => {
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
return global.modules.mainWindow.webContents.session.clearCache()
})
+12
View File
@@ -0,0 +1,12 @@
const Store = require('electron-store')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc')
const electronStore_data = new Store({
name: 'data',
})
mainHandle(ipcMainWindowNames.get_data, async(event, path) => electronStore_data.get(path))
mainOn(ipcMainWindowNames.save_data, (event, { path, data }) => electronStore_data.get(path, data))
+11 -1
View File
@@ -1,5 +1,10 @@
const { mainSend, NAMES: { mainWindow: ipcMainWindowNames }, mainOn } = require('../../common/ipc')
const Store = require('electron-store')
const { mainSend, NAMES: { mainWindow: ipcMainWindowNames }, mainOn, mainHandle } = require('../../common/ipc')
const { mainWindow: MAIN_WINDOW_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME } = require('../events/_name')
const electronStore_hotKey = new Store({
name: 'hotKey',
})
// const { registerHotkey, unRegisterHotkey } = require('../modules/hotKey/utils')
// mainHandle(ipcMainWindowNames.set_hot_key_config, async(event, { action, data }) => {
@@ -14,6 +19,11 @@ const { mainWindow: MAIN_WINDOW_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME } = requi
// }
// })
mainHandle(ipcMainWindowNames.get_hot_key, async() => ({
local: electronStore_hotKey.get('local'),
global: electronStore_hotKey.get('global'),
}))
mainOn(ipcMainWindowNames.quit, () => global.lx_event.mainWindow.quit())
mainOn(ipcMainWindowNames.min_toggle, () => global.lx_event.mainWindow.toggleMinimize())
mainOn(ipcMainWindowNames.hide_toggle, () => global.lx_event.mainWindow.toggleHide())
+4 -3
View File
@@ -7,15 +7,16 @@ require('./musicMeta')
require('./selectDir')
require('./setWindowSize')
require('./showSaveDialog')
require('./clearCache')
require('./getCacheSize')
require('./cache')
require('./setIgnoreMouseEvent')
require('./getEnvParams')
require('./setAppSetting')
require('./appSetting')
require('./setLyricInfo')
require('./hotKey')
require('./getDataPath')
require('./showDialog')
require('./playList')
require('./data')
require('./xm_verify')
+23
View File
@@ -0,0 +1,23 @@
const Store = require('electron-store')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc')
const electronStore_list = new Store({
name: 'playList',
})
mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) => {
let electronStore_list = new Store({
name: 'playList',
clearInvalidConfig: !isIgnoredError,
})
return {
defaultList: electronStore_list.get('defaultList'),
loveList: electronStore_list.get('loveList'),
userList: electronStore_list.get('userList'),
downloadList: electronStore_list.get('downloadList'),
}
})
mainOn(ipcMainWindowNames.save_playlist, (event, { type, data }) => electronStore_list.set(type, data))
+49 -17
View File
@@ -27,7 +27,7 @@ import { mapMutations, mapGetters, mapActions } from 'vuex'
import { rendererOn, rendererSend, rendererInvoke, NAMES } from '../common/ipc'
import { isLinux } from '../common/utils'
import music from './utils/music'
import { throttle, openUrl, compareVer } from './utils'
import { throttle, openUrl, compareVer, getPlayList } from './utils'
import { base as eventBaseName } from './event/names'
window.ELECTRON_DISABLE_SECURITY_WARNINGS = process.env.ELECTRON_DISABLE_SECURITY_WARNINGS
@@ -70,19 +70,34 @@ export default {
},
created() {
this.saveDefaultList = throttle(n => {
window.electronStore_list.set('defaultList', n)
rendererSend(NAMES.mainWindow.save_playlist, {
type: 'defaultList',
data: n,
})
}, 500)
this.saveLoveList = throttle(n => {
window.electronStore_list.set('loveList', n)
rendererSend(NAMES.mainWindow.save_playlist, {
type: 'loveList',
data: n,
})
}, 500)
this.saveUserList = throttle(n => {
window.electronStore_list.set('userList', n)
rendererSend(NAMES.mainWindow.save_playlist, {
type: 'userList',
data: n,
})
}, 500)
this.saveDownloadList = throttle(n => {
window.electronStore_list.set('downloadList', n)
rendererSend(NAMES.mainWindow.save_playlist, {
type: 'downloadList',
data: n,
})
}, 1000)
this.saveSearchHistoryList = throttle(n => {
window.electronStore_data.set('searchHistoryList', n)
rendererSend(NAMES.mainWindow.set_data, {
path: 'searchHistoryList',
data: n,
})
}, 500)
},
mounted() {
@@ -155,6 +170,9 @@ export default {
...mapMutations(['setNewVersion', 'setVersionModalVisible', 'setDownloadProgress', 'setSetting', 'setDesktopLyricConfig']),
...mapMutations('list', ['initList']),
...mapMutations('download', ['updateDownloadList']),
...mapMutations('search', {
setSearchHistoryList: 'setHistory',
}),
init() {
document.documentElement.style.fontSize = this.windowSizeActive.fontSize
@@ -243,19 +261,23 @@ export default {
},
initData() { // 初始化数据
this.initPlayList() // 初始化播放列表
this.initDownloadList() // 初始化下载列表
this.initLocalList() // 初始化播放列表
// this.initDownloadList() // 初始化下载列表
this.initSearchHistoryList() // 初始化搜索历史列表
},
initPlayList() {
let defaultList = window.electronStore_list.get('defaultList') || this.defaultList
let loveList = window.electronStore_list.get('loveList') || this.loveList
let userList = window.electronStore_list.get('userList') || this.userList
if (!defaultList.list) defaultList.list = []
if (!loveList.list) loveList.list = []
this.initList({ defaultList, loveList, userList })
initLocalList() {
getPlayList().then(({ defaultList, loveList, userList, downloadList }) => {
if (!defaultList) defaultList = this.defaultList
if (!loveList) loveList = this.loveList
if (!userList) userList = this.userList
if (!defaultList.list) defaultList.list = []
if (!loveList.list) loveList.list = []
this.initList({ defaultList, loveList, userList })
this.initDownloadList(downloadList) // 初始化下载列表
})
},
initDownloadList() {
let downloadList = window.electronStore_list.get('downloadList')
initDownloadList(downloadList) {
if (downloadList) {
downloadList.forEach(item => {
if (item.status == this.downloadStatus.RUN || item.status == this.downloadStatus.WAITING) {
@@ -266,6 +288,16 @@ export default {
this.updateDownloadList(downloadList)
}
},
initSearchHistoryList() {
rendererInvoke(NAMES.mainWindow.get_data, 'searchHistoryList').then(historyList => {
if (historyList == null) {
historyList = []
rendererInvoke(NAMES.mainWindow.set_data, { path: 'searchHistoryList', data: historyList })
} else {
this.setSearchHistoryList(historyList)
}
})
},
showUpdateModal() {
(this.version.newVersion && this.version.newVersion.history
? Promise.resolve(this.version.newVersion)
+10 -9
View File
@@ -1,21 +1,22 @@
import Vue from 'vue'
import keyBind from '../utils/keyBind'
import { rendererOn, rendererSend, NAMES } from '../../common/ipc'
import { rendererOn, rendererSend, NAMES, rendererInvoke } from '../../common/ipc'
import { base as baseName } from './names'
import Store from 'electron-store'
import { common as hotKeyNamesCommon } from '../../common/hotKey'
const eventHub = window.eventHub = new Vue()
const electronStore_hotKey = window.electronStore_hotKey = new Store({
name: 'hotKey',
})
window.isEditingHotKey = false
const appHotKeyConfig = window.appHotKeyConfig = {
local: electronStore_hotKey.get('local'),
global: electronStore_hotKey.get('global'),
let appHotKeyConfig = {
local: {},
global: {},
}
rendererInvoke(NAMES.mainWindow.get_hot_key).then(({ local, global }) => {
appHotKeyConfig = window.appHotKeyConfig = {
local,
global,
}
})
eventHub.$on(baseName.bindKey, () => {
keyBind.bindKey((key, type, event, keys) => {
+37 -6
View File
@@ -16,14 +16,45 @@ import store from './store'
import '../common/error'
import { getSetting } from './utils'
import languageList from '@/lang/languages.json'
import { rendererSend, NAMES } from '../common/ipc'
sync(store, router)
Vue.config.productionTip = false
new Vue({
router,
store,
i18n,
el: '#root',
render: h => h(App),
getSetting().then(({ setting, version }) => {
// Set language automatically
if (!window.i18n.availableLocales.includes(setting.langId)) {
let langId = null
let locale = window.navigator.language.toLocaleLowerCase()
if (window.i18n.availableLocales.includes(locale)) {
langId = locale
} else {
for (const lang of languageList) {
if (lang.alternate == locale) {
langId = lang.locale
break
}
}
if (langId == null) langId = 'en-us'
}
setting.langId = langId
rendererSend(NAMES.mainWindow.set_app_setting, setting)
console.log('Set lang', setting.langId)
}
window.i18n.locale = setting.langId
store.commit('setSetting', setting)
store.commit('setSettingVersion', version)
new Vue({
router,
store,
i18n,
el: '#root',
render: h => h(App),
})
})
+4 -11
View File
@@ -1,15 +1,5 @@
import Store from 'electron-store'
import music from '../../utils/music'
const electronStore_data = window.electronStore_data = new Store({
name: 'data',
})
let historyList = electronStore_data.get('searchHistoryList')
if (historyList == null) {
historyList = []
electronStore_data.set('searchHistoryList', historyList)
}
const sources = []
const sourceList = {}
const sourceMaxPage = {}
@@ -103,7 +93,7 @@ const state = {
allPage: 1,
total: 0,
sourceMaxPage,
historyList,
historyList: [],
}
// getters
@@ -211,6 +201,9 @@ const mutations = {
clearHistory(state) {
state.historyList = []
},
setHistory(state, list) {
state.historyList = list
},
}
export default {
+3 -3
View File
@@ -9,12 +9,12 @@ export default {
setSetting(state, val) {
state.setting = val
},
setAgreePact(state) {
state.setting.isAgreePact = true
},
setSettingVersion(state, val) {
state.settingVersion = val
},
setAgreePact(state) {
state.setting.isAgreePact = true
},
setLeaderboard(state, { tabId, source }) {
if (tabId != null) state.setting.leaderboard.tabId = tabId
if (source != null) state.setting.leaderboard.source = source
+2 -60
View File
@@ -1,67 +1,9 @@
// const isDev = process.env.NODE_ENV === 'development'
import Store from 'electron-store'
import { windowSizeList } from '../../common/config'
import { version } from '../../../package.json'
import { rendererSend, rendererInvoke, NAMES } from '../../common/ipc'
import languageList from '@/lang/languages.json'
import path from 'path'
import { openDirInExplorer } from '../utils'
const electronStore_config = window.electronStore_config = new Store({
name: 'config',
})
let setting = electronStore_config.get('setting')
let settingVersion = electronStore_config.get('version')
process.versions.app = version
// Set language automatically
if (!window.i18n.availableLocales.includes(setting.langId)) {
let langId = null
let locale = window.navigator.language.toLocaleLowerCase()
if (window.i18n.availableLocales.includes(locale)) {
langId = locale
} else {
for (const lang of languageList) {
if (lang.alternate == locale) {
langId = lang.locale
break
}
}
if (langId == null) langId = 'en-us'
}
setting.langId = langId
electronStore_config.set('setting', setting)
rendererSend(NAMES.mainWindow.set_app_setting, setting)
console.log('Set lang', setting.langId)
}
window.i18n.locale = setting.langId
try {
window.electronStore_list = new Store({
name: 'playList',
clearInvalidConfig: false,
})
} catch (error) {
rendererInvoke(NAMES.mainWindow.get_data_path).then(dataPath => {
let filePath = path.join(dataPath, 'playList.json.bak')
rendererInvoke(NAMES.mainWindow.show_dialog, {
type: 'error',
message: window.i18n.t('store.state.load_list_file_error_title'),
detail: window.i18n.t('store.state.load_list_file_error_detail', {
path: filePath,
detail: error.message,
}),
}).then(() => openDirInExplorer(filePath))
})
window.electronStore_list = new Store({
name: 'playList',
})
}
export default {
themes: [
@@ -144,8 +86,8 @@ export default {
downloadProgress: null,
},
userInfo: null,
setting,
settingVersion,
setting: null,
settingVersion: null,
windowSizeList,
}
+20
View File
@@ -1,4 +1,5 @@
import fs from 'fs'
import path from 'path'
import { shell, clipboard } from 'electron'
import crypto from 'crypto'
import { rendererSend, rendererInvoke, NAMES } from '../../common/ipc'
@@ -341,3 +342,22 @@ export const getProxyInfo = () => window.globalObj.proxy.enable
export const assertApiSupport = source => window.globalObj.qualityList[source] != undefined
export const getSetting = () => rendererInvoke(NAMES.mainWindow.get_setting)
export const saveSetting = () => rendererInvoke(NAMES.mainWindow.set_app_setting)
export const getPlayList = () => rendererInvoke(NAMES.mainWindow.get_playlist).catch(error => {
rendererInvoke(NAMES.mainWindow.get_data_path).then(dataPath => {
let filePath = path.join(dataPath, 'playList.json.bak')
rendererInvoke(NAMES.mainWindow.show_dialog, {
type: 'error',
message: window.i18n.t('store.state.load_list_file_error_title'),
detail: window.i18n.t('store.state.load_list_file_error_detail', {
path: filePath,
detail: error.message,
}),
}).then(() => openDirInExplorer(filePath))
})
return rendererInvoke(NAMES.mainWindow.get_playlist, true)
})