2022-05-23 11:25:55 +03:00
import Cocoa
2023-01-31 08:32:10 +03:00
import AVFoundation
2022-05-23 11:25:55 +03:00
import FlutterMacOS
2022-11-22 18:01:42 +03:00
import desktop_multi_window
2022-06-27 05:00:51 +03:00
// i m p o r t b i t s d o j o _ w i n d o w _ m a c o s
2022-05-23 11:25:55 +03:00
2023-05-12 08:23:56 +03:00
import desktop_drop
2023-10-31 16:10:23 +03:00
import device_info_plus
2022-11-22 18:01:42 +03:00
import flutter_custom_cursor
2023-05-11 09:26:59 +03:00
import package_info_plus
2023-01-28 04:41:05 +03:00
import path_provider_foundation
2022-11-22 18:01:42 +03:00
import screen_retriever
import sqflite
2022-12-02 11:20:46 +03:00
// i m p o r t t r a y _ m a n a g e r
2022-11-22 18:01:42 +03:00
import uni_links_desktop
import url_launcher_macos
2023-10-31 16:10:23 +03:00
import wakelock_plus
2022-11-22 18:01:42 +03:00
import window_manager
import window_size
2023-02-22 17:33:17 +03:00
import texture_rgba_renderer
2022-11-22 18:01:42 +03:00
2022-06-27 05:00:51 +03:00
class MainFlutterWindow : NSWindow {
2022-06-02 11:13:34 +03:00
override func awakeFromNib ( ) {
2023-06-28 07:05:27 +03:00
rustdesk_core_main ( ) ;
2022-06-02 11:13:34 +03:00
let flutterViewController = FlutterViewController . init ( )
let windowFrame = self . frame
self . contentViewController = flutterViewController
self . setFrame ( windowFrame , display : true )
2023-02-02 08:57:20 +03:00
// r e g i s t e r s e l f m e t h o d h a n d l e r
let registrar = flutterViewController . registrar ( forPlugin : " RustDeskPlugin " )
setMethodHandler ( registrar : registrar )
2022-06-02 11:13:34 +03:00
RegisterGeneratedPlugins ( registry : flutterViewController )
2022-11-22 18:01:42 +03:00
FlutterMultiWindowPlugin . setOnWindowCreatedCallback { controller in
// R e g i s t e r t h e p l u g i n w h i c h y o u w a n t a c c e s s f r o m o t h e r i s o l a t e .
// D e s k t o p L i f e c y c l e P l u g i n . r e g i s t e r ( w i t h : c o n t r o l l e r . r e g i s t r a r ( f o r P l u g i n : " D e s k t o p L i f e c y c l e P l u g i n " ) )
2023-10-31 16:10:23 +03:00
// N o t e : c o p y b e l o w f r o m a b o v e R e g i s t e r G e n e r a t e d P l u g i n s
2023-02-02 08:57:20 +03:00
self . setMethodHandler ( registrar : controller . registrar ( forPlugin : " RustDeskPlugin " ) )
2023-05-12 08:24:21 +03:00
DesktopDropPlugin . register ( with : controller . registrar ( forPlugin : " DesktopDropPlugin " ) )
2022-11-22 18:01:42 +03:00
DeviceInfoPlusMacosPlugin . register ( with : controller . registrar ( forPlugin : " DeviceInfoPlusMacosPlugin " ) )
FlutterCustomCursorPlugin . register ( with : controller . registrar ( forPlugin : " FlutterCustomCursorPlugin " ) )
2023-10-31 16:10:23 +03:00
FPPPackageInfoPlusPlugin . register ( with : controller . registrar ( forPlugin : " FPPPackageInfoPlusPlugin " ) )
2022-11-22 18:01:42 +03:00
PathProviderPlugin . register ( with : controller . registrar ( forPlugin : " PathProviderPlugin " ) )
SqflitePlugin . register ( with : controller . registrar ( forPlugin : " SqflitePlugin " ) )
2022-12-02 11:20:46 +03:00
// T r a y M a n a g e r P l u g i n . r e g i s t e r ( w i t h : c o n t r o l l e r . r e g i s t r a r ( f o r P l u g i n : " T r a y M a n a g e r P l u g i n " ) )
2022-11-22 18:01:42 +03:00
UniLinksDesktopPlugin . register ( with : controller . registrar ( forPlugin : " UniLinksDesktopPlugin " ) )
UrlLauncherPlugin . register ( with : controller . registrar ( forPlugin : " UrlLauncherPlugin " ) )
2023-10-31 16:10:23 +03:00
WakelockPlusMacosPlugin . register ( with : controller . registrar ( forPlugin : " WakelockPlusMacosPlugin " ) )
2022-11-22 18:01:42 +03:00
WindowSizePlugin . register ( with : controller . registrar ( forPlugin : " WindowSizePlugin " ) )
2023-02-22 17:33:17 +03:00
TextureRgbaRendererPlugin . register ( with : controller . registrar ( forPlugin : " TextureRgbaRendererPlugin " ) )
2022-11-22 18:01:42 +03:00
}
2022-06-02 11:13:34 +03:00
super . awakeFromNib ( )
}
2023-01-07 07:40:29 +03:00
override public func order ( _ place : NSWindow . OrderingMode , relativeTo otherWin : Int ) {
super . order ( place , relativeTo : otherWin )
hiddenWindowAtLaunch ( )
}
2023-02-02 08:57:20 +03:00
// / O v e r r i d e w i n d o w t h e m e .
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 12:08:40 +03:00
case " terminate " :
NSApplication . shared . terminate ( self )
result ( nil )
2023-01-31 08:32:10 +03: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 08:57:20 +03:00
default :
result ( FlutterMethodNotImplemented )
}
} )
}
2022-05-23 11:25:55 +03:00
}