mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-18 08:44:16 +08:00
✨ 支持 template 模板 list 模式
This commit is contained in:
@@ -3,6 +3,21 @@ import path from "path";
|
||||
import commonConst from "../../common/utils/commonConst";
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main";
|
||||
|
||||
const getPreloadPath = (plugin, pluginIndexPath) => {
|
||||
const { name, preload, tplPath, indexPath } = plugin;
|
||||
if (commonConst.dev()) {
|
||||
if (name === "rubick-system-feature") {
|
||||
return path.resolve(__static, `../feature/public/preload.js`);
|
||||
}
|
||||
if (tplPath) {
|
||||
return path.resolve(indexPath.replace("file:", ""), `./`, preload);
|
||||
}
|
||||
return path.resolve(pluginIndexPath.replace("file:", ""), `../`, preload);
|
||||
}
|
||||
|
||||
return path.resolve(pluginIndexPath.replace("file:", ""), `../`, preload);
|
||||
};
|
||||
|
||||
export default () => {
|
||||
let view;
|
||||
|
||||
@@ -13,19 +28,12 @@ export default () => {
|
||||
};
|
||||
|
||||
const createView = (plugin, window: BrowserWindow) => {
|
||||
let pluginIndexPath = plugin.indexPath;
|
||||
let pluginIndexPath = plugin.tplPath || plugin.indexPath;
|
||||
if (!pluginIndexPath) {
|
||||
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
|
||||
pluginIndexPath = `file://${path.join(pluginPath, "./", plugin.main)}`;
|
||||
}
|
||||
const preload =
|
||||
commonConst.dev() && plugin.name === "rubick-system-feature"
|
||||
? path.resolve(__static, `../feature/public/preload.js`)
|
||||
: path.resolve(
|
||||
pluginIndexPath.replace("file:", ""),
|
||||
`../`,
|
||||
plugin.preload
|
||||
);
|
||||
const preload = getPreloadPath(plugin, pluginIndexPath);
|
||||
|
||||
const ses = session.fromPartition("<" + plugin.name + ">");
|
||||
ses.setPreloads([`${__static}/preload.js`]);
|
||||
@@ -44,10 +52,10 @@ export default () => {
|
||||
});
|
||||
window.setBrowserView(view);
|
||||
view.webContents.loadURL(pluginIndexPath);
|
||||
window.once("ready-to-show", () => {
|
||||
view.webContents.once("dom-ready", () => {
|
||||
window.setSize(800, 660);
|
||||
view.setBounds({ x: 0, y: 60, width: 800, height: 600 });
|
||||
view.setAutoResize({ width: true });
|
||||
window.setSize(800, 660);
|
||||
commonConst.dev() && view.webContents.openDevTools();
|
||||
executeHooks("PluginEnter", plugin.ext);
|
||||
executeHooks("PluginReady", plugin.ext);
|
||||
|
||||
Reference in New Issue
Block a user