[#237] Dispose plugins from main process
This commit is contained in:
parent
26f732d541
commit
29d8c30c3e
@ -184,6 +184,7 @@ function deleteDownloadModel(modelId: string) {
|
|||||||
const stmt = db.prepare("DELETE FROM models WHERE id = ?");
|
const stmt = db.prepare("DELETE FROM models WHERE id = ?");
|
||||||
stmt.run(modelId);
|
stmt.run(modelId);
|
||||||
stmt.finalize();
|
stmt.finalize();
|
||||||
|
res(modelId);
|
||||||
});
|
});
|
||||||
|
|
||||||
db.close();
|
db.close();
|
||||||
@ -352,7 +353,7 @@ function deleteConversation(id: any) {
|
|||||||
);
|
);
|
||||||
deleteMessages.run(id);
|
deleteMessages.run(id);
|
||||||
deleteMessages.finalize();
|
deleteMessages.finalize();
|
||||||
res([]);
|
res(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
db.close();
|
db.close();
|
||||||
|
|||||||
@ -5,14 +5,6 @@ const fs = require("fs");
|
|||||||
|
|
||||||
let subprocess = null;
|
let subprocess = null;
|
||||||
|
|
||||||
process.on("exit", () => {
|
|
||||||
// Perform cleanup tasks here
|
|
||||||
console.log("kill subprocess on exit");
|
|
||||||
if (subprocess) {
|
|
||||||
subprocess.kill();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function initModel(product) {
|
async function initModel(product) {
|
||||||
// fileName fallback
|
// fileName fallback
|
||||||
if (!product.fileName) {
|
if (!product.fileName) {
|
||||||
@ -79,7 +71,7 @@ async function initModel(product) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function killSubprocess() {
|
function dispose() {
|
||||||
if (subprocess) {
|
if (subprocess) {
|
||||||
subprocess.kill();
|
subprocess.kill();
|
||||||
subprocess = null;
|
subprocess = null;
|
||||||
@ -91,5 +83,5 @@ function killSubprocess() {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
initModel,
|
initModel,
|
||||||
killSubprocess,
|
dispose,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,15 +4,15 @@ import { resolve, join, extname } from "path";
|
|||||||
import { rmdir, unlink, createWriteStream } from "fs";
|
import { rmdir, unlink, createWriteStream } from "fs";
|
||||||
import { init } from "./core/plugin-manager/pluginMgr";
|
import { init } from "./core/plugin-manager/pluginMgr";
|
||||||
import { setupMenu } from "./utils/menu";
|
import { setupMenu } from "./utils/menu";
|
||||||
|
import { dispose } from "./utils/disposable";
|
||||||
|
|
||||||
import isDev = require("electron-is-dev");
|
const isDev = require("electron-is-dev");
|
||||||
// @ts-ignore
|
const request = require("request");
|
||||||
import request = require("request");
|
const progress = require("request-progress");
|
||||||
// @ts-ignore
|
|
||||||
import progress = require("request-progress");
|
|
||||||
const { autoUpdater } = require("electron-updater");
|
const { autoUpdater } = require("electron-updater");
|
||||||
const Store = require("electron-store");
|
const Store = require("electron-store");
|
||||||
|
|
||||||
|
const requiredModules: Record<string, any> = {};
|
||||||
let mainWindow: BrowserWindow | undefined = undefined;
|
let mainWindow: BrowserWindow | undefined = undefined;
|
||||||
|
|
||||||
app
|
app
|
||||||
@ -32,6 +32,7 @@ app
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
|
dispose(requiredModules);
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -106,22 +107,22 @@ function handleIPCs() {
|
|||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
"invokePluginFunc",
|
"invokePluginFunc",
|
||||||
async (_event, modulePath, method, ...args) => {
|
async (_event, modulePath, method, ...args) => {
|
||||||
const module = join(app.getPath("userData"), "plugins", modulePath);
|
const module = require(/* webpackIgnore: true */ join(
|
||||||
return await import(/* webpackIgnore: true */ module)
|
app.getPath("userData"),
|
||||||
.then((plugin) => {
|
"plugins",
|
||||||
if (typeof plugin[method] === "function") {
|
modulePath
|
||||||
return plugin[method](...args);
|
));
|
||||||
} else {
|
requiredModules[modulePath] = module;
|
||||||
console.log(plugin[method]);
|
|
||||||
console.error(`Function "${method}" does not exist in the module.`);
|
if (typeof module[method] === "function") {
|
||||||
}
|
return module[method](...args);
|
||||||
})
|
} else {
|
||||||
.then((res) => {
|
console.log(module[method]);
|
||||||
return res;
|
console.error(`Function "${method}" does not exist in the module.`);
|
||||||
})
|
}
|
||||||
.catch((err) => console.log(err));
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.handle("basePlugins", async (_event) => {
|
ipcMain.handle("basePlugins", async (_event) => {
|
||||||
const basePluginPath = join(
|
const basePluginPath = join(
|
||||||
__dirname,
|
__dirname,
|
||||||
|
|||||||
8
electron/utils/disposable.ts
Normal file
8
electron/utils/disposable.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export function dispose(requiredModules: Record<string, any>) {
|
||||||
|
for (const key in requiredModules) {
|
||||||
|
const module = requiredModules[key];
|
||||||
|
if (typeof module["dispose"] === "function") {
|
||||||
|
module["dispose"]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user