2025-04-15 10:50:26 +08:00
|
|
|
import type { BasePlatformAdapter } from "@/types/platform";
|
2025-06-11 15:26:06 +08:00
|
|
|
import { copyToClipboard, OpenURLWithBrowser } from ".";
|
2025-07-10 09:48:42 +08:00
|
|
|
import { Post } from "@/api/axiosRequest";
|
2025-04-15 10:50:26 +08:00
|
|
|
|
|
|
|
|
export interface WebPlatformAdapter extends BasePlatformAdapter {
|
|
|
|
|
// Add web-specific methods here
|
|
|
|
|
openFileDialog: (options: any) => Promise<string | string[] | null>;
|
2025-04-22 09:35:04 +08:00
|
|
|
metadata: (path: string, options: any) => Promise<Record<string, any>>;
|
2025-07-07 19:41:29 +08:00
|
|
|
error: (message: string) => void;
|
2025-10-13 16:43:29 +08:00
|
|
|
openLogDir: () => Promise<void>;
|
2025-10-23 16:48:13 +08:00
|
|
|
getCurrentWebviewWindow: () => Promise<any>;
|
|
|
|
|
getWindowTheme: () => Promise<string>;
|
|
|
|
|
setWindowTheme: (theme: string | null) => Promise<void>;
|
|
|
|
|
getAllWindows: () => Promise<any[]>;
|
2025-04-15 10:50:26 +08:00
|
|
|
}
|
2025-04-07 11:19:09 +08:00
|
|
|
|
|
|
|
|
// Create Web adapter functions
|
2025-04-15 08:55:06 +08:00
|
|
|
export const createWebAdapter = (): WebPlatformAdapter => {
|
2025-04-07 11:19:09 +08:00
|
|
|
return {
|
2025-04-15 10:50:26 +08:00
|
|
|
async commands(commandName, ...args) {
|
|
|
|
|
console.warn(
|
|
|
|
|
`Command "${commandName}" is not supported in web environment`,
|
|
|
|
|
args
|
|
|
|
|
);
|
|
|
|
|
return Promise.reject(new Error("Not supported in web environment"));
|
2025-04-10 16:03:38 +08:00
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async invokeBackend(command, args) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log(`Web mode simulated backend call: ${command}`, args);
|
|
|
|
|
// Implement web environment simulation logic or API calls here
|
2025-04-15 10:50:26 +08:00
|
|
|
return null as any;
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async setWindowSize(width, height) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log(`Web mode simulated window resize: ${width}x${height}`);
|
|
|
|
|
// No actual operation needed in web environment
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async hideWindow() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated window hide");
|
|
|
|
|
// No actual operation needed in web environment
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async showWindow() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated window show");
|
|
|
|
|
// No actual operation needed in web environment
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
convertFileSrc(path) {
|
2025-04-07 11:19:09 +08:00
|
|
|
return path;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async emitEvent(event, payload) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated event emit", event, payload);
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async listenEvent(event, _callback) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated event listen", event);
|
2025-06-10 17:26:19 +08:00
|
|
|
return () => {};
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async setAlwaysOnTop(isPinned) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated set always on top", isPinned);
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async checkScreenRecordingPermission() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated check screen recording permission");
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2025-07-07 19:41:29 +08:00
|
|
|
async checkMicrophonePermission() {
|
|
|
|
|
return false;
|
|
|
|
|
},
|
2025-07-10 09:48:42 +08:00
|
|
|
|
2025-07-07 19:41:29 +08:00
|
|
|
async requestMicrophonePermission() {
|
2025-07-10 09:48:42 +08:00
|
|
|
return false;
|
2025-07-07 19:41:29 +08:00
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
requestScreenRecordingPermission() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated request screen recording permission");
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getScreenshotableMonitors() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get screenshotable monitors");
|
|
|
|
|
return [];
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getScreenshotableWindows() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get screenshotable windows");
|
|
|
|
|
return [];
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async captureMonitorScreenshot(id) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated capture monitor screenshot", id);
|
|
|
|
|
return "";
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async captureWindowScreenshot(id) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated capture window screenshot", id);
|
|
|
|
|
return "";
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async openFileDialog(options) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated open file dialog", options);
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getFileMetadata(path) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get file metadata", path);
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getFileIcon(path, size) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get file icon", path, size);
|
|
|
|
|
return "";
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async checkUpdate() {
|
2025-04-07 11:19:09 +08:00
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async relaunchApp() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated relaunch app");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async listenThemeChanged() {
|
|
|
|
|
console.log("Web mode simulated theme change listener");
|
2025-06-10 17:26:19 +08:00
|
|
|
return () => {};
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async setWindowTheme(theme) {
|
|
|
|
|
console.log("Web mode simulated set window theme:", theme);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getWindowTheme() {
|
|
|
|
|
console.log("Web mode simulated get window theme");
|
2025-04-15 10:50:26 +08:00
|
|
|
return "light";
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async onThemeChanged(callback) {
|
|
|
|
|
console.log("Web mode simulated on theme changed", callback);
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getWindowByLabel(label) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get window by label:", label);
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async createWindow(label, options) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated create window:", label, options);
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async getAllWindows() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get all windows");
|
|
|
|
|
return [];
|
|
|
|
|
},
|
|
|
|
|
|
2025-10-23 16:48:13 +08:00
|
|
|
async getCurrentWebviewWindow() {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated get current window");
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async createWebviewWindow(label, options) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated create webview window:", label, options);
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async listenWindowEvent(event, _callback) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log("Web mode simulated listen window event:", event);
|
2025-06-10 17:26:19 +08:00
|
|
|
return () => {};
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
|
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
isTauri() {
|
2025-04-07 11:19:09 +08:00
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-10 17:26:19 +08:00
|
|
|
async openUrl(url) {
|
2025-04-07 11:19:09 +08:00
|
|
|
console.log(`Web mode opening URL: ${url}`);
|
2025-04-15 10:50:26 +08:00
|
|
|
window.open(url, "_blank");
|
2025-04-07 11:19:09 +08:00
|
|
|
},
|
2025-04-10 16:03:38 +08:00
|
|
|
|
|
|
|
|
isWindows10: async () => false,
|
2025-04-11 14:17:42 +08:00
|
|
|
|
2025-04-15 10:50:26 +08:00
|
|
|
async setShadow(enable) {
|
2025-04-16 11:19:23 +08:00
|
|
|
console.log("setShadow is not supported in web environment", enable);
|
2025-04-11 14:17:42 +08:00
|
|
|
return Promise.resolve();
|
|
|
|
|
},
|
2025-04-18 10:18:28 +08:00
|
|
|
|
2025-04-22 09:35:04 +08:00
|
|
|
async metadata(path, options = {}) {
|
2025-06-10 17:26:19 +08:00
|
|
|
console.log(
|
|
|
|
|
"metadata is not supported in web environment",
|
|
|
|
|
path,
|
|
|
|
|
options
|
|
|
|
|
);
|
2025-06-03 19:28:26 +08:00
|
|
|
return Promise.resolve({ isAbsolute: false });
|
2025-04-18 10:18:28 +08:00
|
|
|
},
|
2025-06-10 17:26:19 +08:00
|
|
|
|
|
|
|
|
async revealItemInDir(path) {
|
|
|
|
|
console.log("revealItemInDir is not supported in web environment", path);
|
|
|
|
|
},
|
2025-06-11 15:26:06 +08:00
|
|
|
|
2025-07-17 09:22:23 +08:00
|
|
|
async openSearchItem(data, formatUrl) {
|
2025-06-11 17:49:05 +08:00
|
|
|
if (data.type === "AI Assistant") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 09:22:23 +08:00
|
|
|
const url = (formatUrl && formatUrl(data)) || data.url;
|
|
|
|
|
if (url) {
|
|
|
|
|
return OpenURLWithBrowser(url);
|
2025-06-11 15:26:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data?.payload?.result?.value) {
|
|
|
|
|
return copyToClipboard(data.payload.result.value);
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-07-07 19:41:29 +08:00
|
|
|
|
|
|
|
|
error: console.error,
|
2025-07-10 09:48:42 +08:00
|
|
|
|
|
|
|
|
async searchMCPServers(_serverId, queryParams) {
|
|
|
|
|
const [error, res]: any = await Post(
|
2025-07-17 09:22:23 +08:00
|
|
|
`/mcp_server/_search?${queryParams?.join("&")}`,
|
|
|
|
|
undefined
|
2025-07-10 09:48:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error("_search", error);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
res?.hits?.hits?.map((item: any) => ({
|
|
|
|
|
...item,
|
|
|
|
|
id: item._source.id,
|
|
|
|
|
name: item._source.name,
|
|
|
|
|
})) || []
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async searchDataSources(_serverId, queryParams) {
|
|
|
|
|
const [error, res]: any = await Post(
|
2025-07-17 09:22:23 +08:00
|
|
|
`/datasource/_search?${queryParams?.join("&")}`,
|
|
|
|
|
undefined
|
2025-07-10 09:48:42 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error("_search", error);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
res?.hits?.hits?.map((item: any) => ({
|
|
|
|
|
...item,
|
|
|
|
|
id: item._source.id,
|
|
|
|
|
name: item._source.name,
|
|
|
|
|
})) || []
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async fetchAssistant(_serverId, queryParams) {
|
|
|
|
|
const [error, res]: any = await Post(
|
2025-07-17 09:22:23 +08:00
|
|
|
`/assistant/_search?${queryParams?.join("&")}`,
|
|
|
|
|
undefined
|
2025-07-10 09:48:42 +08:00
|
|
|
);
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error("_search", error);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
},
|
2025-08-02 11:14:56 +08:00
|
|
|
|
|
|
|
|
async getCurrentWindowLabel() {
|
|
|
|
|
return "web";
|
|
|
|
|
},
|
2025-10-23 16:48:13 +08:00
|
|
|
|
2025-10-13 16:43:29 +08:00
|
|
|
async openLogDir() {
|
|
|
|
|
console.log("openLogDir is not supported in web environment");
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
},
|
2025-04-07 11:19:09 +08:00
|
|
|
};
|
2025-04-15 10:50:26 +08:00
|
|
|
};
|