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>Support <code>[a:z]</code> character batches</li>
|
||||||
<li>Dark theme support</li>
|
<li>Dark theme support</li>
|
||||||
<li>Improved the gathering of images in websites</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>
|
</ul>
|
||||||
|
|
||||||
<h3>Version 4.1 <em>September 21, 2019</em></h3>
|
<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
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { filters, FAST, Filter } from "./filters";
|
import { filters, FAST, Filter } from "./filters";
|
||||||
import { WindowStateTracker } from "./windowstatetracker";
|
import { WindowStateTracker } from "./windowstatetracker";
|
||||||
import { windows } from "./browser";
|
import { windows, CHROME } from "./browser";
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { BaseItem } from "./item";
|
import { BaseItem } from "./item";
|
||||||
|
|
||||||
@ -98,8 +98,11 @@ export async function select(links: BaseItem[], media: BaseItem[]) {
|
|||||||
type: "popup",
|
type: "popup",
|
||||||
});
|
});
|
||||||
const window = await windows.create(windowOptions);
|
const window = await windows.create(windowOptions);
|
||||||
tracker.track(window.id, null);
|
tracker.track(window.id);
|
||||||
try {
|
try {
|
||||||
|
if (!CHROME) {
|
||||||
|
windows.update(window.id, tracker.getOptions({}));
|
||||||
|
}
|
||||||
const port = await Promise.race<Port>([
|
const port = await Promise.race<Port>([
|
||||||
new Promise<Port>(resolve => Bus.oncePort("select", port => {
|
new Promise<Port>(resolve => Bus.oncePort("select", port => {
|
||||||
resolve(port);
|
resolve(port);
|
||||||
|
@ -6,7 +6,7 @@ import { Bus, Port } from "./bus";
|
|||||||
import { WindowStateTracker } from "./windowstatetracker";
|
import { WindowStateTracker } from "./windowstatetracker";
|
||||||
import { Promised, timeout } from "./util";
|
import { Promised, timeout } from "./util";
|
||||||
import { donate } from "./windowutils";
|
import { donate } from "./windowutils";
|
||||||
import { windows } from "./browser";
|
import { windows, CHROME } from "./browser";
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { BaseItem } from "./item";
|
import { BaseItem } from "./item";
|
||||||
|
|
||||||
@ -21,8 +21,11 @@ export async function single(item: BaseItem | null) {
|
|||||||
type: "popup",
|
type: "popup",
|
||||||
});
|
});
|
||||||
const window = await windows.create(windowOptions);
|
const window = await windows.create(windowOptions);
|
||||||
tracker.track(window.id, null);
|
tracker.track(window.id);
|
||||||
try {
|
try {
|
||||||
|
if (!CHROME) {
|
||||||
|
windows.update(window.id, tracker.getOptions({}));
|
||||||
|
}
|
||||||
const port: Port = await Promise.race<Port>([
|
const port: Port = await Promise.race<Port>([
|
||||||
new Promise<Port>(resolve => Bus.oncePort("single", port => {
|
new Promise<Port>(resolve => Bus.oncePort("single", port => {
|
||||||
resolve(port);
|
resolve(port);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
import { Prefs } from "./prefs";
|
import { Prefs } from "./prefs";
|
||||||
import { windows } from "./browser";
|
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"]));
|
const VALID_WINDOW_STATES = Object.freeze(new Set(["normal", "maximized"]));
|
||||||
@ -80,6 +82,7 @@ export class WindowStateTracker {
|
|||||||
if (!this.windowId) {
|
if (!this.windowId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const window = await windows.get(this.windowId);
|
const window = await windows.get(this.windowId);
|
||||||
if (!VALID_WINDOW_STATES.has(window.state)) {
|
if (!VALID_WINDOW_STATES.has(window.state)) {
|
||||||
return;
|
return;
|
||||||
@ -97,17 +100,30 @@ export class WindowStateTracker {
|
|||||||
}
|
}
|
||||||
await this.save();
|
await this.save();
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
track(windowId: number, port: any) {
|
track(windowId: number, port?: Port) {
|
||||||
if (port) {
|
if (port) {
|
||||||
port.on("resized", this.update);
|
port.on("resized", this.update);
|
||||||
|
port.on("unload", e => this.finalize(e));
|
||||||
|
port.on("disconnect", this.finalize.bind(this));
|
||||||
}
|
}
|
||||||
this.windowId = windowId;
|
this.windowId = windowId;
|
||||||
}
|
}
|
||||||
|
|
||||||
async finalize() {
|
async finalize(state?: any) {
|
||||||
|
if (state) {
|
||||||
|
this.left = state.left;
|
||||||
|
this.top = state.top;
|
||||||
|
}
|
||||||
await this.update();
|
await this.update();
|
||||||
this.windowId = 0;
|
this.windowId = 0;
|
||||||
|
if (state) {
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// License: MIT
|
// License: MIT
|
||||||
|
|
||||||
import { windows, tabs, runtime } from "../lib/browser";
|
import { windows, tabs, runtime, CHROME } from "../lib/browser";
|
||||||
import { getManager } from "./manager/man";
|
import { getManager } from "./manager/man";
|
||||||
import DEFAULT_ICONS from "../data/icons.json";
|
import DEFAULT_ICONS from "../data/icons.json";
|
||||||
import { Prefs } from "./prefs";
|
import { Prefs } from "./prefs";
|
||||||
@ -129,8 +129,11 @@ export async function openManager(focus = true) {
|
|||||||
type: "popup",
|
type: "popup",
|
||||||
});
|
});
|
||||||
const window = await windows.create(windowOptions);
|
const window = await windows.create(windowOptions);
|
||||||
tracker.track(window.id, null);
|
tracker.track(window.id);
|
||||||
try {
|
try {
|
||||||
|
if (!CHROME) {
|
||||||
|
windows.update(window.id, tracker.getOptions({}));
|
||||||
|
}
|
||||||
const port = await Promise.race<Port>([
|
const port = await Promise.race<Port>([
|
||||||
new Promise<Port>(resolve => Bus.oncePort("manager", port => {
|
new Promise<Port>(resolve => Bus.oncePort("manager", port => {
|
||||||
resolve(port);
|
resolve(port);
|
||||||
|
@ -16,6 +16,16 @@ const PORT = new class Port extends EventEmitter {
|
|||||||
throw new Error("Could not connect");
|
throw new Error("Could not connect");
|
||||||
}
|
}
|
||||||
new WindowState(this.port);
|
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) => {
|
this.port.onMessage.addListener((msg: any) => {
|
||||||
if (typeof msg === "string") {
|
if (typeof msg === "string") {
|
||||||
this.emit(msg);
|
this.emit(msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user