mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-28 03:30:24 +08:00
✨ Feature: add update progress bar and some optimization
ISSUES CLOSED: #83
This commit is contained in:
@@ -94,14 +94,16 @@ import { NodeHttpHandler } from '@smithy/node-http-handler'
|
||||
import http, { AgentOptions } from 'http'
|
||||
import https from 'https'
|
||||
|
||||
// 通用获取 Agent 函数
|
||||
// 工具函数
|
||||
import { getAgent } from '../manage/utils/common'
|
||||
import logger from '@core/picgo/logger'
|
||||
|
||||
const STORE_PATH = app.getPath('userData')
|
||||
|
||||
export default {
|
||||
listen () {
|
||||
picgoCoreIPC.listen()
|
||||
// Upload Related IPC
|
||||
// from macOS tray
|
||||
ipcMain.on('uploadClipboardFiles', async () => {
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
@@ -137,6 +139,7 @@ export default {
|
||||
return uploadChoosedFiles(evt.sender, files)
|
||||
})
|
||||
|
||||
// ShortKey Related IPC
|
||||
ipcMain.on('updateShortKey', (evt: IpcMainEvent, item: IShortKeyConfig, oldKey: string, from: string) => {
|
||||
const result = shortKeyHandler.updateShortKey(item, oldKey, from)
|
||||
evt.sender.send('updateShortKeyResponse', result)
|
||||
@@ -172,6 +175,7 @@ export default {
|
||||
}
|
||||
})
|
||||
|
||||
// Gallery image cloud delete IPC
|
||||
ipcMain.handle('delete-sftp-file', async (_evt: IpcMainInvokeEvent, config: ISftpPlistConfig, fileName: string) => {
|
||||
try {
|
||||
const client = SSHClient.instance
|
||||
@@ -190,7 +194,6 @@ export default {
|
||||
ipcMain.handle('delete-aws-s3-file', async (_evt: IpcMainInvokeEvent, configMap: IStringKeyMap) => {
|
||||
try {
|
||||
const { imgUrl, config: { accessKeyID, secretAccessKey, bucketName, region, endpoint, pathStyleAccess, rejectUnauthorized, proxy } } = configMap
|
||||
console.log(JSON.stringify(configMap, null, 2))
|
||||
const url = new URL(!/^https?:\/\//.test(imgUrl) ? `http://${imgUrl}` : imgUrl)
|
||||
const fileKey = url.pathname.replace(/^\/+/, '')
|
||||
const endpointUrl: string | undefined = endpoint
|
||||
@@ -242,11 +245,13 @@ export default {
|
||||
const result = await client.send(command)
|
||||
return result.$metadata.httpStatusCode === 204
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
// migrate from PicGo
|
||||
|
||||
ipcMain.handle('migrateFromPicGo', async () => {
|
||||
const picGoConfigPath = STORE_PATH.replace('piclist', 'picgo')
|
||||
const fileToMigration = [
|
||||
@@ -274,6 +279,8 @@ export default {
|
||||
}
|
||||
})
|
||||
|
||||
// PicList Setting page IPC
|
||||
|
||||
ipcMain.on('updateCustomLink', () => {
|
||||
const notification = new Notification({
|
||||
title: T('OPERATION_SUCCEED'),
|
||||
@@ -339,6 +346,8 @@ export default {
|
||||
mainWindow.setAlwaysOnTop(!isAlwaysOnTop)
|
||||
})
|
||||
|
||||
// Window operation API
|
||||
|
||||
ipcMain.on('openSettingWindow', () => {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.show()
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
|
||||
@@ -62,9 +62,8 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
uploadChoosedFiles(win.webContents, files)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
autoUpdater.setFeedURL({
|
||||
@@ -90,9 +89,19 @@ autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||
autoUpdater.downloadUpdate()
|
||||
}
|
||||
db.set('settings.showUpdateTip', !result.checkboxChecked)
|
||||
}).catch((err) => {
|
||||
logger.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
autoUpdater.on('download-progress', (progressObj) => {
|
||||
const percent = {
|
||||
progress: progressObj.percent
|
||||
}
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send('updateProgress', percent)
|
||||
})
|
||||
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
@@ -100,9 +109,13 @@ autoUpdater.on('update-downloaded', () => {
|
||||
buttons: ['Yes', 'No'],
|
||||
message: T('TIPS_UPDATE_DOWNLOADED')
|
||||
}).then((result) => {
|
||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
window.webContents.send('updateProgress', { progress: 100 })
|
||||
if (result.response === 0) {
|
||||
autoUpdater.quitAndInstall()
|
||||
}
|
||||
}).catch((err) => {
|
||||
logger.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user