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