🚧 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,10 +1,8 @@
/* eslint-disable camelcase */
import { ipcRenderer } from 'electron'
import { TALKING_DATA_APPID, TALKING_DATA_EVENT } from '#/events/constants'
import pkg from 'root/package.json'
import { handleTalkingDataEvent } from '@/utils/common'
import pkg from 'root/package.json'
import { TALKING_DATA_APPID, TALKING_DATA_EVENT } from '#/events/constants'
import { ITalkingDataOptions } from '#/types/types'
const { version } = pkg
@@ -19,6 +17,6 @@ export const initTalkingData = () => {
}, 0)
}
ipcRenderer.on(TALKING_DATA_EVENT, (_, data: ITalkingDataOptions) => {
window.electron.ipcRendererOn(TALKING_DATA_EVENT, (_, data: ITalkingDataOptions) => {
handleTalkingDataEvent(data)
})

View File

@@ -1,6 +1,8 @@
import mitt from 'mitt'
import { SHOW_INPUT_BOX, SHOW_INPUT_BOX_RESPONSE } from '#/events/constants'
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type IEvent = {
[SHOW_INPUT_BOX_RESPONSE]: string
[SHOW_INPUT_BOX]: {

View File

@@ -1,8 +1,6 @@
import { ipcRenderer } from 'electron'
import { isReactive, isRef, toRaw, unref } from 'vue'
import { RPC_ACTIONS, RPC_ACTIONS_INVOKE } from '#/events/constants'
import { IRPCActionType } from '#/types/enum'
import { ITalkingDataOptions } from '#/types/types'
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
try {
@@ -30,20 +28,3 @@ export const getRawData = (args: any): any => {
}
return args
}
export function sendToMain(channel: string, ...args: any[]) {
const data = getRawData(args)
ipcRenderer.send(channel, ...data)
}
export function sendRPC(action: IRPCActionType, ...args: any[]): void {
ipcRenderer.send(RPC_ACTIONS, action, getRawData(args))
}
export function sendRpcSync(action: IRPCActionType, ...args: any[]) {
return ipcRenderer.sendSync(RPC_ACTIONS, action, getRawData(args))
}
export async function triggerRPC<T>(action: IRPCActionType, ...args: any[]): Promise<T | undefined> {
return await ipcRenderer.invoke(RPC_ACTIONS_INVOKE, action, getRawData(args))
}

View File

@@ -1,19 +1,12 @@
import { ipcRenderer } from 'electron'
import { sendRPC, triggerRPC } from '@/utils/common'
import { RPC_ACTIONS } from '#/events/constants'
import { IRPCActionType } from 'root/src/universal/types/enum'
export function saveConfig(config: IObj | string, value?: any) {
import { IObj } from '#/types/types'
export function saveConfig (config: IObj | string, value?: any) {
const configObject = typeof config === 'string' ? { [config]: value } : config
sendRPC(IRPCActionType.PICLIST_SAVE_CONFIG, configObject)
window.electron.sendRPC(IRPCActionType.PICLIST_SAVE_CONFIG, configObject)
}
export async function getConfig<T>(key?: string): Promise<T | undefined> {
return await triggerRPC<T>(IRPCActionType.PICLIST_GET_CONFIG, key)
}
export async function getConfigSync<T>(key?: string): Promise<T | undefined> {
return await ipcRenderer.sendSync(RPC_ACTIONS, IRPCActionType.PICLIST_GET_CONFIG_SYNC, [key])
export async function getConfig<T> (key?: string): Promise<T | undefined> {
return await window.electron.triggerRPC<T>(IRPCActionType.PICLIST_GET_CONFIG, key)
}

View File

@@ -1,13 +1,30 @@
import { IObject, IResult, IGetResult, IFilter } from '@picgo/store/dist/types'
import { triggerRPC } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
import { IGalleryDB } from '#/types/extra-vue'
interface IFilter {
orderBy?: 'asc' | 'desc'
limit?: number
offset?: number
}
interface IGetResult<T> {
total: number
data: IResult<T>[]
}
interface IObject {
id?: string
[propName: string]: any
}
type IResult<T> = T & {
id: string
createdAt: number
updatedAt: number
}
export class GalleryDB implements IGalleryDB {
async #actionHandler<T>(method: IRPCActionType, ...args: any[]): Promise<T | undefined> {
return await triggerRPC<T>(method, ...args)
return await window.electron.triggerRPC<T>(method, ...args)
}
async get<T>(filter?: IFilter): Promise<IGetResult<T> | undefined> {
@@ -22,7 +39,7 @@ export class GalleryDB implements IGalleryDB {
return await this.#actionHandler<IResult<T>[]>(IRPCActionType.GALLERY_INSERT_DB_BATCH, value)
}
async updateById(id: string, value: IObject): Promise<boolean> {
async updateById (id: string, value: IObject): Promise<boolean> {
return (await this.#actionHandler<boolean>(IRPCActionType.GALLERY_UPDATE_BY_ID_DB, id, value)) || false
}
@@ -30,7 +47,7 @@ export class GalleryDB implements IGalleryDB {
return await this.#actionHandler<IResult<T> | undefined>(IRPCActionType.GALLERY_GET_BY_ID_DB, id)
}
async removeById(id: string): Promise<void> {
async removeById (id: string): Promise<void> {
return await this.#actionHandler<void>(IRPCActionType.GALLERY_REMOVE_BY_ID_DB, id)
}
}

View File

@@ -1,15 +1,15 @@
import { onBeforeUnmount, onMounted } from 'vue'
function disableDrag(e: DragEvent) {
function disableDrag (e: DragEvent) {
const dropzone = document.getElementById('upload-area')
if (dropzone === null || !dropzone.contains(<Node>e.target)) {
if (dropzone === null || !dropzone.contains((e.target as Node))) {
e.preventDefault()
e.dataTransfer!.effectAllowed = 'none'
e.dataTransfer!.dropEffect = 'none'
}
}
export function useDragEventListeners() {
export function useDragEventListeners () {
onMounted(() => {
window.addEventListener('dragenter', disableDrag, false)
window.addEventListener('dragover', disableDrag)

View File

@@ -0,0 +1,19 @@
import { IStringKeyMap } from '#/types/types'
import { RELEASE_URL, RELEASE_URL_BACKUP } from '#/utils/static'
export const getLatestVersion = async (): Promise<string> => {
try {
const { data: normalList } = await window.node.axios.get(RELEASE_URL)
return normalList[0].name
} catch (err) {
console.error('Error fetching latest version: ', err)
try {
const { data } = await window.node.axios.get(`${RELEASE_URL_BACKUP}/latest.yml`)
const r = window.node.yaml.load(data) as IStringKeyMap
return r.version
} catch (err) {
console.error('Error fetching backup latest version: ', err)
return ''
}
}
}

View File

@@ -1,17 +1,20 @@
import { ref } from 'vue'
import { triggerRPC } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
const osGlobal = ref<string>(process.platform)
import { IRPCActionType } from '#/types/enum'
import { IPicBedType } from '#/types/types'
console.log('global.ts loaded', window.node.https)
const osGlobal = ref<string>(window.electron.sendRpcSync(IRPCActionType.GET_PLATFORM))
const picBedGlobal = ref<IPicBedType[]>([])
const pageReloadCount = ref(0)
async function updatePicBedGlobal() {
picBedGlobal.value = (await triggerRPC<IPicBedType[]>(IRPCActionType.MAIN_GET_PICBED))!
async function updatePicBedGlobal () {
picBedGlobal.value = (await window.electron.triggerRPC<IPicBedType[]>(IRPCActionType.MAIN_GET_PICBED))!
}
async function updatePageReloadCount() {
async function updatePageReloadCount () {
pageReloadCount.value++
}
export { osGlobal, pageReloadCount, picBedGlobal, updatePicBedGlobal, updatePageReloadCount }
export { osGlobal, pageReloadCount, picBedGlobal, updatePageReloadCount, updatePicBedGlobal }

View File

@@ -1,3 +1,5 @@
import { IRPCActionType } from '#/types/enum'
const isSpecialKey = (key: string) => {
const keyArr = ['Shift', 'Control', 'Alt', 'Meta']
@@ -5,7 +7,7 @@ const isSpecialKey = (key: string) => {
}
const keyBinding = (event: KeyboardEvent) => {
const meta = process.platform === 'darwin' ? 'Cmd' : 'Super'
const meta = window.electron.sendRpcSync(IRPCActionType.GET_PLATFORM) === 'darwin' ? 'Cmd' : 'Super'
const specialKey = {
Ctrl: event.ctrlKey,
Shift: event.shiftKey,