🚧 WIP(custom): v3.0.0 migrate to vite and esm

This commit is contained in:
Kuingsmile
2025-07-31 17:37:30 +08:00
parent cd76bc7c10
commit 054f4b4cff
597 changed files with 197292 additions and 13329 deletions

View File

@@ -1,7 +1,7 @@
import path from 'path'
import { app } from 'electron'
import path from 'node:path'
import { getLogger } from '@core/utils/localLogger'
import { app } from 'electron'
const STORE_PATH = app.getPath('userData')
const LOG_PATH = path.join(STORE_PATH, 'piclist-gui-local.log')
@@ -24,9 +24,9 @@ process.on('unhandledRejection', (error: any) => {
})
// acconrding to https://github.com/Molunerfinn/PicGo/commit/7363be798cfef11e980934e542817ff1d6c04389#diff-896d0db4fbd446798fbffec14d456b4cd98d4c72c46856c770a585fa7ab0926f
function bootstrapEPIPESuppression() {
function bootstrapEPIPESuppression () {
let suppressing = false
function logEPIPEErrorOnce() {
function logEPIPEErrorOnce () {
if (suppressing) {
return
}
@@ -35,8 +35,27 @@ function bootstrapEPIPESuppression() {
handleProcessError('Detected EPIPE error; suppressing further EPIPE errors')
}
require('epipebomb')(process.stdout, logEPIPEErrorOnce)
require('epipebomb')(process.stderr, logEPIPEErrorOnce)
epipeBomb(process.stdout, logEPIPEErrorOnce)
epipeBomb(process.stderr, logEPIPEErrorOnce)
}
bootstrapEPIPESuppression()
function epipeBomb (stream: any, callback: any) {
if (stream == null) stream = process.stdout
if (callback == null) callback = process.exit
function epipeFilter (err: any) {
if (err.code === 'EPIPE') return callback()
// If there's more than one error handler (ie, us),
// then the error won't be bubbled up anyway
if (stream.listeners('error').length <= 1) {
stream.removeAllListeners() // Pretend we were never here
stream.emit('error', err) // Then emit as if we were never here
stream.on('error', epipeFilter) // Then reattach, ready for the next error!
}
}
stream.on('error', epipeFilter)
}

View File

@@ -1,12 +1,6 @@
// TODO: so how to import pure esm module in electron main process????? help wanted
import { shellPath } from 'shell-path'
// just copy the fix-path because I can't import pure ESM module in electron main process
// @ts-nocheck since the module is not pure ESM
// shell-path 3.0.0 not work
const shellPath = require('shell-path')
export default function fixPath() {
export default function fixPath () {
if (process.platform === 'win32') {
return
}

View File

@@ -1,25 +1,29 @@
import axios from 'axios'
import fs from 'fs-extra'
import { app, globalShortcut, protocol, Notification, dialog, screen, shell } from 'electron'
import { UpdateInfo, autoUpdater } from 'electron-updater'
import path from 'path'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import '~/lifeCycle/errorHandler'
import path from 'node:path'
import bus from '@core/bus'
import db from '@core/datastore'
import picgo from '@core/picgo'
import logger from '@core/picgo/logger'
import { remoteNoticeHandler } from 'apis/app/remoteNotice'
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 axios from 'axios'
import { app, dialog, globalShortcut, Notification, protocol, screen, shell } from 'electron'
import updater from 'electron-updater'
import fs from 'fs-extra'
import { II18nLanguage, IRemoteNoticeTriggerHook, ISartMode, IWindowList } from '#/types/enum'
import { configPaths } from '#/utils/configPaths'
import { notificationList } from '#/utils/notification'
import { CLIPBOARD_IMAGE_FOLDER } from '#/utils/static'
import busEventList from '~/events/busEventList'
import { rpcServer } from '~/events/rpc'
import { startFileServer, stopFileServer } from '~/fileServer'
import { T } from '~/i18n'
import '~/lifeCycle/errorHandler'
import fixPath from '~/lifeCycle/fixPath'
import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
import getManageApi from '~/manage/Main'
@@ -32,11 +36,6 @@ import { getUploadFiles } from '~/utils/handleArgv'
import { initI18n } from '~/utils/handleI18n'
import updateChecker from '~/utils/updateChecker'
import { II18nLanguage, IRemoteNoticeTriggerHook, ISartMode, IWindowList } from '#/types/enum'
import { configPaths } from '#/utils/configPaths'
import { CLIPBOARD_IMAGE_FOLDER } from '#/utils/static'
import { rpcServer } from '~/events/rpc'
const isDevelopment = process.env.NODE_ENV !== 'production'
const handleStartUpFiles = (argv: string[], cwd: string) => {
@@ -58,15 +57,15 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
return false
}
autoUpdater.setFeedURL({
updater.autoUpdater.setFeedURL({
provider: 'generic',
url: 'https://release.piclist.cn/latest',
channel: 'latest'
})
autoUpdater.autoDownload = false
updater.autoUpdater.autoDownload = false
autoUpdater.on('update-available', async (info: UpdateInfo) => {
updater.autoUpdater.on('update-available', async (info: updater.UpdateInfo) => {
const lang = db.get(configPaths.settings.language) || II18nLanguage.ZH_CN
let updateLog = ''
try {
@@ -110,7 +109,7 @@ autoUpdater.on('update-available', async (info: UpdateInfo) => {
})
.then(result => {
if (result.response === 0) {
autoUpdater.downloadUpdate()
updater.autoUpdater.downloadUpdate()
} else {
shell.openExternal('https://github.com/Kuingsmile/PicList/releases/latest')
}
@@ -121,7 +120,7 @@ autoUpdater.on('update-available', async (info: UpdateInfo) => {
})
})
autoUpdater.on('download-progress', progressObj => {
updater.autoUpdater.on('download-progress', progressObj => {
const percent = {
progress: progressObj.percent
}
@@ -129,7 +128,7 @@ autoUpdater.on('download-progress', progressObj => {
window.webContents.send('updateProgress', percent)
})
autoUpdater.on('update-downloaded', () => {
updater.autoUpdater.on('update-downloaded', () => {
dialog
.showMessageBox({
type: 'info',
@@ -141,7 +140,7 @@ autoUpdater.on('update-downloaded', () => {
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
window.webContents.send('updateProgress', { progress: 100 })
if (result.response === 0) {
autoUpdater.quitAndInstall()
updater.autoUpdater.quitAndInstall()
}
})
.catch(err => {
@@ -149,12 +148,12 @@ autoUpdater.on('update-downloaded', () => {
})
})
autoUpdater.on('error', err => {
updater.autoUpdater.on('error', err => {
console.log(err)
})
class LifeCycle {
async #beforeReady() {
async #beforeReady () {
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
// fix the $PATH in macOS & linux
fixPath()
@@ -166,9 +165,8 @@ class LifeCycle {
busEventList.listen()
}
#onReady() {
#onReady () {
const readyFunction = async () => {
createProtocol('picgo')
windowManager.create(IWindowList.TRAY_WINDOW)
windowManager.create(IWindowList.SETTING_WINDOW)
const isAutoListenClipboard = db.get(configPaths.settings.isAutoListenClipboard) || false
@@ -192,7 +190,7 @@ class LifeCycle {
const currentPicBedConfig = db.get(`picBed.${currentPicBed}`)?._configName || 'Default'
const tooltip = `${currentPicBed} ${currentPicBedConfig}`
if (process.platform === 'darwin') {
isHideDock ? app.dock.hide() : setDockMenu()
isHideDock ? app.dock?.hide() : setDockMenu()
startMode !== ISartMode.NO_TRAY && createTray(tooltip)
} else {
createTray(tooltip)
@@ -210,9 +208,9 @@ class LifeCycle {
handleStartUpFiles(process.argv, process.cwd())
}
if (global.notificationList && global.notificationList?.length > 0) {
while (global.notificationList?.length) {
const option = global.notificationList.pop()
if (notificationList && notificationList.length > 0) {
while (notificationList.length) {
const option = notificationList.pop()
const notice = new Notification(option!)
notice.show()
}
@@ -252,7 +250,7 @@ class LifeCycle {
app.whenReady().then(readyFunction)
}
#onRunning() {
#onRunning () {
app.on('second-instance', (_, commandLine, workingDirectory) => {
logger.info('detect second instance')
const result = handleStartUpFiles(commandLine, workingDirectory)
@@ -267,7 +265,6 @@ class LifeCycle {
}
})
app.on('activate', () => {
createProtocol('picgo')
if (!windowManager.has(IWindowList.TRAY_WINDOW)) {
windowManager.create(IWindowList.TRAY_WINDOW)
}
@@ -287,7 +284,7 @@ class LifeCycle {
}
}
#onQuit() {
#onQuit () {
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
@@ -319,7 +316,7 @@ class LifeCycle {
}
}
async launchApp() {
async launchApp () {
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()