mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-18 00:34:19 +08:00
fix-detach
This commit is contained in:
@@ -82,7 +82,7 @@ export default () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const init = (plugin, window: BrowserWindow) => {
|
const init = (plugin, window: BrowserWindow) => {
|
||||||
if (view === null || view === undefined) {
|
if (view === null || view === undefined || view.inDetach) {
|
||||||
createView(plugin, window);
|
createView(plugin, window);
|
||||||
// if (viewInstance.getView(plugin.name) && !commonConst.dev()) {
|
// if (viewInstance.getView(plugin.name) && !commonConst.dev()) {
|
||||||
// view = viewInstance.getView(plugin.name).view;
|
// view = viewInstance.getView(plugin.name).view;
|
||||||
@@ -176,14 +176,29 @@ export default () => {
|
|||||||
const removeView = (window: BrowserWindow) => {
|
const removeView = (window: BrowserWindow) => {
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
executeHooks('PluginOut', null);
|
executeHooks('PluginOut', null);
|
||||||
|
// 先记住这次要移除的视图,防止后面异步代码里全局引用被换掉
|
||||||
|
const snapshotView = view;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.removeBrowserView(view);
|
// 获取当前视图,判断是否已经换成了新视图
|
||||||
if (!view.inDetach) {
|
const currentView = window.getBrowserView?.();
|
||||||
window.setBrowserView(null);
|
window.removeBrowserView(snapshotView);
|
||||||
view.webContents?.destroy();
|
|
||||||
|
// 主窗口的插件视图仍然挂着旧实例时,需要还原主窗口 UI
|
||||||
|
if (!snapshotView.inDetach) {
|
||||||
|
// 如果窗口还挂着旧视图,说明还没换掉,需要把主窗口恢复到初始状态
|
||||||
|
if (currentView === snapshotView) {
|
||||||
|
window.setBrowserView(null);
|
||||||
|
if (view === snapshotView) {
|
||||||
|
window.webContents?.executeJavaScript(`window.initRubick()`);
|
||||||
|
view = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snapshotView.webContents?.destroy();
|
||||||
|
}
|
||||||
|
// 分离窗口只需释放全局引用,视图由分离窗口继续管理
|
||||||
|
else if (view === snapshotView) {
|
||||||
|
view = undefined;
|
||||||
}
|
}
|
||||||
window.webContents?.executeJavaScript(`window.initRubick()`);
|
|
||||||
view = undefined;
|
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user