新增 不允许将歌词窗口拖出主屏幕之外 的设置项

pull/389/head
lyswhut 2020-08-23 12:13:17 +08:00
parent 44acc7d5ac
commit c15895ab45
10 changed files with 87 additions and 51 deletions

View File

@ -1,6 +1,7 @@
### 新增
- 在歌单详情界面新增播放当前歌单按钮、收藏歌单按钮
- 新增`不允许将歌词窗口拖出主屏幕之外`的设置项,默认开启,在连接多个屏幕时想要拖动到其他屏幕时可关闭此设置
### 修复

View File

@ -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,

View File

@ -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 => {

View File

@ -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,

View File

@ -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)
})

View File

@ -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)
}

View File

@ -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",

View File

@ -48,6 +48,7 @@
"desktop_lyric_enable": "显示歌词",
"desktop_lyric_lock": "锁定歌词",
"desktop_lyric_always_on_top": "使歌词总是在其他窗口之上",
"desktop_lyric_lock_screen": "不允许歌词窗口拖出主屏幕之外",
"search": "搜索设置",
"search_hot_title": "是否显示热门搜索",

View File

@ -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": "熱門搜索",

View File

@ -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')}}