mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
force createTab to go through the queue as well (#1420)
This commit is contained in:
parent
00e3c4ec75
commit
925389fc70
@ -29,6 +29,17 @@ async function getClientId() {
|
|||||||
return cachedClientId;
|
return cachedClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TabSwitchQueueEntry =
|
||||||
|
| {
|
||||||
|
createTab: false;
|
||||||
|
tabId: string;
|
||||||
|
setInBackend: boolean;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
createTab: true;
|
||||||
|
pinned: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export class WaveBrowserWindow extends BaseWindow {
|
export class WaveBrowserWindow extends BaseWindow {
|
||||||
waveWindowId: string;
|
waveWindowId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
@ -37,7 +48,7 @@ export class WaveBrowserWindow extends BaseWindow {
|
|||||||
activeTabView: WaveTabView;
|
activeTabView: WaveTabView;
|
||||||
private canClose: boolean;
|
private canClose: boolean;
|
||||||
private deleteAllowed: boolean;
|
private deleteAllowed: boolean;
|
||||||
private tabSwitchQueue: { tabId: string; setInBackend: boolean }[];
|
private tabSwitchQueue: TabSwitchQueueEntry[];
|
||||||
|
|
||||||
constructor(waveWindow: WaveWindow, fullConfig: FullConfigType, opts: WindowOpts) {
|
constructor(waveWindow: WaveWindow, fullConfig: FullConfigType, opts: WindowOpts) {
|
||||||
console.log("create win", waveWindow.oid);
|
console.log("create win", waveWindow.oid);
|
||||||
@ -306,11 +317,6 @@ export class WaveBrowserWindow extends BaseWindow {
|
|||||||
await this.queueTabSwitch(tabId, setInBackend);
|
await this.queueTabSwitch(tabId, setInBackend);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTab(pinned = false) {
|
|
||||||
const tabId = await WorkspaceService.CreateTab(this.workspaceId, null, true, pinned);
|
|
||||||
await this.setActiveTab(tabId, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
async closeTab(tabId: string) {
|
async closeTab(tabId: string) {
|
||||||
console.log(`closeTab tabid=${tabId} ws=${this.workspaceId} window=${this.waveWindowId}`);
|
console.log(`closeTab tabid=${tabId} ws=${this.workspaceId} window=${this.waveWindowId}`);
|
||||||
const rtn = await WorkspaceService.CloseTab(this.workspaceId, tabId, true);
|
const rtn = await WorkspaceService.CloseTab(this.workspaceId, tabId, true);
|
||||||
@ -430,12 +436,20 @@ export class WaveBrowserWindow extends BaseWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async queueTabSwitch(tabId: string, setInBackend: boolean) {
|
async queueTabSwitch(tabId: string, setInBackend: boolean) {
|
||||||
|
await this._queueTabSwitchInternal({ createTab: false, tabId, setInBackend });
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueCreateTab(pinned = false) {
|
||||||
|
await this._queueTabSwitchInternal({ createTab: true, pinned });
|
||||||
|
}
|
||||||
|
|
||||||
|
async _queueTabSwitchInternal(entry: TabSwitchQueueEntry) {
|
||||||
if (this.tabSwitchQueue.length >= 2) {
|
if (this.tabSwitchQueue.length >= 2) {
|
||||||
this.tabSwitchQueue[1] = { tabId, setInBackend };
|
this.tabSwitchQueue[1] = entry;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const wasEmpty = this.tabSwitchQueue.length === 0;
|
const wasEmpty = this.tabSwitchQueue.length === 0;
|
||||||
this.tabSwitchQueue.push({ tabId, setInBackend });
|
this.tabSwitchQueue.push(entry);
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
await this.processTabSwitchQueue();
|
await this.processTabSwitchQueue();
|
||||||
}
|
}
|
||||||
@ -450,13 +464,25 @@ export class WaveBrowserWindow extends BaseWindow {
|
|||||||
async processTabSwitchQueue() {
|
async processTabSwitchQueue() {
|
||||||
while (this.tabSwitchQueue.length > 0) {
|
while (this.tabSwitchQueue.length > 0) {
|
||||||
try {
|
try {
|
||||||
const { tabId, setInBackend } = this.tabSwitchQueue[0];
|
const entry = this.tabSwitchQueue[0];
|
||||||
|
let tabId: string = null;
|
||||||
|
// have to use "===" here to get the typechecker to work :/
|
||||||
|
if (entry.createTab === true) {
|
||||||
|
const { pinned } = entry;
|
||||||
|
tabId = await WorkspaceService.CreateTab(this.workspaceId, null, true, pinned);
|
||||||
|
} else if (entry.createTab === false) {
|
||||||
|
let setInBackend: boolean = false;
|
||||||
|
({ tabId, setInBackend } = entry);
|
||||||
if (this.activeTabView?.waveTabId == tabId) {
|
if (this.activeTabView?.waveTabId == tabId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (setInBackend) {
|
if (setInBackend) {
|
||||||
await WorkspaceService.SetActiveTab(this.workspaceId, tabId);
|
await WorkspaceService.SetActiveTab(this.workspaceId, tabId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (tabId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const [tabView, tabInitialized] = await getOrCreateWebViewForTab(tabId);
|
const [tabView, tabInitialized] = await getOrCreateWebViewForTab(tabId);
|
||||||
await this.setTabViewIntoWindow(tabView, tabInitialized);
|
await this.setTabViewIntoWindow(tabView, tabInitialized);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -558,7 +584,7 @@ ipcMain.on("create-tab", async (event, opts) => {
|
|||||||
const senderWc = event.sender;
|
const senderWc = event.sender;
|
||||||
const ww = getWaveWindowByWebContentsId(senderWc.id);
|
const ww = getWaveWindowByWebContentsId(senderWc.id);
|
||||||
if (ww != null) {
|
if (ww != null) {
|
||||||
await ww.createTab();
|
await ww.queueCreateTab();
|
||||||
}
|
}
|
||||||
event.returnValue = true;
|
event.returnValue = true;
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user