Feat(Electron-store): Add electron store

Add electron store to support install tool
This commit is contained in:
2024-05-08 12:36:16 +08:00
parent d677aeed07
commit 1ef2db5f47
9 changed files with 334 additions and 14 deletions

21
src/main/dataProcess.ts Normal file
View File

@@ -0,0 +1,21 @@
import Store, { Schema } from 'electron-store'
import { ipcMain } from 'electron'
const schema: Schema<StoreSchema> = {
installedTools: {
default: []
}
}
const store = new Store<StoreSchema>({ schema })
ipcMain.handle('store:installTool', (_, value: Record<string, Record<Platform, ToolVo>>) => {
const installedTools = store.get('installedTools')
store.set('installedTools', { ...installedTools, ...value })
return store.get('installedTools')
})
ipcMain.handle('store:getInstalledTool', () => {
return store.get('installedTools')
})

78
src/main/global.d.ts vendored
View File

@@ -11,3 +11,81 @@ interface ImportMetaEnv {
interface ImportMeta {
readonly env: ImportMetaEnv
}
interface StoreSchema {
installedTools: Record<string, Record<Platform, ToolVo>>
}
interface ToolVo {
id: string
name: string
toolId: string
icon: string
platform: Platform
description: string
base: ToolBaseVo
author: UserWithInfoVo
ver: string
keywords: string[]
categories: ToolCategoryVo[]
source: ToolDataVo
dist: ToolDataVo
entryPoint: string
publish: string
review: 'NONE' | 'PROCESSING' | 'PASS' | 'REJECT'
createTime: string
updateTime: string
favorite: boolean
}
interface ToolBaseVo {
id: string
name: string
source: ToolDataVo
dist: ToolDataVo
platform: Platform
compiled: boolean
createTime: string
updateTime: string
}
interface ToolDataVo {
id: string
data?: string
createTime?: string
updateTime?: string
}
interface UserWithInfoVo {
id: string
username: string
twoFactor: boolean
verified: boolean
locking: boolean
expiration: string
credentialsExpiration: string
enable: boolean
currentLoginTime: string
currentLoginIp: string
lastLoginTime: string
lastLoginIp: string
createTime: string
updateTime: string
userInfo: UserInfoVo
}
interface UserInfoVo {
id: string
userId: string
nickname: string
avatar: string
email: string
}
interface ToolCategoryVo {
id: string
name: string
enable: boolean
createTime: string
updateTime: string
}

View File

@@ -50,7 +50,7 @@ app.on('open-url', (_, argv) => {
handleUrl(argv)
})
function createWindow(): void {
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 900,
@@ -120,3 +120,4 @@ app.on('window-all-closed', () => {
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
import './dataProcess'

View File

@@ -1,8 +1,12 @@
import { contextBridge, Notification } from 'electron'
import { contextBridge, Notification, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
// Custom APIs for renderer
const api = {}
const api = {
installTool: (newTools: Record<string, Record<Platform, ToolVo>>) =>
ipcRenderer.invoke('store:installTool', newTools),
getInstalledTool: () => ipcRenderer.invoke('store:getInstalledTool')
}
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise

View File

@@ -1,8 +1,14 @@
import { ElectronAPI } from "@electron-toolkit/preload";
import { Notification } from "electron";
import { ElectronAPI } from '@electron-toolkit/preload'
import { Notification } from 'electron'
declare global {
type _ElectronAPI = ElectronAPI
type _ElectronAPI = ElectronAPI
class _Notification extends Notification {}
class _Notification extends Notification {}
interface API {
installTool: (
newTools: Record<string, Record<Platform, ToolVo>>
) => Promise<Record<string, Record<Platform, ToolVo>>>
}
}

View File

@@ -19,6 +19,7 @@ interface ImportMeta {
interface Window {
electronAPI: _ElectronAPI
Notification: typeof _Notification
api: API
}
interface RouteJsonObject {