chore: tracking events for app tabs header (#7778)

fix AF-1194
This commit is contained in:
pengx17
2024-08-08 09:14:46 +00:00
parent 6ef5675be1
commit b71945c29f
4 changed files with 137 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import {
addTab,
closeTab,
reloadView,
type TabAction,
WebContentViewsManager,
} from './tab-views';
@@ -15,6 +16,8 @@ export const showTabContextMenu = async (tabId: string, viewIndex: number) => {
return;
}
const { resolve, promise } = Promise.withResolvers<TabAction | null>();
const template: Parameters<typeof Menu.buildFromTemplate>[0] = [
tabMeta.pinned
? {
@@ -90,4 +93,22 @@ export const showTabContextMenu = async (tabId: string, viewIndex: number) => {
];
const menu = Menu.buildFromTemplate(template);
menu.popup();
// eslint-disable-next-line prefer-const
let unsub: (() => void) | undefined;
const subscription = WebContentViewsManager.instance.tabAction$.subscribe(
action => {
resolve(action);
unsub?.();
}
);
menu.on('menu-will-close', () => {
setTimeout(() => {
resolve(null);
unsub?.();
});
});
unsub = () => {
subscription.unsubscribe();
};
return promise;
};

View File

@@ -108,7 +108,7 @@ type OpenInSplitViewAction = {
};
};
type TabAction =
export type TabAction =
| AddTabAction
| CloseTabAction
| PinTabAction