Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/main/browsers/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default () => {
};

const init = (plugin, window: BrowserWindow) => {
if (view === null || view === undefined) {
if (view === null || view === undefined || view.inDetach) {
createView(plugin, window);
// if (viewInstance.getView(plugin.name) && !commonConst.dev()) {
// view = viewInstance.getView(plugin.name).view;
Expand Down Expand Up @@ -176,14 +176,29 @@ export default () => {
const removeView = (window: BrowserWindow) => {
if (!view) return;
executeHooks('PluginOut', null);
// 先记住这次要移除的视图,防止后面异步代码里全局引用被换掉
const snapshotView = view;
setTimeout(() => {
window.removeBrowserView(view);
if (!view.inDetach) {
window.setBrowserView(null);
view.webContents?.destroy();
// 获取当前视图,判断是否已经换成了新视图
const currentView = window.getBrowserView?.();
window.removeBrowserView(snapshotView);

// 主窗口的插件视图仍然挂着旧实例时,需要还原主窗口 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);
};

Expand Down