2023-08-07 04:36:27 -04:00
|
|
|
import { app } from 'electron'
|
|
|
|
|
2020-01-07 07:49:27 -05:00
|
|
|
import {
|
2024-06-08 23:53:07 -04:00
|
|
|
MANUAL_WINDOW_URL,
|
2020-01-07 07:49:27 -05:00
|
|
|
MINI_WINDOW_URL,
|
2023-05-05 05:51:49 -04:00
|
|
|
RENAME_WINDOW_URL,
|
2024-06-08 23:53:07 -04:00
|
|
|
SETTING_WINDOW_URL,
|
|
|
|
TRAY_WINDOW_URL,
|
|
|
|
TOOLBOX_WINDOW_URL
|
2020-01-07 07:49:27 -05:00
|
|
|
} from './constants'
|
2023-08-07 04:36:27 -04:00
|
|
|
|
2024-06-08 23:53:07 -04:00
|
|
|
import bus from '@core/bus'
|
2020-04-10 11:28:46 -04:00
|
|
|
import { CREATE_APP_MENU } from '@core/bus/constants'
|
2024-06-08 23:53:07 -04:00
|
|
|
import db from '@core/datastore'
|
|
|
|
|
|
|
|
import { T } from '~/i18n'
|
|
|
|
|
2020-04-12 10:34:45 -04:00
|
|
|
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'
|
2024-06-08 23:53:07 -04:00
|
|
|
import { IWindowList } from '#/types/enum'
|
|
|
|
import { configPaths } from '#/utils/configPaths'
|
2020-01-07 07:49:27 -05:00
|
|
|
|
|
|
|
const windowList = new Map<IWindowList, IWindowListItem>()
|
|
|
|
|
2023-06-28 09:57:17 -04:00
|
|
|
const handleWindowParams = (windowURL: string) => windowURL
|
2022-02-20 08:30:22 -05:00
|
|
|
|
2024-06-15 07:37:50 -04:00
|
|
|
const getDefaultWindowSizes = (): { width: number; height: number } => {
|
|
|
|
const [mainWindowWidth, mainWindowHeight] = db.get([
|
|
|
|
configPaths.settings.mainWindowWidth,
|
|
|
|
configPaths.settings.mainWindowHeight
|
|
|
|
])
|
2023-03-24 03:57:43 -04:00
|
|
|
return {
|
|
|
|
width: mainWindowWidth || 1200,
|
|
|
|
height: mainWindowHeight || 800
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-12 11:38:17 -04:00
|
|
|
const { width: defaultWindowWidth, height: defaultWindowHeight } = getDefaultWindowSizes()
|
2023-03-24 03:57:43 -04:00
|
|
|
|
2023-06-28 09:57:17 -04:00
|
|
|
const trayWindowOptions = {
|
|
|
|
height: 350,
|
|
|
|
width: 196,
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
|
|
|
fullscreenable: false,
|
|
|
|
resizable: false,
|
|
|
|
transparent: true,
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true,
|
|
|
|
backgroundThrottling: false,
|
|
|
|
webSecurity: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-12 03:31:41 -04:00
|
|
|
const manualWindowOptions = {
|
|
|
|
height: 800,
|
|
|
|
width: 1200,
|
|
|
|
show: false,
|
|
|
|
frame: true,
|
|
|
|
center: true,
|
|
|
|
fullscreenable: true,
|
|
|
|
resizable: true,
|
|
|
|
title: 'Manual',
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
transparent: false,
|
|
|
|
webPreferences: {
|
|
|
|
webviewTag: true,
|
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true,
|
|
|
|
webSecurity: false
|
|
|
|
}
|
|
|
|
} as IBrowserWindowOptions
|
|
|
|
|
2023-06-28 09:57:17 -04:00
|
|
|
const settingWindowOptions = {
|
|
|
|
height: defaultWindowHeight,
|
|
|
|
width: defaultWindowWidth,
|
|
|
|
show: false,
|
|
|
|
frame: true,
|
|
|
|
center: true,
|
|
|
|
fullscreenable: true,
|
|
|
|
resizable: true,
|
|
|
|
title: 'PicList',
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
transparent: true,
|
|
|
|
titleBarStyle: 'hidden',
|
|
|
|
webPreferences: {
|
2023-08-28 03:47:50 -04:00
|
|
|
webviewTag: true,
|
2023-06-28 09:57:17 -04:00
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true,
|
|
|
|
webSecurity: false
|
|
|
|
}
|
|
|
|
} as IBrowserWindowOptions
|
|
|
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
settingWindowOptions.show = false
|
|
|
|
settingWindowOptions.frame = false
|
|
|
|
settingWindowOptions.backgroundColor = '#3f3c37'
|
|
|
|
settingWindowOptions.transparent = false
|
|
|
|
settingWindowOptions.icon = `${__static}/logo.png`
|
|
|
|
}
|
|
|
|
|
|
|
|
const miniWindowOptions = {
|
|
|
|
height: 64,
|
|
|
|
width: 64,
|
|
|
|
show: process.platform === 'linux',
|
|
|
|
frame: false,
|
|
|
|
fullscreenable: false,
|
|
|
|
skipTaskbar: true,
|
|
|
|
resizable: false,
|
|
|
|
transparent: process.platform !== 'linux',
|
|
|
|
icon: `${__static}/logo.png`,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true
|
|
|
|
}
|
|
|
|
} as IBrowserWindowOptions
|
|
|
|
|
2024-04-09 03:03:32 -04:00
|
|
|
if (db.get(configPaths.settings.miniWindowOntop)) {
|
2023-06-28 09:57:17 -04:00
|
|
|
miniWindowOptions.alwaysOnTop = true
|
|
|
|
}
|
|
|
|
|
|
|
|
const renameWindowOptions = {
|
|
|
|
height: 175,
|
|
|
|
width: 300,
|
|
|
|
show: true,
|
|
|
|
fullscreenable: false,
|
|
|
|
resizable: false,
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true,
|
|
|
|
backgroundThrottling: false
|
|
|
|
}
|
|
|
|
} as IBrowserWindowOptions
|
|
|
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
renameWindowOptions.show = true
|
|
|
|
renameWindowOptions.backgroundColor = '#3f3c37'
|
|
|
|
renameWindowOptions.autoHideMenuBar = true
|
|
|
|
renameWindowOptions.transparent = false
|
|
|
|
}
|
|
|
|
|
|
|
|
const toolboxWindowOptions = {
|
|
|
|
height: 450,
|
|
|
|
width: 800,
|
|
|
|
show: false,
|
|
|
|
frame: true,
|
|
|
|
center: true,
|
|
|
|
fullscreenable: false,
|
|
|
|
resizable: false,
|
|
|
|
title: `PicList ${T('TOOLBOX')}`,
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
icon: `${__static}/logo.png`,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: !!process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
|
|
|
|
nodeIntegrationInWorker: true,
|
|
|
|
webSecurity: false
|
|
|
|
}
|
|
|
|
} as IBrowserWindowOptions
|
|
|
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
toolboxWindowOptions.backgroundColor = '#3f3c37'
|
|
|
|
toolboxWindowOptions.autoHideMenuBar = true
|
|
|
|
toolboxWindowOptions.transparent = false
|
|
|
|
}
|
|
|
|
|
2020-01-07 07:49:27 -05:00
|
|
|
windowList.set(IWindowList.TRAY_WINDOW, {
|
|
|
|
isValid: process.platform !== 'linux',
|
|
|
|
multiple: false,
|
2023-06-28 09:57:17 -04:00
|
|
|
options: () => trayWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
callback(window) {
|
2022-02-20 08:30:22 -05:00
|
|
|
window.loadURL(handleWindowParams(TRAY_WINDOW_URL))
|
2020-04-10 11:28:46 -04:00
|
|
|
window.on('blur', () => {
|
|
|
|
window.hide()
|
2020-01-07 07:49:27 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-09-12 03:31:41 -04:00
|
|
|
windowList.set(IWindowList.MANUAL_WINDOW, {
|
|
|
|
isValid: true,
|
|
|
|
multiple: false,
|
|
|
|
options: () => manualWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
callback(window) {
|
2023-09-12 03:31:41 -04:00
|
|
|
window.loadURL(handleWindowParams(MANUAL_WINDOW_URL))
|
|
|
|
window.focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-07 07:49:27 -05:00
|
|
|
windowList.set(IWindowList.SETTING_WINDOW, {
|
|
|
|
isValid: true,
|
|
|
|
multiple: false,
|
2023-06-28 09:57:17 -04:00
|
|
|
options: () => settingWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
callback(window, windowManager) {
|
2022-02-20 08:30:22 -05:00
|
|
|
window.loadURL(handleWindowParams(SETTING_WINDOW_URL))
|
2020-04-10 11:28:46 -04:00
|
|
|
window.on('closed', () => {
|
2020-04-12 10:34:45 -04:00
|
|
|
bus.emit(TOGGLE_SHORTKEY_MODIFIED_MODE, false)
|
2020-01-07 07:49:27 -05:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
process.nextTick(() => {
|
|
|
|
app.quit()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
bus.emit(CREATE_APP_MENU)
|
2020-04-12 10:34:45 -04:00
|
|
|
windowManager.create(IWindowList.MINI_WINDOW)
|
2020-01-07 07:49:27 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
windowList.set(IWindowList.MINI_WINDOW, {
|
|
|
|
isValid: process.platform !== 'darwin',
|
|
|
|
multiple: false,
|
2023-06-28 09:57:17 -04:00
|
|
|
options: () => miniWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
callback(window) {
|
2022-02-20 08:30:22 -05:00
|
|
|
window.loadURL(handleWindowParams(MINI_WINDOW_URL))
|
2020-01-07 07:49:27 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
windowList.set(IWindowList.RENAME_WINDOW, {
|
|
|
|
isValid: true,
|
|
|
|
multiple: true,
|
2023-06-28 09:57:17 -04:00
|
|
|
options: () => renameWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
async callback(window, windowManager) {
|
2022-02-20 08:30:22 -05:00
|
|
|
window.loadURL(handleWindowParams(RENAME_WINDOW_URL))
|
2024-04-11 00:06:15 -04:00
|
|
|
const currentWindow = windowManager.getAvailableWindow(true)
|
2020-01-07 07:49:27 -05:00
|
|
|
if (currentWindow && currentWindow.isVisible()) {
|
2024-06-15 07:37:50 -04:00
|
|
|
// bounds: { x: 821, y: 75, width: 800, height: 450 }
|
2020-01-07 07:49:27 -05:00
|
|
|
const bounds = currentWindow.getBounds()
|
2024-06-24 10:55:02 -04:00
|
|
|
let positionX = bounds.x + bounds.width / 2 - 150
|
2020-01-07 07:49:27 -05:00
|
|
|
let positionY
|
|
|
|
// if is the settingWindow
|
|
|
|
if (bounds.height > 400) {
|
|
|
|
positionY = bounds.y + bounds.height / 2 - 88
|
2024-06-15 07:37:50 -04:00
|
|
|
} else {
|
|
|
|
// if is the miniWindow
|
2020-01-07 07:49:27 -05:00
|
|
|
positionY = bounds.y + bounds.height / 2
|
|
|
|
}
|
2024-06-24 10:55:02 -04:00
|
|
|
positionX = Math.floor(positionX)
|
|
|
|
positionY = Math.floor(positionY)
|
2020-04-10 11:28:46 -04:00
|
|
|
window.setPosition(positionX, positionY, false)
|
2020-01-07 07:49:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-05-05 05:51:49 -04:00
|
|
|
windowList.set(IWindowList.TOOLBOX_WINDOW, {
|
|
|
|
isValid: true,
|
|
|
|
multiple: false,
|
2023-06-28 09:57:17 -04:00
|
|
|
options: () => toolboxWindowOptions,
|
2024-06-15 07:37:50 -04:00
|
|
|
async callback(window, windowManager) {
|
2023-05-05 05:51:49 -04:00
|
|
|
window.loadURL(TOOLBOX_WINDOW_URL)
|
2024-04-11 00:06:15 -04:00
|
|
|
const currentWindow = windowManager.getAvailableWindow(true)
|
2023-05-05 05:51:49 -04:00
|
|
|
if (currentWindow && currentWindow.isVisible()) {
|
|
|
|
const bounds = currentWindow.getBounds()
|
2024-06-24 10:55:02 -04:00
|
|
|
let positionX = bounds.x + bounds.width / 2 - 400
|
2023-05-05 05:51:49 -04:00
|
|
|
let positionY
|
|
|
|
if (bounds.height > 400) {
|
|
|
|
positionY = bounds.y + bounds.height / 2 - 225
|
|
|
|
} else {
|
|
|
|
positionY = bounds.y + bounds.height / 2
|
|
|
|
}
|
2024-06-24 10:55:02 -04:00
|
|
|
positionX = Math.floor(positionX)
|
|
|
|
positionY = Math.floor(positionY)
|
2023-05-05 05:51:49 -04:00
|
|
|
window.setPosition(positionX, positionY, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-07 07:49:27 -05:00
|
|
|
export default windowList
|