mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-31 12:49:41 +08:00
⚡ Perf(custom): reduce idle memory usage by 60 percent
This commit is contained in:
@@ -109,8 +109,7 @@ export function createMenu() {
|
||||
export function createContextMenu() {
|
||||
const ClipboardWatcher = clipboardPoll
|
||||
const isListeningClipboard = picgo.getConfig<boolean | undefined>(configPaths.settings.isListeningClipboard) || false
|
||||
const isMiniWindowVisible =
|
||||
windowManager.has(IWindowList.MINI_WINDOW) && windowManager.get(IWindowList.MINI_WINDOW)!.isVisible()
|
||||
const isMiniWindowVisible = windowManager.get(IWindowList.MINI_WINDOW)?.isVisible() || false
|
||||
|
||||
const startWatchClipboard = () => {
|
||||
picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: true })
|
||||
@@ -236,11 +235,9 @@ export function createTray(tooltip: string) {
|
||||
// click事件在Mac和Windows上可以触发(在Ubuntu上无法触发,Unity不支持)
|
||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
||||
tray.on('right-click', () => {
|
||||
if (windowManager.has(IWindowList.TRAY_WINDOW)) {
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)!.hide()
|
||||
}
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.hide()
|
||||
createContextMenu()
|
||||
tray!.popUpContextMenu(contextMenu!)
|
||||
tray?.popUpContextMenu(contextMenu!)
|
||||
})
|
||||
|
||||
tray.on('click', (_, bounds) => {
|
||||
@@ -277,33 +274,29 @@ export function createTray(tooltip: string) {
|
||||
})
|
||||
}
|
||||
}
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)!.webContents.send('clipboardFiles', obj)
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents.send('clipboardFiles', obj)
|
||||
}, 0)
|
||||
} else {
|
||||
if (windowManager.has(IWindowList.TRAY_WINDOW)) {
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)!.hide()
|
||||
}
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.hide()
|
||||
const autoCloseMiniWindow =
|
||||
picgo.getConfig<boolean | undefined>(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||
if (autoCloseMiniWindow) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)?.close()
|
||||
}
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
}
|
||||
})
|
||||
|
||||
tray.on('drag-enter', () => {
|
||||
if (nativeTheme.shouldUseDarkColors) {
|
||||
tray!.setImage(uploadDarkPng)
|
||||
tray?.setImage(uploadDarkPng)
|
||||
} else {
|
||||
tray!.setImage(uploadPng)
|
||||
tray?.setImage(uploadPng)
|
||||
}
|
||||
})
|
||||
|
||||
tray.on('drag-end', () => {
|
||||
tray!.setImage(getTrayIcon())
|
||||
tray?.setImage(getTrayIcon())
|
||||
})
|
||||
|
||||
// drop-files only be supported in macOS
|
||||
@@ -313,8 +306,8 @@ export function createTray(tooltip: string) {
|
||||
const allConfig = picgo.getConfig<any>() || {}
|
||||
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||
const rawInput = cloneDeep(files)
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
const res = await uploader.setWebContents(trayWindow.webContents).uploadReturnCtx(files)
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
const res = await uploader.setWebContents(trayWindow?.webContents).uploadReturnCtx(files)
|
||||
const imgs = res[0] ? res[0] : false
|
||||
const backImgs = res[1] ? res[1] : false
|
||||
const deleteLocalFile = allConfig.settings?.deleteLocalFile || false
|
||||
@@ -344,33 +337,35 @@ export function createTray(tooltip: string) {
|
||||
await GalleryDB.getInstance().insert(imgs[i])
|
||||
}
|
||||
handleCopyUrl(pasteText.join('\n'))
|
||||
trayWindow.webContents.send('dragFiles', imgs)
|
||||
trayWindow?.webContents.send('dragFiles', imgs)
|
||||
}
|
||||
if (backImgs !== false) {
|
||||
for (const backImg of backImgs) {
|
||||
await GalleryDB.getInstance().insert(backImg)
|
||||
}
|
||||
trayWindow.webContents.send('dragFiles', backImgs)
|
||||
trayWindow?.webContents.send('dragFiles', backImgs)
|
||||
}
|
||||
})
|
||||
}
|
||||
// toggleWindow()
|
||||
} else if (process.platform === 'linux') {
|
||||
// click事件在Ubuntu上无法触发,Unity不支持(在Mac和Windows上可以触发)
|
||||
// 需要使用 setContextMenu 设置菜单
|
||||
createContextMenu()
|
||||
tray!.setContextMenu(contextMenu)
|
||||
tray?.setContextMenu(contextMenu)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleWindow = (bounds: IBounds) => {
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
if (trayWindow.isVisible()) {
|
||||
let trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
if (!trayWindow) {
|
||||
trayWindow = windowManager.create(IWindowList.TRAY_WINDOW)
|
||||
}
|
||||
if (trayWindow?.isVisible()) {
|
||||
trayWindow.hide()
|
||||
} else {
|
||||
trayWindow.setPosition(bounds.x - 98 + 11, bounds.y, false)
|
||||
trayWindow.webContents.send('updateFiles')
|
||||
trayWindow.show()
|
||||
trayWindow.focus()
|
||||
trayWindow?.setPosition(bounds.x - 98 + 11, bounds.y, false)
|
||||
trayWindow?.webContents.send('updateFiles')
|
||||
trayWindow?.show()
|
||||
trayWindow?.focus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ import path from 'node:path'
|
||||
import { themesDir } from '@core/datastore/dirs'
|
||||
import * as fsWalk from '@nodelib/fs.walk'
|
||||
import AdmZip from 'adm-zip'
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
import axios from 'axios'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
import { randomStringGenerator } from '@/manage/utils/common'
|
||||
import { IWindowList } from '~/utils/enum'
|
||||
|
||||
import windowManager from '../window/windowManager'
|
||||
|
||||
let insertedCSSKeyMain: string | undefined
|
||||
|
||||
export async function resolveThemes(): Promise<{ key: string; label: string }[]> {
|
||||
@@ -75,12 +76,11 @@ export async function readTheme(theme: string): Promise<string> {
|
||||
export async function applyTheme(theme: string): Promise<void> {
|
||||
theme = path.basename(theme)
|
||||
const css = await readTheme(theme)
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
try {
|
||||
await windowManager.get(IWindowList.SETTING_WINDOW)?.webContents.removeInsertedCSS(insertedCSSKeyMain || '')
|
||||
insertedCSSKeyMain = await windowManager.get(IWindowList.SETTING_WINDOW)?.webContents.insertCSS(css)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
try {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
await window?.webContents.removeInsertedCSS(insertedCSSKeyMain || '')
|
||||
insertedCSSKeyMain = await window?.webContents.insertCSS(css)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ const handleClipboardUploadingReturnCtx = async (img?: IUploadOption): Promise<(
|
||||
const useBuiltinClipboard = useBuiltinClipboardConfig === undefined ? true : !!useBuiltinClipboardConfig
|
||||
const win = windowManager.getAvailableWindow()
|
||||
if (useBuiltinClipboard) {
|
||||
return await uploader.setWebContents(win!.webContents).uploadWithBuildInClipboardReturnCtx(img)
|
||||
return await uploader.setWebContents(win?.webContents).uploadWithBuildInClipboardReturnCtx(img)
|
||||
}
|
||||
return await uploader.setWebContents(win!.webContents).uploadReturnCtx(img)
|
||||
return await uploader.setWebContents(win?.webContents).uploadReturnCtx(img)
|
||||
}
|
||||
|
||||
export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
@@ -31,7 +31,6 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
const allConfig = picgo.getConfig<any>() || {}
|
||||
if (img !== false) {
|
||||
if (img.length > 0) {
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||
const [pastedText, shortUrl] = await pasteTemplate(pasteStyle, img[0], allConfig.settings?.customLink)
|
||||
img[0].shortUrl = shortUrl
|
||||
@@ -52,17 +51,15 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
}
|
||||
const inserted = await GalleryDB.getInstance().insert(img[0])
|
||||
// trayWindow just be created in mac/windows, not in linux
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
trayWindow?.webContents?.send('clipboardFiles', [])
|
||||
trayWindow?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
settingWindow?.webContents?.send('updateGallery')
|
||||
if (backImg !== false) {
|
||||
await GalleryDB.getInstance().insert(backImg[0])
|
||||
trayWindow?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
settingWindow?.webContents?.send('updateGallery')
|
||||
}
|
||||
return {
|
||||
url: handleUrlEncodeWithSetting(inserted.imgUrl as string),
|
||||
@@ -88,7 +85,7 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
}
|
||||
|
||||
export const uploadChoosedFiles = async (
|
||||
webContents: WebContents,
|
||||
webContents: WebContents | undefined,
|
||||
files: IFileWithPath[],
|
||||
): Promise<IStringKeyMap[]> => {
|
||||
const input = files.map(item => item.path)
|
||||
@@ -150,18 +147,16 @@ export const uploadChoosedFiles = async (
|
||||
}
|
||||
handleCopyUrl(pasteText.join('\n'))
|
||||
// trayWindow just be created in mac/windows, not in linux
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
trayWindow?.webContents?.send('uploadFiles')
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
settingWindow?.webContents?.send('updateGallery')
|
||||
if (backImgs !== false) {
|
||||
for (const backImg of backImgs) {
|
||||
await GalleryDB.getInstance().insert(backImg)
|
||||
}
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
trayWindow?.webContents?.send('uploadFiles')
|
||||
settingWindow?.webContents?.send('updateGallery')
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
|
||||
@@ -17,22 +17,22 @@ import { configPaths } from '~/utils/configPaths'
|
||||
import { ICOREBuildInEvent, IWindowList } from '~/utils/enum'
|
||||
import { CLIPBOARD_IMAGE_FOLDER } from '~/utils/static'
|
||||
|
||||
const waitForRename = (window: BrowserWindow, id: number): Promise<string | null> => {
|
||||
const waitForRename = (window: BrowserWindow | undefined, id: number | undefined): Promise<string | null> => {
|
||||
return new Promise(resolve => {
|
||||
ipcMain.once(`${RENAME_FILE_NAME}${id}`, (_: IpcMainEvent, newName: string) => {
|
||||
resolve(newName)
|
||||
window.close()
|
||||
window?.close()
|
||||
})
|
||||
window.on('close', () => {
|
||||
window?.on('close', () => {
|
||||
resolve(null)
|
||||
ipcMain.removeAllListeners(`${RENAME_FILE_NAME}${id}`)
|
||||
windowManager.deleteById(window.id)
|
||||
windowManager.deleteById(window?.id)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
class Uploader {
|
||||
private webContents: WebContents | null = null
|
||||
private webContents: WebContents | undefined = undefined
|
||||
|
||||
constructor() {
|
||||
this.init()
|
||||
@@ -77,10 +77,10 @@ class Uploader {
|
||||
? `${dayjs().add(index, 'ms').format('YYYYMMDDHHmmssSSS')}${item.extname}`
|
||||
: item.fileName
|
||||
if (rename) {
|
||||
const window = windowManager.create(IWindowList.RENAME_WINDOW)!
|
||||
const window = windowManager.create(IWindowList.RENAME_WINDOW)
|
||||
ipcMain.on(GET_RENAME_FILE_NAME, (evt, _) => {
|
||||
try {
|
||||
if (evt.sender.id === window.webContents.id) {
|
||||
if (evt.sender.id === window?.webContents.id) {
|
||||
logger.info('rename window ready, wait for rename...')
|
||||
window.webContents.send(RENAME_FILE_NAME, fileName, item.fileName, window.webContents.id)
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class Uploader {
|
||||
logger.error(e)
|
||||
}
|
||||
})
|
||||
name = await waitForRename(window, window.webContents.id)
|
||||
name = await waitForRename(window, window?.webContents.id)
|
||||
}
|
||||
item.fileName = name || fileName
|
||||
}),
|
||||
@@ -98,7 +98,7 @@ class Uploader {
|
||||
})
|
||||
}
|
||||
|
||||
setWebContents(webContents: WebContents) {
|
||||
setWebContents(webContents: WebContents | undefined) {
|
||||
this.webContents = webContents
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import { configPaths } from '~/utils/configPaths'
|
||||
import { IWindowList } from '~/utils/enum'
|
||||
|
||||
import logo from '../../../../../resources/logo.png?asset&asarUnpack'
|
||||
import { applyTheme } from '../theme'
|
||||
|
||||
const windowList = new Map<string, IWindowListItem>()
|
||||
|
||||
@@ -182,7 +181,10 @@ windowList.set(IWindowList.TRAY_WINDOW, {
|
||||
window.loadFile(path.join(dirname, '../renderer/index.html'))
|
||||
}
|
||||
window.on('blur', () => {
|
||||
window.hide()
|
||||
window.close()
|
||||
})
|
||||
window.on('closed', () => {
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -191,7 +193,7 @@ windowList.set(IWindowList.SETTING_WINDOW, {
|
||||
isValid: true,
|
||||
multiple: false,
|
||||
options: () => settingWindowOptions,
|
||||
callback(window, windowManager) {
|
||||
callback(window) {
|
||||
if (!app.isPackaged && process.env.ELECTRON_RENDERER_URL) {
|
||||
window.loadURL(`${process.env.ELECTRON_RENDERER_URL}#main-page/upload`)
|
||||
} else {
|
||||
@@ -201,18 +203,13 @@ windowList.set(IWindowList.SETTING_WINDOW, {
|
||||
}
|
||||
window.on('closed', () => {
|
||||
bus.emit(TOGGLE_SHORTKEY_MODIFIED_MODE, false)
|
||||
if (process.platform === 'linux') {
|
||||
process.nextTick(() => {
|
||||
app.quit()
|
||||
})
|
||||
}
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
window.on('ready-to-show', () => {
|
||||
const customTheme = picgo.getConfig<string>(configPaths.settings.theme) || 'default.css'
|
||||
applyTheme(customTheme)
|
||||
window.once('ready-to-show', async () => {
|
||||
window.show()
|
||||
window.focus()
|
||||
})
|
||||
bus.emit(CREATE_APP_MENU)
|
||||
windowManager.create(IWindowList.MINI_WINDOW)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -220,7 +217,8 @@ windowList.set(IWindowList.MINI_WINDOW, {
|
||||
isValid: process.platform !== 'darwin',
|
||||
multiple: false,
|
||||
options: () => miniWindowOptions,
|
||||
callback(window) {
|
||||
callback(window, windowManager) {
|
||||
const id = window.id
|
||||
if (!app.isPackaged && process.env.ELECTRON_RENDERER_URL) {
|
||||
window.loadURL(`${process.env.ELECTRON_RENDERER_URL}#mini-page`)
|
||||
} else {
|
||||
@@ -228,6 +226,10 @@ windowList.set(IWindowList.MINI_WINDOW, {
|
||||
hash: 'mini-page',
|
||||
})
|
||||
}
|
||||
window.on('closed', () => {
|
||||
windowManager.deleteById(id)
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -250,6 +252,9 @@ windowList.set(IWindowList.RENAME_WINDOW, {
|
||||
const positionY = Math.floor(y + height / 2 - (height > 400 ? 88 : 0))
|
||||
window.setPosition(positionX, positionY, false)
|
||||
}
|
||||
window.on('closed', () => {
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -272,6 +277,13 @@ windowList.set(IWindowList.TOOLBOX_WINDOW, {
|
||||
const positionY = Math.floor(y + height / 2 - (height > 400 ? 225 : 0))
|
||||
window.setPosition(positionX, positionY, false)
|
||||
}
|
||||
window.once('ready-to-show', () => {
|
||||
window.show()
|
||||
window.focus()
|
||||
})
|
||||
window.on('closed', () => {
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -322,6 +334,9 @@ windowList.set(IWindowList.UPDATE_WINDOW, {
|
||||
const positionY = Math.floor(y + height / 2 - 300)
|
||||
window.setPosition(positionX, positionY, false)
|
||||
}
|
||||
window.on('closed', () => {
|
||||
window = null as unknown as Electron.BrowserWindow
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -9,10 +9,15 @@ class WindowManager implements IWindowManager {
|
||||
|
||||
create(name: string) {
|
||||
const windowConfig: IWindowListItem = windowList.get(name)!
|
||||
if (!windowConfig.isValid) return null
|
||||
if (!windowConfig.isValid) return undefined
|
||||
|
||||
if (!windowConfig.multiple) {
|
||||
if (this.has(name)) return this.#windowMap.get(name)!
|
||||
const existingWin = this.#windowMap.get(name)
|
||||
if (existingWin) {
|
||||
if (existingWin.isMinimized()) existingWin.restore()
|
||||
existingWin.focus()
|
||||
return existingWin
|
||||
}
|
||||
}
|
||||
|
||||
const window = new BrowserWindow(windowConfig.options())
|
||||
@@ -30,17 +35,15 @@ class WindowManager implements IWindowManager {
|
||||
}
|
||||
|
||||
get(name: string) {
|
||||
if (this.has(name)) {
|
||||
return this.#windowMap.get(name)!
|
||||
}
|
||||
return this.create(name)
|
||||
return this.#windowMap.get(name) || undefined
|
||||
}
|
||||
|
||||
has(name: string) {
|
||||
return this.#windowMap.has(name)
|
||||
}
|
||||
|
||||
deleteById = (id: number) => {
|
||||
deleteById = (id: number | undefined) => {
|
||||
if (id === undefined) return
|
||||
const name = this.#windowIdMap.get(id)
|
||||
if (name) {
|
||||
this.#windowMap.delete(name)
|
||||
@@ -59,8 +62,7 @@ class WindowManager implements IWindowManager {
|
||||
|
||||
const trayWindow = this.#windowMap.get(IWindowList.TRAY_WINDOW)
|
||||
if (trayWindow) return trayWindow
|
||||
|
||||
return this.create(IWindowList.SETTING_WINDOW)!
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,19 +38,19 @@ async function busCallUploadClipboardFiles() {
|
||||
|
||||
async function busCallUploadFiles(pathList: IFileWithPath[]) {
|
||||
const win = windowManager.getAvailableWindow()
|
||||
const result = await uploadChoosedFiles(win.webContents, pathList)
|
||||
const result = await uploadChoosedFiles(win?.webContents, pathList)
|
||||
const urls = result.map((item: any) => item.url)
|
||||
bus.emit(UPLOAD_WITH_FILES_RESPONSE, urls)
|
||||
}
|
||||
|
||||
function busCallGetWindowId() {
|
||||
const win = windowManager.getAvailableWindow()
|
||||
bus.emit(GET_WINDOW_ID_REPONSE, win.id)
|
||||
bus.emit(GET_WINDOW_ID_REPONSE, win?.id)
|
||||
}
|
||||
|
||||
function busCallGetSettingWindowId() {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
bus.emit(GET_SETTING_WINDOW_ID_RESPONSE, settingWindow.id)
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
bus.emit(GET_SETTING_WINDOW_ID_RESPONSE, settingWindow?.id)
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -52,7 +52,10 @@ const buildMiniPageMenu = () => {
|
||||
{
|
||||
label: $t('HIDE_MINI_WINDOW'),
|
||||
click() {
|
||||
BrowserWindow.getFocusedWindow()!.hide()
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
console.log('hide mini window', miniWindow)
|
||||
miniWindow?.close()
|
||||
console.log('mini window closed')
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -93,7 +96,7 @@ const buildMiniPageMenu = () => {
|
||||
return Menu.buildFromTemplate(template)
|
||||
}
|
||||
|
||||
const buildMainPageMenu = (win: BrowserWindow) => {
|
||||
const buildMainPageMenu = (win: BrowserWindow | undefined) => {
|
||||
const template = [
|
||||
{
|
||||
label: $t('ABOUT'),
|
||||
@@ -121,8 +124,7 @@ const buildMainPageMenu = (win: BrowserWindow) => {
|
||||
{
|
||||
label: $t('OPEN_TOOLBOX'),
|
||||
click() {
|
||||
const window = windowManager.create(IWindowList.TOOLBOX_WINDOW)
|
||||
window?.show()
|
||||
windowManager.create(IWindowList.TOOLBOX_WINDOW)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -234,9 +236,7 @@ const buildPicBedListMenu = () => {
|
||||
checked: config._id === defaultId && item.type === currentPicBed,
|
||||
click() {
|
||||
changeCurrentUploader(item.type, config, config._id)
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('syncPicBed')
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('syncPicBed')
|
||||
setTrayToolTip(`${item.type} ${config._configName || 'Default'}`)
|
||||
},
|
||||
}
|
||||
@@ -248,9 +248,7 @@ const buildPicBedListMenu = () => {
|
||||
[configPaths.picBed.current]: item.type,
|
||||
[configPaths.picBed.uploader]: item.type,
|
||||
})
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('syncPicBed')
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('syncPicBed')
|
||||
setTrayToolTip(item.type)
|
||||
}
|
||||
: undefined,
|
||||
@@ -293,8 +291,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
||||
picgo.saveConfig({
|
||||
[`picgoPlugins.${plugin.fullName}`]: true,
|
||||
})
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send(PICGO_TOGGLE_PLUGIN, plugin.fullName, true)
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send(PICGO_TOGGLE_PLUGIN, plugin.fullName, true)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -304,10 +301,10 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
||||
picgo.saveConfig({
|
||||
[`picgoPlugins.${plugin.fullName}`]: false,
|
||||
})
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
window.webContents.send(PICGO_TOGGLE_PLUGIN, plugin.fullName, false)
|
||||
window.webContents.send(PICGO_HANDLE_PLUGIN_DONE, plugin.fullName)
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
window?.webContents?.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
window?.webContents?.send(PICGO_TOGGLE_PLUGIN, plugin.fullName, false)
|
||||
window?.webContents?.send(PICGO_HANDLE_PLUGIN_DONE, plugin.fullName)
|
||||
if (plugin.config.transformer.name) {
|
||||
handleRestoreState('transformer', plugin.config.transformer.name)
|
||||
}
|
||||
@@ -319,16 +316,16 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
||||
{
|
||||
label: $t('UNINSTALL_PLUGIN'),
|
||||
click() {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
window?.webContents?.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
handlePluginUninstall(plugin.fullName)
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('UPDATE_PLUGIN'),
|
||||
click() {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
window?.webContents?.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
||||
handlePluginUpdate(plugin.fullName)
|
||||
},
|
||||
},
|
||||
@@ -340,11 +337,11 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
||||
c: `${i} - ${plugin.config[i].fullName || plugin.config[i].name}`,
|
||||
}),
|
||||
click() {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const currentType = i
|
||||
const configName = plugin.config[i].fullName || plugin.config[i].name
|
||||
const config = plugin.config[i].config
|
||||
window.webContents.send(PICGO_CONFIG_PLUGIN, currentType, configName, config)
|
||||
window?.webContents?.send(PICGO_CONFIG_PLUGIN, currentType, configName, config)
|
||||
},
|
||||
}
|
||||
menu.push(obj)
|
||||
|
||||
@@ -125,27 +125,27 @@ const handleNPMError = (): IDispose => {
|
||||
}
|
||||
|
||||
export const handlePluginUpdate = async (fullName: string | string[]) => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const dispose = handleNPMError()
|
||||
const res = await picgo.pluginHandler.update(typeof fullName === 'string' ? [fullName] : fullName)
|
||||
if (res.success) {
|
||||
window.webContents.send('updateSuccess', res.body[0])
|
||||
window?.webContents?.send('updateSuccess', res.body[0])
|
||||
} else {
|
||||
showNotification({
|
||||
title: $t('PLUGIN_UPDATE_FAILED'),
|
||||
body: res.body as string,
|
||||
})
|
||||
}
|
||||
window.webContents.send('hideLoading')
|
||||
window?.webContents.send('hideLoading')
|
||||
dispose()
|
||||
}
|
||||
|
||||
export const handlePluginUninstall = async (fullName: string) => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const dispose = handleNPMError()
|
||||
const res = await picgo.pluginHandler.uninstall([fullName])
|
||||
if (res.success) {
|
||||
window.webContents.send('uninstallSuccess', res.body[0])
|
||||
window?.webContents?.send('uninstallSuccess', res.body[0])
|
||||
shortKeyHandler.unregisterPluginShortKey(res.body[0])
|
||||
} else {
|
||||
showNotification({
|
||||
@@ -153,7 +153,7 @@ export const handlePluginUninstall = async (fullName: string) => {
|
||||
body: res.body as string,
|
||||
})
|
||||
}
|
||||
window.webContents.send('hideLoading')
|
||||
window?.webContents?.send('hideLoading')
|
||||
dispose()
|
||||
}
|
||||
|
||||
@@ -195,7 +195,8 @@ export const pluginInstallFunc = async (event: IIPCEvent, args: [fullName: strin
|
||||
}
|
||||
|
||||
export const pluginImportLocalFunc = async (event: IIPCEvent) => {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
if (!settingWindow) return
|
||||
const res = await dialog.showOpenDialog(settingWindow, {
|
||||
properties: ['openDirectory'],
|
||||
})
|
||||
|
||||
@@ -39,7 +39,6 @@ export default [
|
||||
action: IRPCActionType.CONFIGURE_MIGRATE_FROM_PICLIST_INSTALLATION,
|
||||
handler: async () => {
|
||||
const configDir = app.getPath('userData')
|
||||
console.log('Migrating from PicList installation at:', configDir)
|
||||
const files = [
|
||||
'data.json',
|
||||
'data.bak.json',
|
||||
|
||||
@@ -2,8 +2,9 @@ import { isPortable } from '@core/datastore/dirs'
|
||||
import picgo from '@core/picgo'
|
||||
import { app, nativeTheme, shell } from 'electron'
|
||||
|
||||
import { applyTheme, fetchThemes, importThemes, resolveThemes } from '~/apis/app/theme'
|
||||
import { applyTheme, fetchThemes, importThemes, readTheme, resolveThemes } from '~/apis/app/theme'
|
||||
import { i18nManager } from '~/i18n'
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
import { IRPCActionType, IRPCType } from '~/utils/enum'
|
||||
|
||||
export default [
|
||||
@@ -88,4 +89,20 @@ export default [
|
||||
},
|
||||
type: IRPCType.INVOKE,
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.THEME_GET_BOOTSTRAP,
|
||||
handler: async () => {
|
||||
let savedMode = picgo.getConfig<string>(configPaths.settings.systemTheme) || 'system'
|
||||
const customTheme = picgo.getConfig<string>(configPaths.settings.theme) || 'default.css'
|
||||
if (savedMode === 'system') {
|
||||
savedMode = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
|
||||
}
|
||||
const theme = await readTheme(customTheme)
|
||||
return {
|
||||
mode: savedMode,
|
||||
css: theme,
|
||||
}
|
||||
},
|
||||
type: IRPCType.INVOKE,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -22,9 +22,7 @@ export default [
|
||||
action: IRPCActionType.OPEN_WINDOW,
|
||||
handler: async (_: IIPCEvent, args: [windowName: string]) => {
|
||||
const window = windowManager.get(args[0])
|
||||
if (window) {
|
||||
window.show()
|
||||
}
|
||||
window?.show()
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -37,11 +35,7 @@ export default [
|
||||
action: IRPCActionType.CLOSE_WINDOW,
|
||||
handler: async () => {
|
||||
const window = BrowserWindow.getFocusedWindow()
|
||||
if (process.platform === 'linux') {
|
||||
window?.hide()
|
||||
} else {
|
||||
window?.close()
|
||||
}
|
||||
window?.close()
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -54,7 +48,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.SHOW_MINI_PAGE_MENU,
|
||||
handler: async () => {
|
||||
const window = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
const menu = buildMiniPageMenu()
|
||||
menu.popup({
|
||||
window,
|
||||
@@ -64,7 +58,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.SHOW_MAIN_PAGE_MENU,
|
||||
handler: async () => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const menu = buildMainPageMenu(window)
|
||||
menu.popup({
|
||||
window,
|
||||
@@ -74,7 +68,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.SHOW_UPLOAD_PAGE_MENU,
|
||||
handler: async () => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const menu = buildPicBedListMenu()
|
||||
menu.popup({
|
||||
window,
|
||||
@@ -84,7 +78,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.SHOW_SECOND_UPLOADER_MENU,
|
||||
handler: async () => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const menu = buildSecondPicBedMenu()
|
||||
menu.popup({
|
||||
window,
|
||||
@@ -94,7 +88,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.SHOW_PLUGIN_PAGE_MENU,
|
||||
handler: async (_: IIPCEvent, args: [plugin: IPicGoPlugin]) => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const menu = buildPluginPageMenu(args[0])
|
||||
menu.popup({
|
||||
window,
|
||||
@@ -111,30 +105,30 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.MINI_WINDOW_ON_TOP,
|
||||
handler: async (_: IIPCEvent, args: [isOnTop: boolean]) => {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.setAlwaysOnTop(args[0])
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
miniWindow?.setAlwaysOnTop(args[0])
|
||||
},
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MAIN_WINDOW_ON_TOP,
|
||||
handler: async () => {
|
||||
const mainWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const isAlwaysOnTop = mainWindow.isAlwaysOnTop()
|
||||
mainWindow.setAlwaysOnTop(!isAlwaysOnTop)
|
||||
const mainWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const isAlwaysOnTop = mainWindow?.isAlwaysOnTop()
|
||||
mainWindow?.setAlwaysOnTop(!isAlwaysOnTop)
|
||||
},
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.UPDATE_MINI_WINDOW_ICON,
|
||||
handler: async (_: IIPCEvent, args: [iconPath: string]) => {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.webContents.send('updateMiniIcon', args[0])
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
miniWindow?.webContents?.send('updateMiniIcon', args[0])
|
||||
},
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.REFRESH_SETTING_WINDOW,
|
||||
handler: async () => {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
settingWindow.webContents.session.clearCache().then(() => {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
settingWindow?.webContents.session.clearCache().then(() => {
|
||||
settingWindow.webContents.reloadIgnoringCache()
|
||||
})
|
||||
},
|
||||
|
||||
@@ -29,9 +29,9 @@ const trayRoutes = [
|
||||
{
|
||||
action: IRPCActionType.TRAY_UPLOAD_CLIPBOARD_FILES,
|
||||
handler: async () => {
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
// macOS use builtin clipboard is OK
|
||||
const res = await uploader.setWebContents(trayWindow.webContents).uploadWithBuildInClipboardReturnCtx()
|
||||
const res = await uploader.setWebContents(trayWindow?.webContents).uploadWithBuildInClipboardReturnCtx()
|
||||
const img = res[0] ? res[0] : false
|
||||
const backupImgs = res[1] ? res[1] : false
|
||||
const allConfig = picgo.getConfig<any>() || {}
|
||||
@@ -54,19 +54,19 @@ const trayRoutes = [
|
||||
notification.show()
|
||||
}
|
||||
await GalleryDB.getInstance().insert(img[0])
|
||||
trayWindow.webContents.send('clipboardFiles', [])
|
||||
trayWindow?.webContents.send('clipboardFiles', [])
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery')
|
||||
}
|
||||
if (backupImgs && backupImgs.length > 0) {
|
||||
await GalleryDB.getInstance().insert(backupImgs[0])
|
||||
trayWindow.webContents.send('uploadFiles')
|
||||
trayWindow?.webContents.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
}
|
||||
}
|
||||
trayWindow.webContents.send('uploadFiles')
|
||||
trayWindow?.webContents.send('uploadFiles')
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@@ -65,15 +65,8 @@ const progressHandler = (progressObj: updater.ProgressInfo) => {
|
||||
const percent = {
|
||||
progress: progressObj.percent,
|
||||
}
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const updateWindow = windowManager.get(IWindowList.UPDATE_WINDOW)
|
||||
|
||||
if (settingWindow) {
|
||||
settingWindow.webContents.send('updateProgress', percent)
|
||||
}
|
||||
if (updateWindow) {
|
||||
updateWindow.webContents.send('UPDATE_PROGRESS', percent)
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('updateProgress', percent)
|
||||
windowManager.get(IWindowList.UPDATE_WINDOW)?.webContents?.send('UPDATE_PROGRESS', percent)
|
||||
}
|
||||
|
||||
const downloadedHandler = () => {
|
||||
@@ -82,10 +75,10 @@ const downloadedHandler = () => {
|
||||
if (!windowManager.has(IWindowList.UPDATE_WINDOW)) {
|
||||
windowManager.create(IWindowList.UPDATE_WINDOW)
|
||||
}
|
||||
const updateWindow = windowManager.get(IWindowList.UPDATE_WINDOW)!
|
||||
const updateWindow = windowManager.get(IWindowList.UPDATE_WINDOW)
|
||||
|
||||
const sendUpdateInfo = () => {
|
||||
updateWindow.webContents.send('SHOW_UPDATE_INFO', {
|
||||
updateWindow?.webContents.send('SHOW_UPDATE_INFO', {
|
||||
type: 'update-downloaded',
|
||||
title: lang === II18nLanguage.ZH_CN ? '更新已下载' : 'Update Downloaded',
|
||||
message:
|
||||
@@ -95,14 +88,14 @@ const downloadedHandler = () => {
|
||||
})
|
||||
}
|
||||
|
||||
if (updateWindow.webContents.isLoading()) {
|
||||
if (updateWindow?.webContents.isLoading()) {
|
||||
updateWindow.webContents.once('did-finish-load', sendUpdateInfo)
|
||||
} else {
|
||||
sendUpdateInfo()
|
||||
}
|
||||
|
||||
if (!updateWindow.isVisible()) {
|
||||
updateWindow.show()
|
||||
if (!updateWindow?.isVisible()) {
|
||||
updateWindow?.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import '~/lifeCycle/errorHandler'
|
||||
|
||||
import path from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
import bus from '@core/bus'
|
||||
import picgo from '@core/picgo'
|
||||
@@ -10,9 +11,10 @@ import shortKeyHandler from 'apis/app/shortKey/shortKeyHandler'
|
||||
import { createTray, setDockMenu } from 'apis/app/system'
|
||||
import { uploadChoosedFiles, uploadClipboardFiles } from 'apis/app/uploader/apis'
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
import { app, globalShortcut, Notification, protocol, screen } from 'electron'
|
||||
import { app, globalShortcut, net, Notification, protocol, screen } from 'electron'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
import { themesDir } from '~/apis/core/datastore/dirs'
|
||||
import busEventList from '~/events/busEventList'
|
||||
import { rpcServer } from '~/events/rpc'
|
||||
import { startFileServer, stopFileServer } from '~/fileServer'
|
||||
@@ -50,7 +52,7 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
if (files.length > 0) {
|
||||
logger.info('cli -> uploading files from cli', ...files.map(file => file.path))
|
||||
const win = windowManager.getAvailableWindow()
|
||||
uploadChoosedFiles(win.webContents, files)
|
||||
uploadChoosedFiles(win?.webContents, files)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -62,6 +64,9 @@ await setupAutoUpdater()
|
||||
class LifeCycle {
|
||||
async #beforeReady() {
|
||||
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{ scheme: 'theme', privileges: { standard: true, secure: true, supportFetchAPI: true } },
|
||||
])
|
||||
// fix the $PATH in macOS & linux
|
||||
fixPath()
|
||||
beforeOpen()
|
||||
@@ -78,9 +83,16 @@ class LifeCycle {
|
||||
|
||||
#onReady() {
|
||||
const readyFunction = async () => {
|
||||
protocol.handle('theme', request => {
|
||||
const requestUrl = request.url
|
||||
const urlObj = new URL(requestUrl)
|
||||
const relativePath = urlObj.pathname
|
||||
const themeBaseDir = path.join(themesDir())
|
||||
const absolutePath = path.join(themeBaseDir, relativePath)
|
||||
return net.fetch(pathToFileURL(absolutePath).toString())
|
||||
})
|
||||
const allConfig = picgo.getConfig<any>() || {}
|
||||
windowManager.create(IWindowList.TRAY_WINDOW)
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
// clipboard monitor
|
||||
const isAutoListenClipboard = allConfig.settings?.isAutoListenClipboard || false
|
||||
const ClipboardWatcher = clipboardPoll
|
||||
if (isAutoListenClipboard) {
|
||||
@@ -127,50 +139,53 @@ class LifeCycle {
|
||||
notice.show()
|
||||
}
|
||||
}
|
||||
if (isDevelopment) {
|
||||
MemoryMonitor.start()
|
||||
}
|
||||
await remoteNoticeHandler.init()
|
||||
remoteNoticeHandler.triggerHook(IRemoteNoticeTriggerHook.APP_START)
|
||||
if (startMode === ISartMode.MINI && process.platform !== 'darwin') {
|
||||
windowManager.create(IWindowList.MINI_WINDOW)
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.removeAllListeners()
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
miniWindow?.removeAllListeners()
|
||||
if (allConfig.settings?.miniWindowOntop) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
miniWindow?.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = allConfig.settings?.miniWindowPosition
|
||||
if (lastPosition) {
|
||||
if (lastPosition[0] < 0 || lastPosition[0] > width || lastPosition[1] < 0 || lastPosition[1] > height) {
|
||||
miniWindow.setPosition(width - 100, height - 100)
|
||||
miniWindow?.setPosition(width - 100, height - 100)
|
||||
picgo.saveConfig({ [configPaths.settings.miniWindowPosition]: [width - 100, height - 100] })
|
||||
} else if (
|
||||
lastPosition[0] + miniWindow.getSize()[0] > width ||
|
||||
lastPosition[1] + miniWindow.getSize()[1] > height
|
||||
lastPosition[0] + miniWindow?.getSize()[0] > width ||
|
||||
lastPosition[1] + miniWindow?.getSize()[1] > height
|
||||
) {
|
||||
miniWindow.setPosition(width - miniWindow.getSize()[0], height - miniWindow.getSize()[1])
|
||||
picgo.saveConfig({
|
||||
[configPaths.settings.miniWindowPosition]: [
|
||||
width - miniWindow.getSize()[0],
|
||||
height - miniWindow.getSize()[1],
|
||||
],
|
||||
})
|
||||
miniWindow?.setPosition(width - miniWindow.getSize()[0], height - miniWindow.getSize()[1])
|
||||
if (miniWindow) {
|
||||
picgo.saveConfig({
|
||||
[configPaths.settings.miniWindowPosition]: [
|
||||
width - miniWindow.getSize()[0],
|
||||
height - miniWindow.getSize()[1],
|
||||
],
|
||||
})
|
||||
}
|
||||
} else {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
miniWindow?.setPosition(lastPosition[0], lastPosition[1])
|
||||
}
|
||||
} else {
|
||||
miniWindow.setPosition(width - 100, height - 100)
|
||||
miniWindow?.setPosition(width - 100, height - 100)
|
||||
}
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
const position = miniWindow?.getPosition()
|
||||
picgo.saveConfig({ [configPaths.settings.miniWindowPosition]: position })
|
||||
}
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
miniWindow.show()
|
||||
miniWindow.focus()
|
||||
miniWindow?.on('close', setPositionFunc)
|
||||
miniWindow?.on('move', setPositionFunc)
|
||||
miniWindow?.show()
|
||||
miniWindow?.focus()
|
||||
} else if (startMode === ISartMode.MAIN) {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
settingWindow.show()
|
||||
settingWindow.focus()
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
}
|
||||
const clipboardDir = path.join(picgo.baseDir, CLIPBOARD_IMAGE_FOLDER)
|
||||
fs.emptyDir(clipboardDir)
|
||||
@@ -183,19 +198,10 @@ class LifeCycle {
|
||||
logger.info('detect second instance')
|
||||
const result = handleStartUpFiles(commandLine, workingDirectory)
|
||||
if (!result) {
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
if (settingWindow.isMinimized()) {
|
||||
settingWindow.restore()
|
||||
}
|
||||
settingWindow.focus()
|
||||
}
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
}
|
||||
})
|
||||
app.on('activate', () => {
|
||||
if (!windowManager.has(IWindowList.TRAY_WINDOW)) {
|
||||
windowManager.create(IWindowList.TRAY_WINDOW)
|
||||
}
|
||||
if (!windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
}
|
||||
@@ -228,11 +234,7 @@ class LifeCycle {
|
||||
}
|
||||
|
||||
#onQuit() {
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
app.on('window-all-closed', () => {})
|
||||
|
||||
app.on('will-quit', () => {
|
||||
UpDownTaskQueue.getInstance().persist()
|
||||
|
||||
@@ -207,7 +207,7 @@ class AliyunApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -246,10 +246,10 @@ class AliyunApi {
|
||||
res?.objects?.forEach((item: OSS.ObjectMeta) => {
|
||||
item.size !== 0 && result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
@@ -257,12 +257,12 @@ class AliyunApi {
|
||||
} while (res.isTruncated === true && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -305,10 +305,10 @@ class AliyunApi {
|
||||
res?.objects?.forEach((item: OSS.ObjectMeta) => {
|
||||
item.size !== 0 && result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -316,7 +316,7 @@ class AliyunApi {
|
||||
} while (res.isTruncated === true && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ class GithubApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: repo, customUrl: branch, prefix, cancelToken, cdnUrl } = configMap
|
||||
const slicedPrefix = prefix.replace(/(^\/+|\/+$)/g, '')
|
||||
const cancelTask = [false]
|
||||
@@ -220,22 +220,22 @@ class GithubApi {
|
||||
result.fullList.push(this.formatFile(item, currentPrefix, branch, repo, cdnUrl))
|
||||
}
|
||||
})
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
}
|
||||
result.success = true
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: repo, customUrl: branch, prefix, cancelToken, cdnUrl } = configMap
|
||||
const slicedPrefix = prefix.replace(/(^\/+|\/+$)/g, '')
|
||||
const cancelTask = [false]
|
||||
@@ -265,13 +265,13 @@ class GithubApi {
|
||||
})
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
result.success = true
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class ImgurApi {
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketConfig: { Location: albumHash },
|
||||
cancelToken,
|
||||
@@ -122,7 +122,7 @@ class ImgurApi {
|
||||
})
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -139,7 +139,7 @@ class ImgurApi {
|
||||
})
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -148,7 +148,7 @@ class ImgurApi {
|
||||
}
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class LocalApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { prefix, customUrl = '', cancelToken } = configMap
|
||||
const urlPrefix = customUrl.replace(/\/+$/, '')
|
||||
const cancelTask = [false]
|
||||
@@ -109,12 +109,12 @@ class LocalApi {
|
||||
this.logParam(error, 'getBucketListRecursively')
|
||||
}
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { customUrl = '', cancelToken, baseDir } = configMap
|
||||
let prefix = configMap.prefix
|
||||
prefix = this.transBack(prefix)
|
||||
@@ -165,7 +165,7 @@ class LocalApi {
|
||||
this.logParam(error, 'getBucketListBackstage')
|
||||
}
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ class QiniuApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: bucket, prefix, cancelToken, customUrl: urlPrefix } = configMap
|
||||
let marker = undefined as any
|
||||
const slicedPrefix = prefix.slice(1)
|
||||
@@ -281,10 +281,10 @@ class QiniuApi {
|
||||
res.respBody.items.forEach((item: any) => {
|
||||
item.fsize !== 0 && result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
@@ -292,12 +292,12 @@ class QiniuApi {
|
||||
} while (res.respBody && res.respBody.marker && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: bucket, prefix, cancelToken, customUrl: urlPrefix } = configMap
|
||||
let marker = undefined as any
|
||||
const slicedPrefix = prefix.slice(1)
|
||||
@@ -349,10 +349,10 @@ class QiniuApi {
|
||||
res.respBody.items.forEach((item: any) => {
|
||||
item.fsize !== 0 && result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -360,7 +360,7 @@ class QiniuApi {
|
||||
} while (res.respBody && res.respBody.marker && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ class S3plistApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -345,11 +345,11 @@ class S3plistApi {
|
||||
res.Contents.forEach((item: _Object) => {
|
||||
result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
this.logParam(res, 'getBucketListRecursively')
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
@@ -358,18 +358,18 @@ class S3plistApi {
|
||||
} catch (error) {
|
||||
this.logParam(error, 'getBucketListRecursively')
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -415,11 +415,11 @@ class S3plistApi {
|
||||
res.Contents.forEach((item: _Object) => {
|
||||
result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
} else {
|
||||
this.logParam(res, 'getBucketListBackstage')
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -428,13 +428,13 @@ class S3plistApi {
|
||||
} catch (error) {
|
||||
this.logParam(error, 'getBucketListBackstage')
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ class SftpApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { prefix, customUrl, cancelToken } = configMap
|
||||
const urlPrefix = customUrl || `${this.host}:${this.port}`
|
||||
const cancelTask = [false]
|
||||
@@ -185,7 +185,7 @@ class SftpApi {
|
||||
this.logParam(error, 'getBucketListRecursively')
|
||||
}
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class SftpApi {
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { prefix, customUrl, cancelToken, baseDir } = configMap
|
||||
let urlPrefix = customUrl || `${this.host}:${this.port}`
|
||||
urlPrefix = urlPrefix.replace(/\/+$/, '')
|
||||
@@ -257,20 +257,20 @@ class SftpApi {
|
||||
}
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
this.logParam(error, 'getBucketListBackstage')
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
result.success = true
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class SmmsApi {
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { cancelToken } = configMap
|
||||
let marker = 1
|
||||
const cancelTask = [false]
|
||||
@@ -84,18 +84,18 @@ class SmmsApi {
|
||||
if (res.data.Count === 0) {
|
||||
result.success = true
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
} else {
|
||||
res.data.data.forEach((item: any) => {
|
||||
result.fullList.push(this.formatFile(item))
|
||||
})
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
}
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class SmmsApi {
|
||||
} while (!cancelTask[0] && res?.status === 200 && res?.data?.success && res.data.CurrentPage < res.data.TotalPages)
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class TcyunApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -134,10 +134,10 @@ class TcyunApi {
|
||||
this.formatFile(item, slicedPrefix, urlPrefix),
|
||||
),
|
||||
)
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
@@ -145,12 +145,12 @@ class TcyunApi {
|
||||
} while (res.IsTruncated === 'true' && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const {
|
||||
bucketName: bucket,
|
||||
bucketConfig: { Location: region },
|
||||
@@ -190,10 +190,10 @@ class TcyunApi {
|
||||
this.formatFile(item, slicedPrefix, urlPrefix),
|
||||
),
|
||||
)
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -201,7 +201,7 @@ class TcyunApi {
|
||||
} while (res.IsTruncated === 'true' && !cancelTask[0])
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class UpyunApi {
|
||||
}
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: bucket, prefix, cancelToken } = configMap
|
||||
const slicedPrefix = prefix.slice(1)
|
||||
const urlPrefix = configMap.customUrl || `http://${bucket}.test.upcdn.net`
|
||||
@@ -147,10 +147,10 @@ class UpyunApi {
|
||||
item.type === 'F' && folderQueue.push(`${slicedPrefix}${item.name}/`)
|
||||
item.type === 'N' && result.fullList.push(this.formatFile(item, folder, urlPrefix))
|
||||
})
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
return
|
||||
}
|
||||
@@ -163,12 +163,12 @@ class UpyunApi {
|
||||
}
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { bucketName: bucket, prefix, cancelToken } = configMap
|
||||
const slicedPrefix = prefix.slice(1)
|
||||
const urlPrefix = configMap.customUrl || `http://${bucket}.test.upcdn.net`
|
||||
@@ -196,10 +196,10 @@ class UpyunApi {
|
||||
item.type === 'N' && result.fullList.push(this.formatFile(item, slicedPrefix, urlPrefix))
|
||||
item.type === 'F' && result.fullList.push(this.formatFolder(item, slicedPrefix, urlPrefix))
|
||||
})
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
@@ -207,7 +207,7 @@ class UpyunApi {
|
||||
} while (!cancelTask[0] && res.next !== this.stopMarker)
|
||||
result.success = !cancelTask[0]
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class WebdavplistApi {
|
||||
isRequestSuccess = (code: number) => code >= 200 && code < 300
|
||||
|
||||
async getBucketListRecursively(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { prefix, customUrl, cancelToken } = configMap
|
||||
const urlPrefix = customUrl || this.endpoint
|
||||
const cancelTask = [false]
|
||||
@@ -133,12 +133,12 @@ class WebdavplistApi {
|
||||
this.logParam(error, 'getBucketListRecursively')
|
||||
}
|
||||
result.finished = true
|
||||
window.webContents.send(refreshDownloadFileTransferList, result)
|
||||
window?.webContents.send(refreshDownloadFileTransferList, result)
|
||||
ipcMain.removeAllListeners(cancelDownloadLoadingFileList)
|
||||
}
|
||||
|
||||
async getBucketListBackstage(configMap: IStringKeyMap): Promise<any> {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const { prefix, customUrl, cancelToken, baseDir } = configMap
|
||||
let urlPrefix = customUrl || this.endpoint
|
||||
urlPrefix = urlPrefix.replace(/\/+$/, '')
|
||||
@@ -179,20 +179,20 @@ class WebdavplistApi {
|
||||
}
|
||||
} else {
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
this.logParam(error, 'getBucketListBackstage')
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
return
|
||||
}
|
||||
result.success = true
|
||||
result.finished = true
|
||||
window.webContents.send('refreshFileTransferList', result)
|
||||
window?.webContents.send('refreshFileTransferList', result)
|
||||
ipcMain.removeAllListeners('cancelLoadingFileList')
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,8 @@ export class ManageApi extends EventEmitter implements IManageApiType {
|
||||
}
|
||||
|
||||
private sendDefaultResult(eventName: string, defaultResult: any) {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send(eventName, defaultResult)
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
window?.webContents.send(eventName, defaultResult)
|
||||
ipcMain.removeAllListeners(
|
||||
eventName === refreshDownloadFileTransferList ? cancelDownloadLoadingFileList : 'cancelLoadingFileList',
|
||||
)
|
||||
|
||||
@@ -72,8 +72,6 @@ export const deleteChoosedFiles = async (list: ImgInfo[]): Promise<boolean[]> =>
|
||||
}
|
||||
}
|
||||
}
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('updateGallery')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { appConfigPath, themesDir } from '@core/datastore/dirs'
|
||||
import * as fsWalk from '@nodelib/fs.walk'
|
||||
import fs from 'fs-extra'
|
||||
import yaml from 'yaml'
|
||||
|
||||
@@ -101,37 +100,16 @@ function getClipboardFiles() {
|
||||
})
|
||||
}
|
||||
|
||||
function getFileInCssDir() {
|
||||
const cssDir = path.join(dirname, '../../resources/theme').replace('app.asar', 'app.asar.unpacked')
|
||||
const res = fsWalk.walkSync(cssDir, {
|
||||
followSymbolicLinks: true,
|
||||
fs,
|
||||
stats: true,
|
||||
throwErrorOnBrokenSymbolicLink: false,
|
||||
})
|
||||
const result: string[] = []
|
||||
res.forEach(item => {
|
||||
if (item.stats?.isFile()) {
|
||||
result.push(item.path)
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function resolveCss() {
|
||||
try {
|
||||
fs.ensureDirSync(themesDir())
|
||||
const css = getFileInCssDir()
|
||||
css.forEach(item => {
|
||||
const dest = path.join(themesDir(), path.basename(item))
|
||||
if (!fs.pathExistsSync(dest)) {
|
||||
fs.copyFileSync(item, dest)
|
||||
} else {
|
||||
diffFilesAndUpdate(item, dest)
|
||||
}
|
||||
const srcDir = path.join(dirname, '../../resources/theme').replace('app.asar', 'app.asar.unpacked')
|
||||
const destDir = themesDir()
|
||||
fs.copySync(srcDir, destDir, {
|
||||
overwrite: true,
|
||||
errorOnExist: false,
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('Failed to resolve CSS:', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,7 @@ export const configPaths = {
|
||||
enableSecondUploader: 'settings.enableSecondUploader',
|
||||
lastSyncTime: 'settings.lastSyncTime',
|
||||
theme: 'settings.theme',
|
||||
systemTheme: 'settings.systemTheme',
|
||||
enableAdvancedAnimation: 'settings.enableAdvancedAnimation',
|
||||
isDisableGPU: 'settings.isDisableGPU',
|
||||
},
|
||||
|
||||
@@ -79,6 +79,7 @@ export const IRPCActionType = {
|
||||
THEME_FETCH_THEMES: 'THEME_FETCH_THEMES',
|
||||
THEME_IMPORT_THEMES: 'THEME_IMPORT_THEMES',
|
||||
THEME_APPLY_THEME: 'THEME_APPLY_THEME',
|
||||
THEME_GET_BOOTSTRAP: 'THEME_GET_BOOTSTRAP',
|
||||
RELOAD_APP: 'RELOAD_APP',
|
||||
OPEN_URL: 'OPEN_URL',
|
||||
OPEN_FILE: 'OPEN_FILE',
|
||||
|
||||
@@ -264,17 +264,13 @@ class UploadTaskQueueManager {
|
||||
const inserted = await GalleryDB.getInstance().insert(img)
|
||||
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('updateGallery')
|
||||
|
||||
handleCopyUrl(pasteText)
|
||||
if (backupImgs && backupImgs.length > 0) {
|
||||
await GalleryDB.getInstance().insert(backupImgs[0])
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents?.send('uploadFiles')
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('updateGallery')
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -6,66 +6,69 @@ import { configPaths } from '~/utils/configPaths'
|
||||
import { IWindowList } from '~/utils/enum'
|
||||
|
||||
export function openMiniWindow(hideSettingWindow: boolean = true) {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
const allConfig = picgo.getConfig<any>() || {}
|
||||
let miniWindow = windowManager.get(IWindowList.MINI_WINDOW)
|
||||
if (!miniWindow) {
|
||||
miniWindow = windowManager.create(IWindowList.MINI_WINDOW)
|
||||
}
|
||||
|
||||
miniWindow.removeAllListeners('close')
|
||||
miniWindow.removeAllListeners('move')
|
||||
miniWindow?.removeAllListeners('close')
|
||||
miniWindow?.removeAllListeners('move')
|
||||
|
||||
if (picgo.getConfig<boolean>(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
if (allConfig.settings?.miniWindowOntop) {
|
||||
miniWindow?.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = picgo.getConfig<number[]>(configPaths.settings.miniWindowPosition)
|
||||
const lastPosition = allConfig.settings?.miniWindowPosition
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
const position = miniWindow?.getPosition()
|
||||
picgo.saveConfig({ [configPaths.settings.miniWindowPosition]: position })
|
||||
}
|
||||
if (lastPosition) {
|
||||
if (lastPosition[0] < 0 || lastPosition[0] > width || lastPosition[1] < 0 || lastPosition[1] > height) {
|
||||
miniWindow.setPosition(width - 100, height - 100)
|
||||
miniWindow?.setPosition(width - 100, height - 100)
|
||||
picgo.saveConfig({ [configPaths.settings.miniWindowPosition]: [width - 100, height - 100] })
|
||||
} else if (
|
||||
lastPosition[0] + miniWindow.getSize()[0] > width ||
|
||||
lastPosition[1] + miniWindow.getSize()[1] > height
|
||||
lastPosition[0] + miniWindow?.getSize()[0] > width ||
|
||||
lastPosition[1] + miniWindow?.getSize()[1] > height
|
||||
) {
|
||||
miniWindow.setPosition(width - miniWindow.getSize()[0], height - miniWindow.getSize()[1])
|
||||
picgo.saveConfig({
|
||||
[configPaths.settings.miniWindowPosition]: [width - miniWindow.getSize()[0], height - miniWindow.getSize()[1]],
|
||||
})
|
||||
miniWindow?.setPosition(width - miniWindow?.getSize()[0], height - miniWindow?.getSize()[1])
|
||||
if (miniWindow) {
|
||||
picgo.saveConfig({
|
||||
[configPaths.settings.miniWindowPosition]: [
|
||||
width - miniWindow.getSize()[0],
|
||||
height - miniWindow.getSize()[1],
|
||||
],
|
||||
})
|
||||
}
|
||||
} else {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
miniWindow?.setPosition(lastPosition[0], lastPosition[1])
|
||||
}
|
||||
} else {
|
||||
miniWindow.setPosition(width - 100, height - 100)
|
||||
miniWindow?.setPosition(width - 100, height - 100)
|
||||
}
|
||||
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
miniWindow.show()
|
||||
miniWindow.focus()
|
||||
miniWindow?.on('close', setPositionFunc)
|
||||
miniWindow?.on('move', setPositionFunc)
|
||||
miniWindow?.show()
|
||||
miniWindow?.focus()
|
||||
if (hideSettingWindow) {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
settingWindow.hide()
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.close()
|
||||
} else {
|
||||
const autoCloseMainWindow = picgo.getConfig<boolean>(configPaths.settings.autoCloseMainWindow) || false
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW) && autoCloseMainWindow) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.hide()
|
||||
const autoCloseMainWindow = allConfig.settings?.autoCloseMainWindow || false
|
||||
if (autoCloseMainWindow) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const openMainWindow = () => {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const autoCloseMiniWindow = picgo.getConfig<boolean>(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
if (autoCloseMiniWindow) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)?.close()
|
||||
}
|
||||
}
|
||||
|
||||
export const hideMiniWindow = () => {
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW)) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||
}
|
||||
windowManager.get(IWindowList.MINI_WINDOW)?.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user