mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-31 10:03:18 +00:00 
			
		
		
		
	 61fd608200
			
		
	
	
		61fd608200
		
			
		
	
	
	
	
		
			
			* refactor: rename structs * chore: read database id from view * chore: fix open database error because of create a database view for database id * chore: fix tests * chore: rename datbase id to view id in flutter * refactor: move grid and board to database view folder * refactor: rename functions * refactor: move calender to datbase view folder * refactor: rename app_flowy to appflowy_flutter * chore: reanming * chore: fix freeze gen * chore: remove todos * refactor: view process events * chore: add link database test * chore: just open view if there is opened database
		
			
				
	
	
		
			86 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
| import Cocoa
 | |
| import FlutterMacOS
 | |
| 
 | |
| private let kTrafficLightOffetTop = 22
 | |
| 
 | |
| class MainFlutterWindow: NSWindow {
 | |
|   func registerMethodChannel(flutterViewController: FlutterViewController) {
 | |
|     let cocoaWindowChannel = FlutterMethodChannel(name: "flutter/cocoaWindow", binaryMessenger: flutterViewController.engine.binaryMessenger)
 | |
|     cocoaWindowChannel.setMethodCallHandler({
 | |
|       (call: FlutterMethodCall, result: FlutterResult) -> Void in
 | |
|       if call.method == "setWindowPosition" {
 | |
|         guard let position = call.arguments as? NSArray else {
 | |
|           result(nil)
 | |
|           return
 | |
|         }
 | |
|         let nX = position[0] as! NSNumber
 | |
|         let nY = position[1] as! NSNumber
 | |
|         let x = nX.doubleValue
 | |
|         let y = nY.doubleValue
 | |
|         
 | |
|         self.setFrameOrigin(NSPoint(x: x, y: y))
 | |
|         result(nil)
 | |
|         return
 | |
|       } else if call.method == "getWindowPosition" {
 | |
|         let frame = self.frame
 | |
|         result([frame.origin.x, frame.origin.y])
 | |
|         return
 | |
|       } else if call.method == "zoom" {
 | |
|         self.zoom(self)
 | |
|         result(nil)
 | |
|         return
 | |
|       }
 | |
|       
 | |
|       result(FlutterMethodNotImplemented)
 | |
|     })
 | |
|   }
 | |
| 
 | |
|   func layoutTrafficLightButton(titlebarView: NSView, button: NSButton, offsetTop: CGFloat, offsetLeft: CGFloat) {
 | |
|     button.translatesAutoresizingMaskIntoConstraints = false;
 | |
|     titlebarView.addConstraint(NSLayoutConstraint.init(
 | |
|       item: button,
 | |
|       attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: titlebarView, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: offsetTop))
 | |
|     titlebarView.addConstraint(NSLayoutConstraint.init(
 | |
|       item: button,
 | |
|       attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: titlebarView, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: offsetLeft))
 | |
|   }
 | |
| 
 | |
|   func layoutTrafficLights() {
 | |
|     let closeButton = self.standardWindowButton(ButtonType.closeButton)!
 | |
|     let minButton = self.standardWindowButton(ButtonType.miniaturizeButton)!
 | |
|     let zoomButton = self.standardWindowButton(ButtonType.zoomButton)!
 | |
|     let titlebarView = closeButton.superview!
 | |
| 
 | |
|     self.layoutTrafficLightButton(titlebarView: titlebarView, button: closeButton, offsetTop: CGFloat(kTrafficLightOffetTop), offsetLeft: 20)
 | |
|     self.layoutTrafficLightButton(titlebarView: titlebarView, button: minButton, offsetTop: CGFloat(kTrafficLightOffetTop), offsetLeft: 38)
 | |
|     self.layoutTrafficLightButton(titlebarView: titlebarView, button: zoomButton, offsetTop: CGFloat(kTrafficLightOffetTop), offsetLeft: 56)
 | |
| 
 | |
|     let customToolbar = NSTitlebarAccessoryViewController()
 | |
|     let newView = NSView()
 | |
|     newView.frame = NSRect(origin: CGPoint(), size: CGSize(width: 0, height: 40))  // only the height is cared
 | |
|     customToolbar.view = newView
 | |
|     self.addTitlebarAccessoryViewController(customToolbar)
 | |
|   }
 | |
| 
 | |
|   override func awakeFromNib() {
 | |
|     let flutterViewController = FlutterViewController.init()
 | |
|     let windowFrame = self.frame
 | |
|     self.contentViewController = flutterViewController
 | |
| 
 | |
|     self.registerMethodChannel(flutterViewController: flutterViewController)
 | |
| 
 | |
|     self.setFrame(windowFrame, display: true)
 | |
|     self.titlebarAppearsTransparent = true
 | |
|     self.titleVisibility = .hidden
 | |
|     self.styleMask.insert(StyleMask.fullSizeContentView)
 | |
|     self.isMovableByWindowBackground = true
 | |
|     self.isMovable = false
 | |
| 
 | |
|     self.layoutTrafficLights()
 | |
| 
 | |
|     RegisterGeneratedPlugins(registry: flutterViewController)
 | |
| 
 | |
|     super.awakeFromNib()
 | |
|   }
 | |
| }
 |