mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Add options checks for waitForConnection and closeIfFocusLost
This commit is contained in:
@@ -10,7 +10,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching (_ aNotification: Notification) {
|
func applicationDidFinishLaunching (_ aNotification: Notification) {
|
||||||
if (CommandLine.argc < 2) {
|
if CommandLine.argc < 2 {
|
||||||
fputs("Error: Not enough args\n", stderr)
|
fputs("Error: Not enough args\n", stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,9 @@ class AppDelegate : NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applicationDidResignActive (_ aNotification: Notification) {
|
func applicationDidResignActive (_ aNotification: Notification) {
|
||||||
self.mainWindow?.performClose(aNotification)
|
if self.initData.closeIfFocusLost {
|
||||||
|
self.mainWindow?.performClose(aNotification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationShouldTerminateAfterLastWindowClosed (
|
func applicationShouldTerminateAfterLastWindowClosed (
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ struct InitData : Codable {
|
|||||||
let defaultMediaType: MediaType
|
let defaultMediaType: MediaType
|
||||||
let availableMediaTypes: Int
|
let availableMediaTypes: Int
|
||||||
|
|
||||||
|
let closeIfFocusLost: Bool
|
||||||
|
|
||||||
let windowPositionX: Int
|
let windowPositionX: Int
|
||||||
let windowPositionY: Int
|
let windowPositionY: Int
|
||||||
|
|
||||||
|
|||||||
@@ -129,9 +129,17 @@ export default async function createShim (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: If we're closing a selector, make sure it's the
|
||||||
|
* same one that caused the session creation.
|
||||||
|
*/
|
||||||
case "main:/sessionCreated": {
|
case "main:/sessionCreated": {
|
||||||
const selector = await SelectorManager.getSharedSelector();
|
const selector = await SelectorManager.getSharedSelector();
|
||||||
if (selector.isOpen) {
|
|
||||||
|
const shouldClose = await options.get(
|
||||||
|
"receiverSelectorWaitForConnection");
|
||||||
|
|
||||||
|
if (selector.isOpen && shouldClose) {
|
||||||
selector.close();
|
selector.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import defaultOptions from "../defaultOptions";
|
import defaultOptions from "../defaultOptions";
|
||||||
|
|
||||||
import { ReceiverSelectorType } from "../receiver_selectors";
|
import { ReceiverSelectorType } from "../receiver_selectors/";
|
||||||
import { Message } from "../types";
|
import { Message } from "../types";
|
||||||
import { TypedEventTarget } from "./typedEvents";
|
import { TypedEventTarget } from "./typedEvents";
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ export default class NativeMacReceiverSelector
|
|||||||
const openerWindow = await browser.windows.getCurrent();
|
const openerWindow = await browser.windows.getCurrent();
|
||||||
const centeredProps = getWindowCenteredProps(openerWindow, 350, 0);
|
const centeredProps = getWindowCenteredProps(openerWindow, 350, 0);
|
||||||
|
|
||||||
|
const closeIfFocusLost = await options.get(
|
||||||
|
"receiverSelectorCloseIfFocusLost");
|
||||||
|
|
||||||
this.bridgePort.postMessage({
|
this.bridgePort.postMessage({
|
||||||
subject: "bridge:/receiverSelector/open"
|
subject: "bridge:/receiverSelector/open"
|
||||||
, data: JSON.stringify({
|
, data: JSON.stringify({
|
||||||
@@ -90,6 +93,8 @@ export default class NativeMacReceiverSelector
|
|||||||
, defaultMediaType
|
, defaultMediaType
|
||||||
, availableMediaTypes
|
, availableMediaTypes
|
||||||
|
|
||||||
|
, closeIfFocusLost
|
||||||
|
|
||||||
, windowPositionX: centeredProps.left
|
, windowPositionX: centeredProps.left
|
||||||
, windowPositionY: centeredProps.top
|
, windowPositionY: centeredProps.top
|
||||||
|
|
||||||
@@ -118,20 +123,27 @@ export default class NativeMacReceiverSelector
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private onBridgePortMessageSelected (
|
private async onBridgePortMessageSelected (
|
||||||
message: NativeReceiverSelectorSelectedMessage) {
|
message: NativeReceiverSelectorSelectedMessage) {
|
||||||
|
|
||||||
this.wasReceiverSelected = true;
|
this.wasReceiverSelected = true;
|
||||||
|
|
||||||
this.dispatchEvent(new CustomEvent("selected", {
|
this.dispatchEvent(new CustomEvent("selected", {
|
||||||
detail: message.data
|
detail: message.data
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (!(await options.get("receiverSelectorWaitForConnection"))) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onBridgePortMessageError (
|
private async onBridgePortMessageError (
|
||||||
message: NativeReceiverSelectorErrorMessage) {
|
message: NativeReceiverSelectorErrorMessage) {
|
||||||
|
|
||||||
this.dispatchEvent(new CustomEvent("error"));
|
this.dispatchEvent(new CustomEvent("error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private onBridgePortMessageClose (
|
private async onBridgePortMessageClose (
|
||||||
message: NativeReceiverSelectorCloseMessage) {
|
message: NativeReceiverSelectorCloseMessage) {
|
||||||
|
|
||||||
if (!this.wasReceiverSelected) {
|
if (!this.wasReceiverSelected) {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import ReceiverSelector, {
|
|||||||
ReceiverSelectorEvents
|
ReceiverSelectorEvents
|
||||||
, ReceiverSelectorMediaType } from "./ReceiverSelector";
|
, ReceiverSelectorMediaType } from "./ReceiverSelector";
|
||||||
|
|
||||||
|
import options from "../lib/options";
|
||||||
|
|
||||||
import { TypedEventTarget } from "../lib/typedEvents";
|
import { TypedEventTarget } from "../lib/typedEvents";
|
||||||
import { getWindowCenteredProps } from "../lib/utils";
|
import { getWindowCenteredProps } from "../lib/utils";
|
||||||
import { Message, Receiver } from "../types";
|
import { Message, Receiver } from "../types";
|
||||||
@@ -107,9 +109,15 @@ export default class PopupReceiverSelector
|
|||||||
...centeredProps
|
...centeredProps
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add focus listener
|
|
||||||
browser.windows.onFocusChanged.addListener(
|
const closeIfFocusLost = await options.get(
|
||||||
this.onWindowsFocusChanged);
|
"receiverSelectorCloseIfFocusLost");
|
||||||
|
|
||||||
|
if (closeIfFocusLost) {
|
||||||
|
// Add focus listener
|
||||||
|
browser.windows.onFocusChanged.addListener(
|
||||||
|
this.onWindowsFocusChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async close (): Promise<void> {
|
public async close (): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user