2022-05-23 16:25:55 +08:00
|
|
|
import Cocoa
|
2023-01-31 13:32:10 +08:00
|
|
|
import AVFoundation
|
2023-06-28 11:34:08 +08:00
|
|
|
import Foundation
|
2022-05-23 16:25:55 +08:00
|
|
|
import FlutterMacOS
|
2022-11-22 23:01:42 +08:00
|
|
|
import desktop_multi_window
|
2022-06-27 10:00:51 +08:00
|
|
|
// import bitsdojo_window_macos
|
2022-05-23 16:25:55 +08:00
|
|
|
|
2023-05-12 13:23:56 +08:00
|
|
|
import desktop_drop
|
2022-11-22 23:01:42 +08:00
|
|
|
import device_info_plus_macos
|
|
|
|
import flutter_custom_cursor
|
2023-05-11 14:26:59 +08:00
|
|
|
import package_info_plus
|
2023-01-28 09:41:05 +08:00
|
|
|
import path_provider_foundation
|
2022-11-22 23:01:42 +08:00
|
|
|
import screen_retriever
|
|
|
|
import sqflite
|
2022-12-02 16:20:46 +08:00
|
|
|
// import tray_manager
|
2022-11-22 23:01:42 +08:00
|
|
|
import uni_links_desktop
|
|
|
|
import url_launcher_macos
|
|
|
|
import wakelock_macos
|
|
|
|
import window_manager
|
|
|
|
import window_size
|
2023-02-22 22:33:17 +08:00
|
|
|
import texture_rgba_renderer
|
2022-11-22 23:01:42 +08:00
|
|
|
|
2022-06-27 10:00:51 +08:00
|
|
|
class MainFlutterWindow: NSWindow {
|
2022-06-02 16:13:34 +08:00
|
|
|
override func awakeFromNib() {
|
|
|
|
if (!rustdesk_core_main()){
|
2023-06-28 11:34:08 +08:00
|
|
|
Process.terminate()
|
|
|
|
return
|
2022-06-02 16:13:34 +08:00
|
|
|
}
|
|
|
|
let flutterViewController = FlutterViewController.init()
|
|
|
|
let windowFrame = self.frame
|
|
|
|
self.contentViewController = flutterViewController
|
|
|
|
self.setFrame(windowFrame, display: true)
|
2023-02-02 13:57:20 +08:00
|
|
|
// register self method handler
|
|
|
|
let registrar = flutterViewController.registrar(forPlugin: "RustDeskPlugin")
|
|
|
|
setMethodHandler(registrar: registrar)
|
2022-06-02 16:13:34 +08:00
|
|
|
|
|
|
|
RegisterGeneratedPlugins(registry: flutterViewController)
|
2022-11-22 23:01:42 +08:00
|
|
|
|
|
|
|
FlutterMultiWindowPlugin.setOnWindowCreatedCallback { controller in
|
|
|
|
// Register the plugin which you want access from other isolate.
|
|
|
|
// DesktopLifecyclePlugin.register(with: controller.registrar(forPlugin: "DesktopLifecyclePlugin"))
|
2023-02-02 13:57:20 +08:00
|
|
|
self.setMethodHandler(registrar: controller.registrar(forPlugin: "RustDeskPlugin"))
|
2023-05-12 13:24:21 +08:00
|
|
|
DesktopDropPlugin.register(with: controller.registrar(forPlugin: "DesktopDropPlugin"))
|
2022-11-22 23:01:42 +08:00
|
|
|
DeviceInfoPlusMacosPlugin.register(with: controller.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
|
|
|
FlutterCustomCursorPlugin.register(with: controller.registrar(forPlugin: "FlutterCustomCursorPlugin"))
|
|
|
|
FLTPackageInfoPlusPlugin.register(with: controller.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
|
|
|
|
PathProviderPlugin.register(with: controller.registrar(forPlugin: "PathProviderPlugin"))
|
|
|
|
SqflitePlugin.register(with: controller.registrar(forPlugin: "SqflitePlugin"))
|
2022-12-02 16:20:46 +08:00
|
|
|
// TrayManagerPlugin.register(with: controller.registrar(forPlugin: "TrayManagerPlugin"))
|
2022-11-22 23:01:42 +08:00
|
|
|
UniLinksDesktopPlugin.register(with: controller.registrar(forPlugin: "UniLinksDesktopPlugin"))
|
|
|
|
UrlLauncherPlugin.register(with: controller.registrar(forPlugin: "UrlLauncherPlugin"))
|
|
|
|
WakelockMacosPlugin.register(with: controller.registrar(forPlugin: "WakelockMacosPlugin"))
|
|
|
|
WindowSizePlugin.register(with: controller.registrar(forPlugin: "WindowSizePlugin"))
|
2023-02-22 22:33:17 +08:00
|
|
|
TextureRgbaRendererPlugin.register(with: controller.registrar(forPlugin: "TextureRgbaRendererPlugin"))
|
2022-11-22 23:01:42 +08:00
|
|
|
}
|
2022-06-02 16:13:34 +08:00
|
|
|
|
|
|
|
super.awakeFromNib()
|
|
|
|
}
|
|
|
|
|
2023-01-07 12:40:29 +08:00
|
|
|
override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
|
|
|
|
super.order(place, relativeTo: otherWin)
|
|
|
|
hiddenWindowAtLaunch()
|
|
|
|
}
|
2023-02-02 13:57:20 +08:00
|
|
|
|
|
|
|
/// Override window theme.
|
|
|
|
public func setWindowInterfaceMode(window: NSWindow, themeName: String) {
|
|
|
|
window.appearance = NSAppearance(named: themeName == "light" ? .aqua : .darkAqua)
|
|
|
|
}
|
|
|
|
|
|
|
|
public func setMethodHandler(registrar: FlutterPluginRegistrar) {
|
|
|
|
let channel = FlutterMethodChannel(name: "org.rustdesk.rustdesk/macos", binaryMessenger: registrar.messenger)
|
|
|
|
channel.setMethodCallHandler({
|
|
|
|
(call, result) -> Void in
|
|
|
|
switch call.method {
|
|
|
|
case "setWindowTheme":
|
|
|
|
let arg = call.arguments as! [String: Any]
|
|
|
|
let themeName = arg["themeName"] as? String
|
|
|
|
guard let window = registrar.view?.window else {
|
|
|
|
result(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.setWindowInterfaceMode(window: window,themeName: themeName ?? "light")
|
|
|
|
result(nil)
|
|
|
|
break;
|
2023-02-03 17:08:40 +08:00
|
|
|
case "terminate":
|
|
|
|
NSApplication.shared.terminate(self)
|
|
|
|
result(nil)
|
2023-01-31 13:32:10 +08:00
|
|
|
case "canRecordAudio":
|
|
|
|
switch AVCaptureDevice.authorizationStatus(for: .audio) {
|
|
|
|
case .authorized:
|
|
|
|
result(1)
|
|
|
|
break
|
|
|
|
case .notDetermined:
|
|
|
|
result(0)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
result(-1)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case "requestRecordAudio":
|
|
|
|
AVCaptureDevice.requestAccess(for: .audio, completionHandler: { granted in
|
|
|
|
result(granted)
|
|
|
|
})
|
|
|
|
break
|
2023-02-02 13:57:20 +08:00
|
|
|
default:
|
|
|
|
result(FlutterMethodNotImplemented)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-05-23 16:25:55 +08:00
|
|
|
}
|