mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 02:29:59 +00:00
Set window position in native selector based on data from extension
This commit is contained in:
@@ -2,21 +2,47 @@ import Cocoa
|
|||||||
|
|
||||||
|
|
||||||
class AppDelegate : NSObject, NSApplicationDelegate {
|
class AppDelegate : NSObject, NSApplicationDelegate {
|
||||||
|
var initData: InitData!
|
||||||
|
|
||||||
var mainWindow: NSWindow?
|
var mainWindow: NSWindow?
|
||||||
var mainWindowController: NSWindowController?
|
var mainWindowController: NSWindowController?
|
||||||
var mainWindowViewController: ViewController?
|
var mainWindowViewController: ViewController?
|
||||||
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching (_ aNotification: Notification) {
|
func applicationDidFinishLaunching (_ aNotification: Notification) {
|
||||||
|
if (CommandLine.argc < 2) {
|
||||||
|
fputs("Error: Not enough args\n", stderr)
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let data = CommandLine.arguments[1].data(using: .utf8) else {
|
||||||
|
fputs("Error: Failed to convert input to data\n", stderr)
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Decode and store initialization JSON data
|
||||||
|
self.initData = try JSONDecoder().decode(InitData.self, from: data)
|
||||||
|
} catch {
|
||||||
|
fputs("Error: Failed to parse input data\n", stderr)
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let window = NSWindow(
|
let window = NSWindow(
|
||||||
contentRect: NSZeroRect
|
contentRect: NSZeroRect
|
||||||
, styleMask: [ .titled, .closable ]
|
, styleMask: [ .titled, .closable ]
|
||||||
, backing: .buffered
|
, backing: .buffered
|
||||||
, defer: false)
|
, defer: false)
|
||||||
|
|
||||||
|
let screenHeight = NSScreen.main!.frame.height
|
||||||
|
|
||||||
window.titleVisibility = .hidden
|
window.titleVisibility = .hidden
|
||||||
|
window.isMovableByWindowBackground = true
|
||||||
window.orderFrontRegardless()
|
window.orderFrontRegardless()
|
||||||
window.center()
|
window.setFrameTopLeftPoint(NSPoint(
|
||||||
|
x: self.initData.windowPositionX
|
||||||
|
, y: Int(screenHeight - CGFloat(self.initData.windowPositionY))))
|
||||||
|
|
||||||
let windowController = NSWindowController(window: window)
|
let windowController = NSWindowController(window: window)
|
||||||
windowController.showWindow(window)
|
windowController.showWindow(window)
|
||||||
|
|||||||
@@ -21,24 +21,7 @@ class ViewController : NSViewController {
|
|||||||
override func viewDidLoad () {
|
override func viewDidLoad () {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
if (CommandLine.argc < 2) {
|
self.initData = (NSApplication.shared.delegate as! AppDelegate).initData
|
||||||
fputs("Error: Not enough args\n", stderr)
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let data = CommandLine.arguments[1].data(using: .utf8) else {
|
|
||||||
fputs("Error: Failed to convert input to data\n", stderr)
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
// Decode and store initialization JSON data
|
|
||||||
self.initData = try JSONDecoder().decode(InitData.self, from: data)
|
|
||||||
} catch {
|
|
||||||
fputs("Error: Failed to parse input data\n", stderr)
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View Hierarchy
|
* View Hierarchy
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ struct InitData : Codable {
|
|||||||
let defaultMediaType: MediaType
|
let defaultMediaType: MediaType
|
||||||
let availableMediaTypes: Int
|
let availableMediaTypes: Int
|
||||||
|
|
||||||
|
let windowPositionX: Int
|
||||||
|
let windowPositionY: Int
|
||||||
|
|
||||||
let i18n_extensionName: String
|
let i18n_extensionName: String
|
||||||
let i18n_castButtonTitle: String
|
let i18n_castButtonTitle: String
|
||||||
let i18n_mediaTypeApp: String
|
let i18n_mediaTypeApp: String
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import options from "../lib/options";
|
|||||||
import ReceiverSelector, {
|
import ReceiverSelector, {
|
||||||
ReceiverSelectorMediaType } from "./ReceiverSelector";
|
ReceiverSelectorMediaType } from "./ReceiverSelector";
|
||||||
|
|
||||||
|
import { getWindowCenteredProps } from "../lib/utils";
|
||||||
import { Message, Receiver } from "../types";
|
import { Message, Receiver } from "../types";
|
||||||
|
|
||||||
import { NativeReceiverSelectorCloseMessage
|
import { NativeReceiverSelectorCloseMessage
|
||||||
@@ -58,6 +59,11 @@ export default class NativeMacReceiverSelector
|
|||||||
this.bridgePortDisconnected = true;
|
this.bridgePortDisconnected = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Current window to base centered position on
|
||||||
|
const openerWindow = await browser.windows.getCurrent();
|
||||||
|
const centeredProps = getWindowCenteredProps(openerWindow, 350, 0);
|
||||||
|
|
||||||
this.bridgePort.postMessage({
|
this.bridgePort.postMessage({
|
||||||
subject: "bridge:/receiverSelector/open"
|
subject: "bridge:/receiverSelector/open"
|
||||||
, data: JSON.stringify({
|
, data: JSON.stringify({
|
||||||
@@ -65,6 +71,9 @@ export default class NativeMacReceiverSelector
|
|||||||
, defaultMediaType
|
, defaultMediaType
|
||||||
, availableMediaTypes
|
, availableMediaTypes
|
||||||
|
|
||||||
|
, windowPositionX: centeredProps.left
|
||||||
|
, windowPositionY: centeredProps.top
|
||||||
|
|
||||||
, i18n_extensionName: _("extensionName")
|
, i18n_extensionName: _("extensionName")
|
||||||
, i18n_castButtonTitle: _("popupCastButtonTitle")
|
, i18n_castButtonTitle: _("popupCastButtonTitle")
|
||||||
, i18n_mediaTypeApp: _("popupMediaTypeApp")
|
, i18n_mediaTypeApp: _("popupMediaTypeApp")
|
||||||
|
|||||||
Reference in New Issue
Block a user