mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-29 01:02:47 +08:00
commit
4b8f0e4657
@ -5,18 +5,18 @@ import { WINDOW_MIN_HEIGHT } from '@/common/constans/common';
|
|||||||
export default () => {
|
export default () => {
|
||||||
let win: any;
|
let win: any;
|
||||||
|
|
||||||
const init = (pluginInfo, viewInfo, view) => {
|
const init = async (pluginInfo, viewInfo, view) => {
|
||||||
ipcMain.on('detach:service', async (event, arg: { type: string }) => {
|
ipcMain.on('detach:service', async (event, arg: { type: string }) => {
|
||||||
const data = await operation[arg.type]();
|
const data = await operation[arg.type]();
|
||||||
event.returnValue = data;
|
event.returnValue = data;
|
||||||
});
|
});
|
||||||
createWindow(pluginInfo, viewInfo, view);
|
const createWin = await createWindow(pluginInfo, viewInfo, view);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
require('@electron/remote/main').enable(win.webContents);
|
require('@electron/remote/main').enable(createWin.webContents);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createWindow = async (pluginInfo, viewInfo, view) => {
|
const createWindow = async (pluginInfo, viewInfo, view) => {
|
||||||
win = new BrowserWindow({
|
const createWin = new BrowserWindow({
|
||||||
height: viewInfo.height,
|
height: viewInfo.height,
|
||||||
minHeight: WINDOW_MIN_HEIGHT,
|
minHeight: WINDOW_MIN_HEIGHT,
|
||||||
width: viewInfo.width,
|
width: viewInfo.width,
|
||||||
@ -43,29 +43,32 @@ export default () => {
|
|||||||
});
|
});
|
||||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||||
// Load the url of the dev server if in development mode
|
// Load the url of the dev server if in development mode
|
||||||
win.loadURL('http://localhost:8082');
|
createWin.loadURL('http://localhost:8082');
|
||||||
} else {
|
} else {
|
||||||
win.loadURL(`file://${path.join(__static, './detach/index.html')}`);
|
createWin.loadURL(`file://${path.join(__static, './detach/index.html')}`);
|
||||||
}
|
}
|
||||||
win.on('close', () => {
|
createWin.on('close', () => {
|
||||||
executeHooks('PluginOut', null);
|
executeHooks('PluginOut', null);
|
||||||
});
|
});
|
||||||
win.on('closed', () => {
|
createWin.on('closed', () => {
|
||||||
win = undefined;
|
win = undefined;
|
||||||
});
|
});
|
||||||
|
createWin.on('focus', () => {
|
||||||
|
win = createWin;
|
||||||
|
});
|
||||||
|
|
||||||
win.once('ready-to-show', async () => {
|
createWin.once('ready-to-show', async () => {
|
||||||
const config = await localConfig.getConfig();
|
const config = await localConfig.getConfig();
|
||||||
const darkMode = config.perf.common.darkMode;
|
const darkMode = config.perf.common.darkMode;
|
||||||
darkMode &&
|
darkMode &&
|
||||||
win.webContents.executeJavaScript(
|
createWin.webContents.executeJavaScript(
|
||||||
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
||||||
);
|
);
|
||||||
win.setBrowserView(view);
|
createWin.setBrowserView(view);
|
||||||
win.webContents.executeJavaScript(
|
createWin.webContents.executeJavaScript(
|
||||||
`window.initDetach(${JSON.stringify(pluginInfo)})`
|
`window.initDetach(${JSON.stringify(pluginInfo)})`
|
||||||
);
|
);
|
||||||
win.show();
|
createWin.show();
|
||||||
});
|
});
|
||||||
const executeHooks = (hook, data) => {
|
const executeHooks = (hook, data) => {
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
@ -77,6 +80,7 @@ export default () => {
|
|||||||
`;
|
`;
|
||||||
view.webContents.executeJavaScript(evalJs);
|
view.webContents.executeJavaScript(evalJs);
|
||||||
};
|
};
|
||||||
|
return createWin;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWindow = () => win;
|
const getWindow = () => win;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user