Skip to content

Commit 884884f

Browse files
authored
update emain-window to do repositioning in a simpler way (#3087)
the old way doesn't buy us anything, so we should just do it in a straightforward way.
1 parent 9bcf1cd commit 884884f

File tree

2 files changed

+14
-43
lines changed

2 files changed

+14
-43
lines changed

electron.vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default defineConfig({
161161
"**/*.md",
162162
"**/*.mdx",
163163
"**/*.json",
164-
"emain/**",
164+
"**/emain/**",
165165
"**/*.txt",
166166
"**/*.log",
167167
],

emain/emain-window.ts

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export function calculateWindowBounds(
4040
): { x: number; y: number; width: number; height: number } {
4141
let winWidth = winSize?.width;
4242
let winHeight = winSize?.height;
43-
let winPosX = pos?.x ?? 100;
44-
let winPosY = pos?.y ?? 100;
43+
const winPosX = pos?.x ?? 100;
44+
const winPosY = pos?.y ?? 100;
4545

4646
if (
4747
(winWidth == null || winWidth === 0 || winHeight == null || winHeight === 0) &&
@@ -86,7 +86,7 @@ export function calculateWindowBounds(
8686
winWidth = Math.max(winWidth, MinWindowWidth);
8787
winHeight = Math.max(winHeight, MinWindowHeight);
8888

89-
let winBounds = {
89+
const winBounds = {
9090
x: winPosX,
9191
y: winPosY,
9292
width: winWidth,
@@ -393,6 +393,8 @@ export class WaveBrowserWindow extends BaseWindow {
393393
private async initializeTab(tabView: WaveTabView, primaryStartupTab: boolean) {
394394
const clientId = await getClientId();
395395
await this.awaitWithDevTimeout(tabView.initPromise, "initPromise", tabView.waveTabId);
396+
const winBounds = this.getContentBounds();
397+
tabView.setBounds({ x: 0, y: 0, width: winBounds.width, height: winBounds.height });
396398
this.contentView.addChildView(tabView);
397399
const initOpts: WaveInitOpts = {
398400
tabId: tabView.waveTabId,
@@ -406,7 +408,7 @@ export class WaveBrowserWindow extends BaseWindow {
406408
tabView.savedInitOpts = { ...initOpts };
407409
tabView.savedInitOpts.activate = false;
408410
delete tabView.savedInitOpts.primaryTabStartup;
409-
let startTime = Date.now();
411+
const startTime = Date.now();
410412
console.log(
411413
"before wave ready, init tab, sending wave-init",
412414
tabView.waveTabId,
@@ -456,14 +458,12 @@ export class WaveBrowserWindow extends BaseWindow {
456458
this.allLoadedTabViews.set(tabView.waveTabId, tabView);
457459
if (!tabInitialized) {
458460
console.log("initializing a new tab", primaryStartupTab ? "(primary startup)" : "");
459-
const p1 = this.initializeTab(tabView, primaryStartupTab);
460-
const p2 = this.repositionTabsSlowly(100);
461-
await Promise.all([p1, p2]);
461+
await this.initializeTab(tabView, primaryStartupTab);
462+
this.finalizePositioning();
462463
} else {
463464
console.log("reusing an existing tab, calling wave-init", tabView.waveTabId);
464-
const p1 = this.repositionTabsSlowly(35);
465-
const p2 = tabView.webContents.send("wave-init", tabView.savedInitOpts); // reinit
466-
await Promise.all([p1, p2]);
465+
tabView.webContents.send("wave-init", tabView.savedInitOpts); // reinit
466+
this.finalizePositioning();
467467
}
468468

469469
// something is causing the new tab to lose focus so it requires manual refocusing
@@ -480,35 +480,6 @@ export class WaveBrowserWindow extends BaseWindow {
480480
}, 30);
481481
}
482482

483-
private async repositionTabsSlowly(delayMs: number) {
484-
const activeTabView = this.activeTabView;
485-
const winBounds = this.getContentBounds();
486-
if (activeTabView == null) {
487-
return;
488-
}
489-
if (activeTabView.isOnScreen()) {
490-
activeTabView.setBounds({
491-
x: 0,
492-
y: 0,
493-
width: winBounds.width,
494-
height: winBounds.height,
495-
});
496-
} else {
497-
activeTabView.setBounds({
498-
x: winBounds.width - 10,
499-
y: winBounds.height - 10,
500-
width: winBounds.width,
501-
height: winBounds.height,
502-
});
503-
}
504-
await delay(delayMs);
505-
if (this.activeTabView != activeTabView) {
506-
// another tab view has been set, do not finalize this layout
507-
return;
508-
}
509-
this.finalizePositioning();
510-
}
511-
512483
private finalizePositioning() {
513484
if (this.isDestroyed()) {
514485
return;
@@ -546,7 +517,7 @@ export class WaveBrowserWindow extends BaseWindow {
546517
private removeTabViewLater(tabId: string, delayMs: number) {
547518
setTimeout(() => {
548519
this.removeTabView(tabId, false);
549-
}, 1000);
520+
}, delayMs);
550521
}
551522

552523
// the queue and this function are used to serialize operations that update the window contents view
@@ -744,7 +715,7 @@ ipcMain.on("set-active-tab", async (event, tabId) => {
744715
await ww?.setActiveTab(tabId, true);
745716
});
746717

747-
ipcMain.on("create-tab", async (event, opts) => {
718+
ipcMain.on("create-tab", async (event, _opts) => {
748719
const senderWc = event.sender;
749720
const ww = getWaveWindowByWebContentsId(senderWc.id);
750721
if (ww != null) {
@@ -818,7 +789,7 @@ ipcMain.on("delete-workspace", (event, workspaceId) => {
818789

819790
const workspaceList = await WorkspaceService.ListWorkspaces();
820791

821-
const workspaceHasWindow = !!workspaceList.find((wse) => wse.workspaceid === workspaceId)?.windowid;
792+
const _workspaceHasWindow = !!workspaceList.find((wse) => wse.workspaceid === workspaceId)?.windowid;
822793

823794
const choice = dialog.showMessageBoxSync(this, {
824795
type: "question",

0 commit comments

Comments
 (0)