mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-03-13 08:28:13 -04:00
🔨 Refactor(custom): refactored window manager
This commit is contained in:
parent
eae84cb096
commit
dfbbadea46
@ -233,19 +233,9 @@ windowList.set(IWindowList.RENAME_WINDOW, {
|
|||||||
window.loadURL(handleWindowParams(RENAME_WINDOW_URL))
|
window.loadURL(handleWindowParams(RENAME_WINDOW_URL))
|
||||||
const currentWindow = windowManager.getAvailableWindow(true)
|
const currentWindow = windowManager.getAvailableWindow(true)
|
||||||
if (currentWindow && currentWindow.isVisible()) {
|
if (currentWindow && currentWindow.isVisible()) {
|
||||||
// bounds: { x: 821, y: 75, width: 800, height: 450 }
|
const { x, y, width, height } = currentWindow.getBounds()
|
||||||
const bounds = currentWindow.getBounds()
|
const positionX = Math.floor(x + width / 2 - 150)
|
||||||
let positionX = bounds.x + bounds.width / 2 - 150
|
const positionY = Math.floor(y + height / 2 - (height > 400 ? 88 : 0))
|
||||||
let positionY
|
|
||||||
// if is the settingWindow
|
|
||||||
if (bounds.height > 400) {
|
|
||||||
positionY = bounds.y + bounds.height / 2 - 88
|
|
||||||
} else {
|
|
||||||
// if is the miniWindow
|
|
||||||
positionY = bounds.y + bounds.height / 2
|
|
||||||
}
|
|
||||||
positionX = Math.floor(positionX)
|
|
||||||
positionY = Math.floor(positionY)
|
|
||||||
window.setPosition(positionX, positionY, false)
|
window.setPosition(positionX, positionY, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,16 +249,9 @@ windowList.set(IWindowList.TOOLBOX_WINDOW, {
|
|||||||
window.loadURL(TOOLBOX_WINDOW_URL)
|
window.loadURL(TOOLBOX_WINDOW_URL)
|
||||||
const currentWindow = windowManager.getAvailableWindow(true)
|
const currentWindow = windowManager.getAvailableWindow(true)
|
||||||
if (currentWindow && currentWindow.isVisible()) {
|
if (currentWindow && currentWindow.isVisible()) {
|
||||||
const bounds = currentWindow.getBounds()
|
const { x, y, width, height } = currentWindow.getBounds()
|
||||||
let positionX = bounds.x + bounds.width / 2 - 400
|
const positionX = Math.floor(x + width / 2 - 400)
|
||||||
let positionY
|
const positionY = Math.floor(y + height / 2 - (height > 400 ? 225 : 0))
|
||||||
if (bounds.height > 400) {
|
|
||||||
positionY = bounds.y + bounds.height / 2 - 225
|
|
||||||
} else {
|
|
||||||
positionY = bounds.y + bounds.height / 2
|
|
||||||
}
|
|
||||||
positionX = Math.floor(positionX)
|
|
||||||
positionY = Math.floor(positionY)
|
|
||||||
window.setPosition(positionX, positionY, false)
|
window.setPosition(positionX, positionY, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,36 +9,31 @@ class WindowManager implements IWindowManager {
|
|||||||
|
|
||||||
create(name: IWindowList) {
|
create(name: IWindowList) {
|
||||||
const windowConfig: IWindowListItem = windowList.get(name)!
|
const windowConfig: IWindowListItem = windowList.get(name)!
|
||||||
if (windowConfig.isValid) {
|
if (!windowConfig.isValid) return null
|
||||||
if (!windowConfig.multiple) {
|
|
||||||
if (this.has(name)) return this.#windowMap.get(name)!
|
if (!windowConfig.multiple) {
|
||||||
}
|
if (this.has(name)) return this.#windowMap.get(name)!
|
||||||
const window = new BrowserWindow(windowConfig.options())
|
|
||||||
const id = window.id
|
|
||||||
if (windowConfig.multiple) {
|
|
||||||
this.#windowMap.set(`${name}_${window.id}`, window)
|
|
||||||
this.#windowIdMap.set(window.id, `${name}_${window.id}`)
|
|
||||||
} else {
|
|
||||||
this.#windowMap.set(name, window)
|
|
||||||
this.#windowIdMap.set(window.id, name)
|
|
||||||
}
|
|
||||||
windowConfig.callback(window, this)
|
|
||||||
window.on('close', () => {
|
|
||||||
this.deleteById(id)
|
|
||||||
})
|
|
||||||
return window
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const window = new BrowserWindow(windowConfig.options())
|
||||||
|
const id = window.id
|
||||||
|
const windowName = windowConfig.multiple ? `${name}_${id}` : name
|
||||||
|
|
||||||
|
this.#windowMap.set(windowName, window)
|
||||||
|
this.#windowIdMap.set(id, windowName)
|
||||||
|
|
||||||
|
windowConfig.callback(window, this)
|
||||||
|
window.on('close', () => {
|
||||||
|
this.deleteById(id)
|
||||||
|
})
|
||||||
|
return window
|
||||||
}
|
}
|
||||||
|
|
||||||
get(name: IWindowList) {
|
get(name: IWindowList) {
|
||||||
if (this.has(name)) {
|
if (this.has(name)) {
|
||||||
return this.#windowMap.get(name)!
|
return this.#windowMap.get(name)!
|
||||||
} else {
|
|
||||||
const window = this.create(name)
|
|
||||||
return window
|
|
||||||
}
|
}
|
||||||
|
return this.create(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
has(name: IWindowList) {
|
has(name: IWindowList) {
|
||||||
@ -57,11 +52,15 @@ class WindowManager implements IWindowManager {
|
|||||||
const miniWindow = this.#windowMap.get(IWindowList.MINI_WINDOW)
|
const miniWindow = this.#windowMap.get(IWindowList.MINI_WINDOW)
|
||||||
if (miniWindow && miniWindow.isVisible() && !isSkipMiniWindow) {
|
if (miniWindow && miniWindow.isVisible() && !isSkipMiniWindow) {
|
||||||
return miniWindow
|
return miniWindow
|
||||||
} else {
|
|
||||||
const settingWindow = this.#windowMap.get(IWindowList.SETTING_WINDOW)
|
|
||||||
const trayWindow = this.#windowMap.get(IWindowList.TRAY_WINDOW)
|
|
||||||
return settingWindow || trayWindow || this.create(IWindowList.SETTING_WINDOW)!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingWindow = this.#windowMap.get(IWindowList.SETTING_WINDOW)
|
||||||
|
if (settingWindow) return settingWindow
|
||||||
|
|
||||||
|
const trayWindow = this.#windowMap.get(IWindowList.TRAY_WINDOW)
|
||||||
|
if (trayWindow) return trayWindow
|
||||||
|
|
||||||
|
return this.create(IWindowList.SETTING_WINDOW)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user