2025-04-29 18:36:29 +08:00
|
|
|
|
// See the Electron documentation for details on how to use preload scripts:
|
|
|
|
|
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
|
|
|
|
|
|
|
|
|
|
import { contextBridge, ipcRenderer } from 'electron';
|
2025-05-17 21:34:19 +08:00
|
|
|
|
import { ApiResponse, MenuItem, TagResolutionConfig } from './EIAC_Desktop_Api';
|
2025-04-29 18:36:29 +08:00
|
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld('electronAPI', {
|
2025-05-17 21:34:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取菜单缓存
|
|
|
|
|
* @returns 菜单缓存
|
|
|
|
|
*/
|
|
|
|
|
getMenuCacheAsync: () => ipcRenderer.invoke('get-menu-cache') as Promise<ApiResponse<MenuItem[]>>,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取配置缓存
|
|
|
|
|
* @returns 配置缓存
|
|
|
|
|
*/
|
|
|
|
|
getConfigCacheAsync: () => ipcRenderer.invoke('get-config-cache') as Promise<ApiResponse<TagResolutionConfig[]>>,
|
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 在新标签页打开URL
|
|
|
|
|
* @param callback 回调函数,参数为webContentId和url。其中webContentId是请求打开URL的webview的id。
|
|
|
|
|
*/
|
2025-05-12 01:41:53 +08:00
|
|
|
|
onOpenTab: (callback: (webContentId: number, url: string) => void) => {
|
|
|
|
|
ipcRenderer.on('webview-new-window', (_event, webContentId, url) => callback(webContentId, url));
|
|
|
|
|
},
|
2025-05-12 23:41:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取当前屏幕的缩放比例和分辨率
|
|
|
|
|
* @returns 缩放比例和分辨率
|
|
|
|
|
*/
|
|
|
|
|
getPrimaryDisplay: () => ipcRenderer.invoke('get-primary-display') as Promise<Electron.Display>,
|
2025-05-12 23:41:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 检查URL是否可用
|
|
|
|
|
* @param url 要检查的URL
|
|
|
|
|
* @returns 是否可用
|
|
|
|
|
*/
|
2025-04-30 23:09:05 +08:00
|
|
|
|
checkUrlAvailable: (url: string) => ipcRenderer.invoke('check-url-available', url),
|
2025-04-30 23:31:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 设置webview的cookie
|
|
|
|
|
* @param url 要设置cookie的URL
|
|
|
|
|
* @param cookie cookie字符串
|
|
|
|
|
*/
|
2025-04-30 23:31:36 +08:00
|
|
|
|
setWebviewCookie: (url: string, cookie: string) => ipcRenderer.invoke('set-webview-cookie', url, cookie),
|
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 按键将值设置到sessionStorage
|
|
|
|
|
* @param key 键
|
|
|
|
|
* @param value 值
|
|
|
|
|
*/
|
2025-04-30 23:09:05 +08:00
|
|
|
|
setSessionStorage: (key: string, value: string) => {
|
|
|
|
|
window.sessionStorage.setItem(key, value);
|
|
|
|
|
},
|
2025-04-30 23:31:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 从sessionStorage中获取指定键的值
|
|
|
|
|
* @param key 键
|
|
|
|
|
* @returns 值
|
|
|
|
|
*/
|
2025-04-30 23:09:05 +08:00
|
|
|
|
getSessionStorage: (key: string) => {
|
|
|
|
|
return window.sessionStorage.getItem(key);
|
|
|
|
|
},
|
2025-04-30 23:31:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 从sessionStorage中删除指定键的值
|
|
|
|
|
* @param key 键
|
|
|
|
|
*/
|
2025-04-30 23:09:05 +08:00
|
|
|
|
removeSessionStorage: (key: string) => {
|
|
|
|
|
window.sessionStorage.removeItem(key);
|
2025-04-30 17:28:03 +08:00
|
|
|
|
},
|
2025-04-30 23:31:36 +08:00
|
|
|
|
|
2025-05-17 20:42:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 清空sessionStorage
|
|
|
|
|
*/
|
2025-04-30 23:09:05 +08:00
|
|
|
|
clearSessionStorage: () => {
|
|
|
|
|
window.sessionStorage.clear();
|
|
|
|
|
}
|
2025-05-12 01:41:53 +08:00
|
|
|
|
});
|