Skip to content

Commit 925389f

Browse files
authored
force createTab to go through the queue as well (#1420)
1 parent 00e3c4e commit 925389f

1 file changed

Lines changed: 40 additions & 14 deletions

File tree

emain/emain-window.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ async function getClientId() {
2929
return cachedClientId;
3030
}
3131

32+
type TabSwitchQueueEntry =
33+
| {
34+
createTab: false;
35+
tabId: string;
36+
setInBackend: boolean;
37+
}
38+
| {
39+
createTab: true;
40+
pinned: boolean;
41+
};
42+
3243
export class WaveBrowserWindow extends BaseWindow {
3344
waveWindowId: string;
3445
workspaceId: string;
@@ -37,7 +48,7 @@ export class WaveBrowserWindow extends BaseWindow {
3748
activeTabView: WaveTabView;
3849
private canClose: boolean;
3950
private deleteAllowed: boolean;
40-
private tabSwitchQueue: { tabId: string; setInBackend: boolean }[];
51+
private tabSwitchQueue: TabSwitchQueueEntry[];
4152

4253
constructor(waveWindow: WaveWindow, fullConfig: FullConfigType, opts: WindowOpts) {
4354
console.log("create win", waveWindow.oid);
@@ -306,11 +317,6 @@ export class WaveBrowserWindow extends BaseWindow {
306317
await this.queueTabSwitch(tabId, setInBackend);
307318
}
308319

309-
async createTab(pinned = false) {
310-
const tabId = await WorkspaceService.CreateTab(this.workspaceId, null, true, pinned);
311-
await this.setActiveTab(tabId, false);
312-
}
313-
314320
async closeTab(tabId: string) {
315321
console.log(`closeTab tabid=${tabId} ws=${this.workspaceId} window=${this.waveWindowId}`);
316322
const rtn = await WorkspaceService.CloseTab(this.workspaceId, tabId, true);
@@ -430,12 +436,20 @@ export class WaveBrowserWindow extends BaseWindow {
430436
}
431437

432438
async queueTabSwitch(tabId: string, setInBackend: boolean) {
439+
await this._queueTabSwitchInternal({ createTab: false, tabId, setInBackend });
440+
}
441+
442+
async queueCreateTab(pinned = false) {
443+
await this._queueTabSwitchInternal({ createTab: true, pinned });
444+
}
445+
446+
async _queueTabSwitchInternal(entry: TabSwitchQueueEntry) {
433447
if (this.tabSwitchQueue.length >= 2) {
434-
this.tabSwitchQueue[1] = { tabId, setInBackend };
448+
this.tabSwitchQueue[1] = entry;
435449
return;
436450
}
437451
const wasEmpty = this.tabSwitchQueue.length === 0;
438-
this.tabSwitchQueue.push({ tabId, setInBackend });
452+
this.tabSwitchQueue.push(entry);
439453
if (wasEmpty) {
440454
await this.processTabSwitchQueue();
441455
}
@@ -450,12 +464,24 @@ export class WaveBrowserWindow extends BaseWindow {
450464
async processTabSwitchQueue() {
451465
while (this.tabSwitchQueue.length > 0) {
452466
try {
453-
const { tabId, setInBackend } = this.tabSwitchQueue[0];
454-
if (this.activeTabView?.waveTabId == tabId) {
455-
continue;
467+
const entry = this.tabSwitchQueue[0];
468+
let tabId: string = null;
469+
// have to use "===" here to get the typechecker to work :/
470+
if (entry.createTab === true) {
471+
const { pinned } = entry;
472+
tabId = await WorkspaceService.CreateTab(this.workspaceId, null, true, pinned);
473+
} else if (entry.createTab === false) {
474+
let setInBackend: boolean = false;
475+
({ tabId, setInBackend } = entry);
476+
if (this.activeTabView?.waveTabId == tabId) {
477+
continue;
478+
}
479+
if (setInBackend) {
480+
await WorkspaceService.SetActiveTab(this.workspaceId, tabId);
481+
}
456482
}
457-
if (setInBackend) {
458-
await WorkspaceService.SetActiveTab(this.workspaceId, tabId);
483+
if (tabId == null) {
484+
return;
459485
}
460486
const [tabView, tabInitialized] = await getOrCreateWebViewForTab(tabId);
461487
await this.setTabViewIntoWindow(tabView, tabInitialized);
@@ -558,7 +584,7 @@ ipcMain.on("create-tab", async (event, opts) => {
558584
const senderWc = event.sender;
559585
const ww = getWaveWindowByWebContentsId(senderWc.id);
560586
if (ww != null) {
561-
await ww.createTab();
587+
await ww.queueCreateTab();
562588
}
563589
event.returnValue = true;
564590
return null;

0 commit comments

Comments
 (0)