This commit is contained in:
2026-03-25 22:59:31 +08:00
commit d391deb23b
81 changed files with 13012 additions and 0 deletions

23
src/preload/index.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
import { ElectronAPI } from '@electron-toolkit/preload'
import { settingsDto, checkIDEsResultDto } from '@my-type/settings'
import { checkIDEsVersionDto } from "../my-type/settings";
// 此处只有签名
declare global {
interface Window {
electron: ElectronAPI
api: {
_saveSettings: (settings: settingsDto) => Promise<boolean>
_updateSettings: () => Promise<settingsDto>
_openCodeLaunchpad: () => Promise<boolean>
_closeCodeLaunchpad: () => Promise<boolean>
}
codeLaunchpad: {
_getIDEs: () => Promise<checkIDEsResultDto>
_checkIDEs: () => Promise<checkIDEsResultDto>
_getIDEsVersion: () => Promise<checkIDEsVersionDto>
_checkIDEsVersion: () => Promise<checkIDEsVersionDto>
}
}
}

39
src/preload/index.ts Normal file
View File

@@ -0,0 +1,39 @@
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import { settingsDto } from '@my-type/settings'
// Custom APIs for renderer
// 在此添加新的进程间通信 API
const api = {
_saveSettings: (settings: settingsDto) => ipcRenderer.invoke('settings:save', settings),
_updateSettings: () => ipcRenderer.invoke('settings:update'),
_openCodeLaunchpad: () => ipcRenderer.invoke('tools:openCodeLaunchpad'),
_closeCodeLaunchpad: () => ipcRenderer.invoke('tools:closeCodeLaunchpad')
}
const codeLaunchpadApi = {
_getIDEs: () => ipcRenderer.invoke('codeLaunchpad:getIDEs'),
_checkIDEs: () => ipcRenderer.invoke('codeLaunchpad:checkIDEs'),
_getIDEsVersion: () => ipcRenderer.invoke('codeLaunchpad:getIDEsVersion'),
_checkIDEsVersion: () => ipcRenderer.invoke('codeLaunchpad:checkIDEsVersion')
}
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('electron', electronAPI)
contextBridge.exposeInMainWorld('api', api)
contextBridge.exposeInMainWorld('codeLaunchpad', codeLaunchpadApi)
} catch (error) {
console.error(error)
}
} else {
// @ts-ignore (define in dts)
window.electron = electronAPI
// @ts-ignore (define in dts)
window.api = api
// @ts-ignore (define in dts)
window.codeLaunchpad = codeLaunchpadApi
}