From c15895ab455e2c90684ca138d0c87a127f5a0be7 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 23 Aug 2020 12:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E4=B8=8D=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E5=B0=86=E6=AD=8C=E8=AF=8D=E7=AA=97=E5=8F=A3=E6=8B=96?= =?UTF-8?q?=E5=87=BA=E4=B8=BB=E5=B1=8F=E5=B9=95=E4=B9=8B=E5=A4=96=20?= =?UTF-8?q?=E7=9A=84=E8=AE=BE=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/common/defaultSetting.js | 3 +- src/main/modules/winLyric/event.js | 15 +++++- src/main/modules/winLyric/index.js | 8 +++- src/main/modules/winLyric/rendererEvent.js | 50 ++----------------- src/main/modules/winLyric/utils.js | 56 ++++++++++++++++++++++ src/renderer/lang/en-us/view/setting.json | 1 + src/renderer/lang/zh-cn/view/setting.json | 1 + src/renderer/lang/zh-tw/view/setting.json | 1 + src/renderer/views/Setting.vue | 2 + 10 files changed, 87 insertions(+), 51 deletions(-) create mode 100644 src/main/modules/winLyric/utils.js diff --git a/publish/changeLog.md b/publish/changeLog.md index d55247ca..61047eb8 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,6 +1,7 @@ ### 新增 - 在歌单详情界面新增播放当前歌单按钮、收藏歌单按钮 +- 新增`不允许将歌词窗口拖出主屏幕之外`的设置项,默认开启,在连接多个屏幕时想要拖动到其他屏幕时可关闭此设置 ### 修复 diff --git a/src/common/defaultSetting.js b/src/common/defaultSetting.js index 2203e8ba..07909bad 100644 --- a/src/common/defaultSetting.js +++ b/src/common/defaultSetting.js @@ -3,7 +3,7 @@ const os = require('os') const { isMac } = require('./utils') const defaultSetting = { - version: '1.0.34', + version: '1.0.35', player: { togglePlayMethod: 'listLoop', highQuality: false, @@ -22,6 +22,7 @@ const defaultSetting = { x: null, y: null, theme: 0, + isLockScreen: true, style: { fontSize: 120, opacity: 95, diff --git a/src/main/modules/winLyric/event.js b/src/main/modules/winLyric/event.js index d9f19b7b..0c5a7935 100644 --- a/src/main/modules/winLyric/event.js +++ b/src/main/modules/winLyric/event.js @@ -1,10 +1,12 @@ const { common: COMMON_EVENT_NAME, winLyric: WIN_LYRIC_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME, mainWindow: MAIN_WINDOW_EVENT_NAME } = require('../../events/_name') const { mainSend, NAMES: { winLyric: ipcWinLyricNames } } = require('../../../common/ipc') const { desktop_lyric } = require('../../../common/hotKey') +const { setLyricWindow } = require('./utils') let isLock = null let isEnable = null let isAlwaysOnTop = null +let isLockScreen = null const setLrcConfig = () => { let desktopLyric = global.appSetting.desktopLyric if (global.modules.lyricWindow) { @@ -33,10 +35,21 @@ const setLrcConfig = () => { global.lx_event.winLyric.close() } } + if (isLockScreen != desktopLyric.isLockScreen) { + isLockScreen = desktopLyric.isLockScreen + if (desktopLyric.isLockScreen) { + setLyricWindow({ + x: desktopLyric.x, + y: desktopLyric.y, + w: desktopLyric.width, + h: desktopLyric.height, + }) + } + } } global.lx_event.common.on(COMMON_EVENT_NAME.config, name => { if (WIN_LYRIC_EVENT_NAME.name === name) return - setLrcConfig(false) + setLrcConfig() }) global.lx_event.mainWindow.on(MAIN_WINDOW_EVENT_NAME.setLyricInfo, info => { diff --git a/src/main/modules/winLyric/index.js b/src/main/modules/winLyric/index.js index 77097586..3b2e150d 100644 --- a/src/main/modules/winLyric/index.js +++ b/src/main/modules/winLyric/index.js @@ -80,14 +80,18 @@ const createWindow = () => { x = screenWidth - width - offset y = screenHeight - height - offset } + if (global.appSetting.desktopLyric.isLockScreen) { + x = Math.max(-offset, screenWidth < (width + x) ? screenWidth - width : x) + y = Math.max(-offset, screenHeight < (height + y) ? screenHeight - height : y) + } /** * Initial window options */ global.modules.lyricWindow = new BrowserWindow({ height: Math.max(height > screenHeight ? screenHeight : height, 80), width: Math.max(width > screenWidth ? screenWidth : width, 380), - x: Math.max(-offset, screenWidth < (width + x) ? screenWidth - width : x), - y: Math.max(-offset, screenHeight < (height + y) ? screenHeight - height : y), + x, + y, minWidth: 380, minHeight: 80, useContentSize: true, diff --git a/src/main/modules/winLyric/rendererEvent.js b/src/main/modules/winLyric/rendererEvent.js index c0ebc126..86dc448d 100644 --- a/src/main/modules/winLyric/rendererEvent.js +++ b/src/main/modules/winLyric/rendererEvent.js @@ -8,6 +8,7 @@ const { }, } = require('../../../common/ipc') const { winLyric: WIN_LYRIC_EVENT_NAME } = require('../../events/_name') +const { setLyricWindow } = require('./utils') mainOn(ipcWinLyricNames.get_lyric_info, (event, action) => { if (!global.modules.mainWindow) return @@ -26,51 +27,6 @@ mainHandle(ipcWinLyricNames.get_lyric_config, async() => { return { config: global.appSetting.desktopLyric, languageId: global.appSetting.langId } }) -let bounds -let winX -let winY -let wasW -let wasY -let offset = 8 -mainOn(ipcWinLyricNames.set_win_bounds, (event, { x = 0, y = 0, w = 0, h = 0 }) => { - if (!global.modules.lyricWindow) return - bounds = global.modules.lyricWindow.getBounds() - wasW = global.envParams.workAreaSize.width - wasY = global.envParams.workAreaSize.height + offset - - bounds.width = w - bounds.height = h - if (bounds.width > wasW - offset) { - bounds.width = wasW - offset - } else if (bounds.width < 380) { - bounds.width = 380 - } - if (bounds.height > wasY) { - bounds.height = wasY + offset - } else if (bounds.height < 80) { - bounds.height = 80 - } - - - if (x != 0) { - winX = bounds.x + x - if (winX > wasW - bounds.width + offset) { - winX = wasW - bounds.width + offset - } else if (winX < -offset) { - winX = -offset - } - bounds.x = winX - } - if (y != 0) { - winY = bounds.y + y - if (winY > wasY - bounds.height) { - winY = wasY - bounds.height - } else if (winY < -offset) { - winY = -offset - } - bounds.y = winY - } - - // console.log(bounds, x, y, w, h) - global.modules.lyricWindow.setBounds(bounds) +mainOn(ipcWinLyricNames.set_win_bounds, (event, options) => { + setLyricWindow(options) }) diff --git a/src/main/modules/winLyric/utils.js b/src/main/modules/winLyric/utils.js new file mode 100644 index 00000000..48c891eb --- /dev/null +++ b/src/main/modules/winLyric/utils.js @@ -0,0 +1,56 @@ +// 设置窗口位置、大小 +let bounds +let winX +let winY +let wasW +let wasY +let offset = 8 +exports.setLyricWindow = ({ x = 0, y = 0, w = 0, h = 0 }) => { + if (!global.modules.lyricWindow) return + bounds = global.modules.lyricWindow.getBounds() + wasW = global.envParams.workAreaSize.width + wasY = global.envParams.workAreaSize.height + offset + + bounds.width = w + bounds.height = h + if (bounds.width > wasW - offset) { + bounds.width = wasW - offset + } else if (bounds.width < 380) { + bounds.width = 380 + } + if (bounds.height > wasY) { + bounds.height = wasY + offset + } else if (bounds.height < 80) { + bounds.height = 80 + } + + if (global.appSetting.desktopLyric.isLockScreen) { + if (x != 0) { + winX = bounds.x + x + if (winX > wasW - bounds.width + offset) { + winX = wasW - bounds.width + offset + } else if (winX < -offset) { + winX = -offset + } + bounds.x = winX + } + if (y != 0) { + winY = bounds.y + y + if (winY > wasY - bounds.height) { + winY = wasY - bounds.height + } else if (winY < -offset) { + winY = -offset + } + bounds.y = winY + } + } else { + if (x != 0) { + bounds.x = bounds.x + x + } + if (y != 0) { + bounds.y = bounds.y + y + } + } + // console.log(bounds, x, y, w, h) + global.modules.lyricWindow.setBounds(bounds) +} diff --git a/src/renderer/lang/en-us/view/setting.json b/src/renderer/lang/en-us/view/setting.json index 116b46c4..ac1f2b7c 100644 --- a/src/renderer/lang/en-us/view/setting.json +++ b/src/renderer/lang/en-us/view/setting.json @@ -48,6 +48,7 @@ "desktop_lyric_enable": "Display lyrics", "desktop_lyric_lock": "Lock lyrics", "desktop_lyric_always_on_top": "Make the lyrics always above other windows", + "desktop_lyric_lock_screen": "It is not allowed to drag the lyrics window out of the main screen", "search": "Search", "search_hot_title": "Select whether to show popular searches", diff --git a/src/renderer/lang/zh-cn/view/setting.json b/src/renderer/lang/zh-cn/view/setting.json index 3983fcb3..844c3f6b 100644 --- a/src/renderer/lang/zh-cn/view/setting.json +++ b/src/renderer/lang/zh-cn/view/setting.json @@ -48,6 +48,7 @@ "desktop_lyric_enable": "显示歌词", "desktop_lyric_lock": "锁定歌词", "desktop_lyric_always_on_top": "使歌词总是在其他窗口之上", + "desktop_lyric_lock_screen": "不允许歌词窗口拖出主屏幕之外", "search": "搜索设置", "search_hot_title": "是否显示热门搜索", diff --git a/src/renderer/lang/zh-tw/view/setting.json b/src/renderer/lang/zh-tw/view/setting.json index 0f7ff439..f46798d9 100644 --- a/src/renderer/lang/zh-tw/view/setting.json +++ b/src/renderer/lang/zh-tw/view/setting.json @@ -46,6 +46,7 @@ "desktop_lyric_enable": "顯示歌詞", "desktop_lyric_lock": "鎖定歌詞", "desktop_lyric_always_on_top": "使歌詞總是在其他窗口之上", + "desktop_lyric_lock_screen": "不允許歌詞窗口拖出主屏幕之外", "search": "搜索設置", "search_hot_title": "是否顯示熱門搜索", "search_hot": "熱門搜索", diff --git a/src/renderer/views/Setting.vue b/src/renderer/views/Setting.vue index 5caf0d6a..b135728a 100644 --- a/src/renderer/views/Setting.vue +++ b/src/renderer/views/Setting.vue @@ -82,6 +82,8 @@ div.scroll(:class="$style.setting") material-checkbox(id="setting_desktop_lyric_lock" v-model="current_setting.desktopLyric.isLock" :label="$t('view.setting.desktop_lyric_lock')") div(:class="$style.gapTop") material-checkbox(id="setting_desktop_lyric_alwaysOnTop" v-model="current_setting.desktopLyric.isAlwaysOnTop" :label="$t('view.setting.desktop_lyric_always_on_top')") + div(:class="$style.gapTop") + material-checkbox(id="setting_desktop_lyric_lockScreen" v-model="current_setting.desktopLyric.isLockScreen" :label="$t('view.setting.desktop_lyric_lock_screen')") dt {{$t('view.setting.search')}} dd(:title="$t('view.setting.search_hot_title')") h3 {{$t('view.setting.search_hot')}}