diff --git a/changelog/index.html b/changelog/index.html index 275ff53..d37bf38 100644 --- a/changelog/index.html +++ b/changelog/index.html @@ -366,6 +366,7 @@
  • Support [a:z] character batches
  • Dark theme support
  • Improved the gathering of images in websites
  • +
  • The windows, in particular the Manager window, will now usually remember the size and position correctly.
  • Version 4.1 September 21, 2019

    diff --git a/lib/select.ts b/lib/select.ts index bfc1bc5..eb83520 100644 --- a/lib/select.ts +++ b/lib/select.ts @@ -9,7 +9,7 @@ import { donate, openPrefs, openUrls } from "./windowutils"; // eslint-disable-next-line no-unused-vars import { filters, FAST, Filter } from "./filters"; import { WindowStateTracker } from "./windowstatetracker"; -import { windows } from "./browser"; +import { windows, CHROME } from "./browser"; // eslint-disable-next-line no-unused-vars import { BaseItem } from "./item"; @@ -98,8 +98,11 @@ export async function select(links: BaseItem[], media: BaseItem[]) { type: "popup", }); const window = await windows.create(windowOptions); - tracker.track(window.id, null); + tracker.track(window.id); try { + if (!CHROME) { + windows.update(window.id, tracker.getOptions({})); + } const port = await Promise.race([ new Promise(resolve => Bus.oncePort("select", port => { resolve(port); diff --git a/lib/single.ts b/lib/single.ts index 4488715..a18ef81 100644 --- a/lib/single.ts +++ b/lib/single.ts @@ -6,7 +6,7 @@ import { Bus, Port } from "./bus"; import { WindowStateTracker } from "./windowstatetracker"; import { Promised, timeout } from "./util"; import { donate } from "./windowutils"; -import { windows } from "./browser"; +import { windows, CHROME } from "./browser"; // eslint-disable-next-line no-unused-vars import { BaseItem } from "./item"; @@ -21,8 +21,11 @@ export async function single(item: BaseItem | null) { type: "popup", }); const window = await windows.create(windowOptions); - tracker.track(window.id, null); + tracker.track(window.id); try { + if (!CHROME) { + windows.update(window.id, tracker.getOptions({})); + } const port: Port = await Promise.race([ new Promise(resolve => Bus.oncePort("single", port => { resolve(port); diff --git a/lib/windowstatetracker.ts b/lib/windowstatetracker.ts index 11e57c7..b6430cd 100644 --- a/lib/windowstatetracker.ts +++ b/lib/windowstatetracker.ts @@ -3,6 +3,8 @@ import { Prefs } from "./prefs"; import { windows } from "./browser"; +// eslint-disable-next-line no-unused-vars +import { Port } from "./bus"; const VALID_WINDOW_STATES = Object.freeze(new Set(["normal", "maximized"])); @@ -80,34 +82,48 @@ export class WindowStateTracker { if (!this.windowId) { return; } - const window = await windows.get(this.windowId); - if (!VALID_WINDOW_STATES.has(window.state)) { - return; + try { + const window = await windows.get(this.windowId); + if (!VALID_WINDOW_STATES.has(window.state)) { + return; + } + const previous = JSON.stringify(this); + this.width = window.width; + this.height = window.height; + this.left = window.left; + this.top = window.top; + this.state = window.state; + this.validate(); + if (previous === JSON.stringify(this)) { + // Nothing changed + return; + } + await this.save(); } - const previous = JSON.stringify(this); - this.width = window.width; - this.height = window.height; - this.left = window.left; - this.top = window.top; - this.state = window.state; - this.validate(); - if (previous === JSON.stringify(this)) { - // Nothing changed - return; + catch { + // ignored } - await this.save(); } - track(windowId: number, port: any) { + track(windowId: number, port?: Port) { if (port) { port.on("resized", this.update); + port.on("unload", e => this.finalize(e)); + port.on("disconnect", this.finalize.bind(this)); } this.windowId = windowId; } - async finalize() { + async finalize(state?: any) { + if (state) { + this.left = state.left; + this.top = state.top; + } await this.update(); this.windowId = 0; + if (state) { + await this.save(); + } } async save() { diff --git a/lib/windowutils.ts b/lib/windowutils.ts index 123629f..7b9b1da 100644 --- a/lib/windowutils.ts +++ b/lib/windowutils.ts @@ -1,7 +1,7 @@ "use strict"; // License: MIT -import { windows, tabs, runtime } from "../lib/browser"; +import { windows, tabs, runtime, CHROME } from "../lib/browser"; import { getManager } from "./manager/man"; import DEFAULT_ICONS from "../data/icons.json"; import { Prefs } from "./prefs"; @@ -129,8 +129,11 @@ export async function openManager(focus = true) { type: "popup", }); const window = await windows.create(windowOptions); - tracker.track(window.id, null); + tracker.track(window.id); try { + if (!CHROME) { + windows.update(window.id, tracker.getOptions({})); + } const port = await Promise.race([ new Promise(resolve => Bus.oncePort("manager", port => { resolve(port); diff --git a/windows/manager/port.ts b/windows/manager/port.ts index 974c557..b8f2ba6 100644 --- a/windows/manager/port.ts +++ b/windows/manager/port.ts @@ -16,6 +16,16 @@ const PORT = new class Port extends EventEmitter { throw new Error("Could not connect"); } new WindowState(this.port); + addEventListener("beforeunload", () => { + if (this.port) { + this.port.postMessage({ + msg: "unload", + left: window.screenX, + top: window.screenY + }); + } + }); + this.port.onMessage.addListener((msg: any) => { if (typeof msg === "string") { this.emit(msg);