Track bundled vendor runtime sources
This commit is contained in:
1295
vendor/aigcpanel/electron/mapi/file/index.ts
vendored
Normal file
1295
vendor/aigcpanel/electron/mapi/file/index.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
92
vendor/aigcpanel/electron/mapi/file/main.ts
vendored
Normal file
92
vendor/aigcpanel/electron/mapi/file/main.ts
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import { dialog, ipcMain } from "electron";
|
||||
import fileIndex from "./index";
|
||||
|
||||
ipcMain.handle(
|
||||
"file:openFile",
|
||||
async (
|
||||
event,
|
||||
options: {
|
||||
filters?: {
|
||||
name: string;
|
||||
extensions: string[];
|
||||
}[];
|
||||
properties?: ("multiSelections" | "openFile")[];
|
||||
} = {},
|
||||
): Promise<string | string[] | null> => {
|
||||
options = Object.assign(
|
||||
{
|
||||
filters: [],
|
||||
properties: [],
|
||||
},
|
||||
options,
|
||||
);
|
||||
if (!options.properties.includes("openFile")) {
|
||||
options.properties.push("openFile");
|
||||
}
|
||||
// @ts-ignore
|
||||
options.properties.push("noResolveAliases");
|
||||
const res = await dialog
|
||||
.showOpenDialog({
|
||||
...options,
|
||||
})
|
||||
.catch((e) => {});
|
||||
if (!res || res.canceled) {
|
||||
return null;
|
||||
}
|
||||
if (options.properties.includes("multiSelections")) {
|
||||
return res.filePaths || null;
|
||||
}
|
||||
return res.filePaths?.[0] || null;
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
"file:openDirectory",
|
||||
async (_, options): Promise<string | null> => {
|
||||
const res = await dialog
|
||||
.showOpenDialog({
|
||||
properties: ["openDirectory"],
|
||||
...options,
|
||||
})
|
||||
.catch((e) => {});
|
||||
if (!res || res.canceled) {
|
||||
return null;
|
||||
}
|
||||
return res.filePaths?.[0] || null;
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle("file:openSave", async (_, options): Promise<string | null> => {
|
||||
const res = await dialog
|
||||
.showSaveDialog({
|
||||
...options,
|
||||
})
|
||||
.catch((e) => {});
|
||||
if (!res || res.canceled) {
|
||||
return null;
|
||||
}
|
||||
return res.filePath || null;
|
||||
});
|
||||
|
||||
const autoCleanTemp = async () => {
|
||||
fileIndex.autoCleanTemp(1).finally(() => {
|
||||
setTimeout(
|
||||
() => {
|
||||
autoCleanTemp();
|
||||
},
|
||||
10 * 60 * 1000,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
autoCleanTemp().then();
|
||||
}, 5000);
|
||||
|
||||
export default {
|
||||
...fileIndex,
|
||||
};
|
||||
|
||||
export const Files = {
|
||||
...fileIndex,
|
||||
};
|
||||
21
vendor/aigcpanel/electron/mapi/file/render.ts
vendored
Normal file
21
vendor/aigcpanel/electron/mapi/file/render.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import fileIndex from "./index";
|
||||
import { ipcRenderer } from "electron";
|
||||
|
||||
const openFile = async (options: {} = {}) => {
|
||||
return ipcRenderer.invoke("file:openFile", options);
|
||||
};
|
||||
|
||||
const openDirectory = async (options: {} = {}) => {
|
||||
return ipcRenderer.invoke("file:openDirectory", options);
|
||||
};
|
||||
|
||||
const openSave = async (options: {} = {}) => {
|
||||
return ipcRenderer.invoke("file:openSave", options);
|
||||
};
|
||||
|
||||
export default {
|
||||
...fileIndex,
|
||||
openFile,
|
||||
openDirectory,
|
||||
openSave,
|
||||
};
|
||||
Reference in New Issue
Block a user