Work around Firefox window.create({left, top}) issues
This commit is contained in:
parent
e64da40355
commit
a5c749412a
@ -366,6 +366,7 @@
|
||||
<li>Support <code>[a:z]</code> character batches</li>
|
||||
<li>Dark theme support</li>
|
||||
<li>Improved the gathering of images in websites</li>
|
||||
<li>The windows, in particular the Manager window, will now usually remember the size and position correctly.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Version 4.1 <em>September 21, 2019</em></h3>
|
||||
|
@ -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<Port>([
|
||||
new Promise<Port>(resolve => Bus.oncePort("select", port => {
|
||||
resolve(port);
|
||||
|
@ -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<Port>([
|
||||
new Promise<Port>(resolve => Bus.oncePort("single", port => {
|
||||
resolve(port);
|
||||
|
@ -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() {
|
||||
|
@ -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<Port>([
|
||||
new Promise<Port>(resolve => Bus.oncePort("manager", port => {
|
||||
resolve(port);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user