From 08d0758616335a6df2f4d197d06133d3a2ee7666 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 12 Mar 2021 16:22:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=87=E4=BB=BD=E4=B8=8E?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=8A=9F=E8=83=BD=E5=9C=A8=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=E6=9F=90=E4=BA=9B=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E7=AB=8B=E5=8D=B3=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++-- src/main/event.js | 2 +- src/main/events/Common.js | 8 +++---- src/main/events/_name.js | 2 +- src/main/index.js | 15 ++++++++---- src/main/modules/tray.js | 14 +++++------ src/main/modules/winLyric/event.js | 5 ++-- src/main/modules/winLyric/index.js | 2 +- src/main/modules/winLyric/rendererEvent.js | 2 +- src/main/rendererEvents/appSetting.js | 8 ++++--- src/main/utils/index.js | 18 ++++++++++----- src/renderer/App.vue | 8 +++---- .../components/material/PactModal.vue | 2 +- src/renderer/utils/index.js | 2 +- src/renderer/views/Setting.vue | 23 +++++++++++++++---- 15 files changed, 71 insertions(+), 44 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 6cc4b961..aa287498 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,4 +1,4 @@ ### 修复 -- 修复歌曲ID存储变更导致酷狗图片获取失败的问题 -- 修复收藏的在线列表id迁移保存出错的问题 +- 修复备份与恢复功能在恢复数据时某些设置不立即生效的问题 + diff --git a/src/main/event.js b/src/main/event.js index b51b5163..155e3f35 100644 --- a/src/main/event.js +++ b/src/main/event.js @@ -2,7 +2,7 @@ const { common: COMMON_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = requir const { mainSend, NAMES: { mainWindow: ipcMainWindowNames } } = require('./../common/ipc') const { getAppHotKeyConfig } = require('./utils') -global.lx_event.common.on(COMMON_EVENT_NAME.config, name => { +global.lx_event.common.on(COMMON_EVENT_NAME.configStatus, name => { if (MAIN_WINDOW_EVENT_NAME.name === name) return if (global.modules.mainWindow) mainSend(global.modules.mainWindow, ipcMainWindowNames.set_config, global.appSetting) }) diff --git a/src/main/events/Common.js b/src/main/events/Common.js index bf1e428c..bb9dea0d 100644 --- a/src/main/events/Common.js +++ b/src/main/events/Common.js @@ -1,16 +1,14 @@ const { EventEmitter } = require('events') const { common: COMMON_EVENT_NAME } = require('./_name') -const { updateSetting } = require('../utils') class Common extends EventEmitter { initSetting() { this.emit(COMMON_EVENT_NAME.initConfig) - this.emit(COMMON_EVENT_NAME.config, null) + this.configStatus(null) } - setAppConfig(config, name) { - if (config) updateSetting(config) - this.emit(COMMON_EVENT_NAME.config, name) + configStatus(name) { + this.emit(COMMON_EVENT_NAME.configStatus, name) } } diff --git a/src/main/events/_name.js b/src/main/events/_name.js index 251ba7bb..d15a2c09 100644 --- a/src/main/events/_name.js +++ b/src/main/events/_name.js @@ -1,6 +1,6 @@ exports.common = { initConfig: 'initConfig', - config: 'config', + configStatus: 'config', } exports.mainWindow = { diff --git a/src/main/index.js b/src/main/index.js index e4544b34..2eb1bfae 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -34,8 +34,8 @@ app.commandLine.appendSwitch('wm-window-animations-disabled') const { navigationUrlWhiteList } = require('../common/config') -const { getWindowSizeInfo } = require('./utils') -const { isMac, isLinux, initSetting, initHotKey } = require('../common/utils') +const { getWindowSizeInfo, initSetting, updateSetting } = require('./utils') +const { isMac, isLinux, initHotKey } = require('../common/utils') // https://github.com/electron/electron/issues/18397 @@ -130,11 +130,16 @@ global.appHotKey = { state: null, } +global.lx_core = { + setAppConfig(setting, name) { + updateSetting(setting) + global.lx_event.common.configStatus(name) + }, +} + function init() { console.log('init') - const info = initSetting() - global.appSetting = info.setting - global.appSettingVersion = info.version + initSetting() global.appHotKey.config = initHotKey() global.lx_event.common.initSetting() global.lx_event.hotKey.init() diff --git a/src/main/modules/tray.js b/src/main/modules/tray.js index 58579990..b2b990ad 100644 --- a/src/main/modules/tray.js +++ b/src/main/modules/tray.js @@ -16,7 +16,7 @@ const themeList = [ isNative: false, }, ] -global.lx_event.common.on(COMMON_EVENT_NAME.config, sourceName => { +global.lx_event.common.on(COMMON_EVENT_NAME.configStatus, sourceName => { if (sourceName === TRAY_EVENT_NAME.name) return if (themeId !== global.appSetting.tray.themeId) { themeId = global.appSetting.tray.themeId @@ -89,34 +89,34 @@ const createMenu = tray => { menu.push(global.appSetting.desktopLyric.enable ? { label: '关闭桌面歌词', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { enable: false } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { enable: false } }, TRAY_EVENT_NAME.name) }, } : { label: '开启桌面歌词', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { enable: true } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { enable: true } }, TRAY_EVENT_NAME.name) }, }) menu.push(global.appSetting.desktopLyric.isLock ? { label: '解锁桌面歌词', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { isLock: false } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { isLock: false } }, TRAY_EVENT_NAME.name) }, } : { label: '锁定桌面歌词', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { isLock: true } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { isLock: true } }, TRAY_EVENT_NAME.name) }, }) menu.push(global.appSetting.desktopLyric.isAlwaysOnTop ? { label: '取消置顶', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { isAlwaysOnTop: false } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { isAlwaysOnTop: false } }, TRAY_EVENT_NAME.name) }, } : { label: '置顶歌词', click() { - global.lx_event.common.setAppConfig({ desktopLyric: { isAlwaysOnTop: true } }, TRAY_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: { isAlwaysOnTop: true } }, TRAY_EVENT_NAME.name) }, }) menu.push({ diff --git a/src/main/modules/winLyric/event.js b/src/main/modules/winLyric/event.js index 658725dd..99fabf5b 100644 --- a/src/main/modules/winLyric/event.js +++ b/src/main/modules/winLyric/event.js @@ -2,6 +2,7 @@ const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, hotKey: HOT_K const { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc') const { desktop_lyric } = require('../../../common/hotKey') const { getLyricWindowBounds } = require('./utils') +const { updateSetting } = require('../../utils') let isLock = null let isEnable = null @@ -49,7 +50,7 @@ const setLrcConfig = () => { } } } -global.lx_event.common.on(COMMON_EVENT_NAME.config, name => { +global.lx_event.common.on(COMMON_EVENT_NAME.configStatus, name => { if (WIN_LYRIC_EVENT_NAME.name === name) return setLrcConfig() }) @@ -77,5 +78,5 @@ global.lx_event.hotKey.on(HOT_KEY_EVENT_NAME.keyDown, ({ type, key }) => { } desktopLyricSetting[settingKey] = !desktopLyricSetting[settingKey] - global.lx_event.common.setAppConfig({ desktopLyric: desktopLyricSetting }, null) + updateSetting({ desktopLyric: desktopLyricSetting }, null) }) diff --git a/src/main/modules/winLyric/index.js b/src/main/modules/winLyric/index.js index 498c24c8..c7a194bf 100644 --- a/src/main/modules/winLyric/index.js +++ b/src/main/modules/winLyric/index.js @@ -21,7 +21,7 @@ const setLyricsConfig = debounce(config => { // if (y != null) bounds.y = y // if (width != null) bounds.width = width // if (height != null) bounds.height = height - global.lx_event.common.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name) }, 500) const winEvent = lyricWindow => { diff --git a/src/main/modules/winLyric/rendererEvent.js b/src/main/modules/winLyric/rendererEvent.js index 39e60d0d..d1c3745a 100644 --- a/src/main/modules/winLyric/rendererEvent.js +++ b/src/main/modules/winLyric/rendererEvent.js @@ -20,7 +20,7 @@ mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => { }) mainOn(ipcWinLyricNames.set_lyric_config, (event, config) => { - global.lx_event.common.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name) + global.lx_core.setAppConfig({ desktopLyric: config }, WIN_LYRIC_EVENT_NAME.name) }) mainHandle(ipcWinLyricNames.get_lyric_config, async() => { diff --git a/src/main/rendererEvents/appSetting.js b/src/main/rendererEvents/appSetting.js index 415da098..2198a0c7 100644 --- a/src/main/rendererEvents/appSetting.js +++ b/src/main/rendererEvents/appSetting.js @@ -1,9 +1,11 @@ const { mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../events/_name') -const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc') +const { NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc') -mainOn(ipcMainWindowNames.set_app_setting, (event, config) => { + +mainHandle(ipcMainWindowNames.set_app_setting, (event, config) => { if (!config) return - global.lx_event.common.setAppConfig(config, MAIN_WINDOW_EVENT_NAME.name) + global.lx_core.setAppConfig(config, MAIN_WINDOW_EVENT_NAME.name) + return global.appSetting }) mainHandle(ipcMainWindowNames.get_setting, async() => ({ setting: global.appSetting, version: global.appSettingVersion })) diff --git a/src/main/utils/index.js b/src/main/utils/index.js index eec8533c..f80a671d 100644 --- a/src/main/utils/index.js +++ b/src/main/utils/index.js @@ -1,6 +1,6 @@ const Store = require('electron-store') const { windowSizeList } = require('../../common/config') -const { objectDeepMerge, throttle } = require('../../common/utils') +const { objectDeepMerge, throttle, initSetting } = require('../../common/utils') exports.getWindowSizeInfo = ({ windowSizeId = 1 } = {}) => { return windowSizeList.find(i => i.id === windowSizeId) || windowSizeList[0] @@ -32,10 +32,16 @@ exports.saveAppHotKeyConfig = config => { saveHotKeyConfig(config) } -const saveSetting = throttle(n => { - electronStore_config.set('setting', n) -}) -exports.updateSetting = settings => { +// const saveSetting = throttle(n => { +// electronStore_config.set('setting', n) +// }) +exports.updateSetting = (settings) => { objectDeepMerge(global.appSetting, settings) - saveSetting(global.appSetting) + electronStore_config.set('setting', global.appSetting) + exports.initSetting() +} +exports.initSetting = () => { + const info = initSetting() + global.appSetting = info.setting + global.appSettingVersion = info.version } diff --git a/src/renderer/App.vue b/src/renderer/App.vue index e860dd78..635d8bd3 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -25,7 +25,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, getPlayList, parseUrlParams } from './utils' +import { throttle, openUrl, compareVer, getPlayList, parseUrlParams, saveSetting } from './utils' import { base as eventBaseName } from './event/names' import apiSourceInfo from './utils/music/api-source-info' @@ -113,7 +113,7 @@ export default { watch: { setting: { handler(n, o) { - rendererSend(NAMES.mainWindow.set_app_setting, n) + saveSetting(n) }, deep: true, }, @@ -246,7 +246,7 @@ export default { }) rendererOn(NAMES.mainWindow.set_config, (event, config) => { - // console.log(config) + console.log(config) // this.setDesktopLyricConfig(config) // console.log('set_config', JSON.stringify(this.setting) === JSON.stringify(config)) this.setSetting(Object.assign({}, this.setting, config)) @@ -355,7 +355,7 @@ export default { if (info.listId) { const list = window.allList[info.listId] // console.log(list) - if (!list) return + if (!list || !list.list[info.index]) return info.list = list.list } diff --git a/src/renderer/components/material/PactModal.vue b/src/renderer/components/material/PactModal.vue index ff6cee06..53f24611 100644 --- a/src/renderer/components/material/PactModal.vue +++ b/src/renderer/components/material/PactModal.vue @@ -62,7 +62,7 @@ import { openUrl } from '../../utils' export default { data() { return { - time: 20, + time: 5, globalObj: { isShowPact: false, }, diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index 772849d3..2c9f2759 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -379,7 +379,7 @@ 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 saveSetting = setting => rendererInvoke(NAMES.mainWindow.set_app_setting, setting) export const getPlayList = () => rendererInvoke(NAMES.mainWindow.get_playlist).catch(error => { rendererInvoke(NAMES.mainWindow.get_data_path).then(dataPath => { diff --git a/src/renderer/views/Setting.vue b/src/renderer/views/Setting.vue index 555929d1..371146af 100644 --- a/src/renderer/views/Setting.vue +++ b/src/renderer/views/Setting.vue @@ -279,6 +279,8 @@ import { clearCache, sizeFormate, setWindowSize, + getSetting, + saveSetting, } from '../utils' import { rendererSend, rendererInvoke, NAMES } from '@common/ipc' import { mergeSetting, isMac } from '../../common/utils' @@ -289,6 +291,7 @@ import { base as eventBaseName } from '../event/names' import * as hotKeys from '../../common/hotKey' import { mainWindow as eventsNameMainWindow, winLyric as eventsNameWinLyric } from '../../main/events/_name' import { gzip, gunzip } from 'zlib' +import music from '../utils/music' let hotKeyTargetInput let newHotKey @@ -748,6 +751,8 @@ export default { if (list.location == null) list.location = 0 this.setList(list) } + + await this.refreshSetting(this.setting, this.settingVersion) }, exportPlayList(path) { const data = JSON.parse(JSON.stringify({ @@ -773,9 +778,6 @@ export default { return } if (allData.type !== 'allData') return - const { version: settingVersion, setting } = mergeSetting(allData.setting) - setting.isAgreePact = false - this.refreshSetting(setting, settingVersion) // 兼容0.6.2及以前版本的列表数据 if (allData.defaultList) return this.setList({ id: 'default', list: allData.defaultList.list, name: '试听列表', location: 0 }) @@ -784,6 +786,11 @@ export default { if (list.location == null) list.location = 0 this.setList(list) } + + const { version: settingVersion, setting } = mergeSetting(allData.setting) + setting.isAgreePact = false + + await this.refreshSetting(setting, settingVersion) }, async exportAllData(path) { let allData = JSON.parse(JSON.stringify({ @@ -906,10 +913,18 @@ export default { let info = index == null ? this.windowSizeList[2] : this.windowSizeList[index] setWindowSize(info.width, info.height) }, - refreshSetting(setting, version) { + async refreshSetting(newSetting, newVersion) { + await saveSetting(newSetting) + const { setting, version } = await getSetting() this.setSetting(setting) this.setSettingVersion(version) if (setting.windowSizeId != null) this.handleWindowSizeChange(null, setting.windowSizeId) + window.globalObj.apiSource = setting.apiSource + if (/^user_api/.test(setting.apiSource)) { + rendererInvoke(NAMES.mainWindow.set_user_api, setting.apiSource) + } else { + window.globalObj.qualityList = music.supportQuality[setting.apiSource] + } for (let key of Object.keys(setting.network.proxy)) { window.globalObj.proxy[key] = setting.network.proxy[key] }