mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Move window centering to utils
This commit is contained in:
@@ -8,3 +8,14 @@ export function getNextEllipsis (ellipsis) {
|
|||||||
else if (ellipsis === "...") "";
|
else if (ellipsis === "...") "";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWindowCenteredProps (refWin, width, height) {
|
||||||
|
const centerX = refWin.left + (refWin.width / 2);
|
||||||
|
const centerY = refWin.top + (refWin.height / 3);
|
||||||
|
|
||||||
|
return {
|
||||||
|
width, height
|
||||||
|
, left: Math.floor(centerX - width / 2)
|
||||||
|
, top: Math.floor(centerY - height / 2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import defaultOptions from "./options/defaultOptions";
|
|||||||
import getBridgeInfo from "./lib/getBridgeInfo";
|
import getBridgeInfo from "./lib/getBridgeInfo";
|
||||||
import messageRouter from "./lib/messageRouter";
|
import messageRouter from "./lib/messageRouter";
|
||||||
|
|
||||||
|
import { getWindowCenteredProps } from "./lib/utils";
|
||||||
|
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
|
|
||||||
@@ -335,26 +337,14 @@ let popupPort;
|
|||||||
* to close and returns an API error.
|
* to close and returns an API error.
|
||||||
*/
|
*/
|
||||||
async function openPopup (shimId) {
|
async function openPopup (shimId) {
|
||||||
const width = 350;
|
|
||||||
const height = 200;
|
|
||||||
|
|
||||||
// Current window to base centered position on
|
// Current window to base centered position on
|
||||||
const win = await browser.windows.getCurrent();
|
const win = await browser.windows.getCurrent();
|
||||||
|
const centeredProps = getWindowCenteredProps(win, 350, 200);
|
||||||
// Top(mid)-center position
|
|
||||||
const centerX = win.left + (win.width / 2);
|
|
||||||
const centerY = win.top + (win.height / 3);
|
|
||||||
|
|
||||||
const left = Math.floor(centerX - (width / 2));
|
|
||||||
const top = Math.floor(centerY - (height / 2));
|
|
||||||
|
|
||||||
const popup = await browser.windows.create({
|
const popup = await browser.windows.create({
|
||||||
url: "popup/index.html"
|
url: "popup/index.html"
|
||||||
, type: "popup"
|
, type: "popup"
|
||||||
, width
|
, ...centeredProps
|
||||||
, height
|
|
||||||
, left
|
|
||||||
, top
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store popup details for message forwarding
|
// Store popup details for message forwarding
|
||||||
@@ -363,10 +353,7 @@ async function openPopup (shimId) {
|
|||||||
|
|
||||||
// Size/position not set correctly on creation (bug?)
|
// Size/position not set correctly on creation (bug?)
|
||||||
await browser.windows.update(popup.id, {
|
await browser.windows.update(popup.id, {
|
||||||
width
|
...centeredProps
|
||||||
, height
|
|
||||||
, left
|
|
||||||
, top
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Close popup on other browser window focus
|
// Close popup on other browser window focus
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
import { getNextEllipsis } from "../lib/utils";
|
import { getNextEllipsis
|
||||||
|
, getWindowCenteredProps } from "../lib/utils";
|
||||||
|
|
||||||
const _ = browser.i18n.getMessage;
|
const _ = browser.i18n.getMessage;
|
||||||
|
|
||||||
@@ -146,34 +147,19 @@ export default class Bridge extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onUpdate () {
|
async onUpdate () {
|
||||||
const width = 400;
|
|
||||||
const height = 150;
|
|
||||||
|
|
||||||
// Current window to base centered position on
|
// Current window to base centered position on
|
||||||
const win = await browser.windows.getCurrent();
|
const win = await browser.windows.getCurrent();
|
||||||
|
const centeredProps = getWindowCenteredProps(win, 400, 150);
|
||||||
// Top(mid)-center position
|
|
||||||
const centerX = win.left + (win.width / 2);
|
|
||||||
const centerY = win.top + (win.height / 3);
|
|
||||||
|
|
||||||
const left = Math.floor(centerX - (width / 2));
|
|
||||||
const top = Math.floor(centerY - (height / 2));
|
|
||||||
|
|
||||||
const updaterPopup = await browser.windows.create({
|
const updaterPopup = await browser.windows.create({
|
||||||
url: "../updater/index.html"
|
url: "../updater/index.html"
|
||||||
, type: "popup"
|
, type: "popup"
|
||||||
, width
|
, ...centeredProps
|
||||||
, height
|
|
||||||
, left
|
|
||||||
, top
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Size/position not set correctly on creation (bug?)
|
// Size/position not set correctly on creation (bug?)
|
||||||
await browser.windows.update(updaterPopup.id, {
|
await browser.windows.update(updaterPopup.id, {
|
||||||
width
|
...centeredProps
|
||||||
, height
|
|
||||||
, left
|
|
||||||
, top
|
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.runtime.onConnect.addListener(port => {
|
browser.runtime.onConnect.addListener(port => {
|
||||||
|
|||||||
Reference in New Issue
Block a user