//
//  MacApp.swift
//  AppKitGlue
//
//  Created by Amir on 05/05/2020.
//  Copyright © 2020 Amir Khorsandi. All rights reserved.
//

import Cocoa

class MacApp: NSObject, AppKitBridge {
    
    func initialise() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            if NSApplication.shared.mainWindow != nil {
                self.onMainWindowReady()
            }
        }
    }
    
    private func onMainWindowReady() {
        hideToolbar()
        setSize()
    }
    
    private func setSize() {
        guard let window = NSApplication.shared.mainWindow else {
            return
        }
        if window.minSize.width < 1_200 || window.minSize.height < 768 {
            window.minSize = NSSize(width: 1_200, height: 768)
        }
        window.setFrame(.init(origin: window.frame.origin, size: window.minSize), display: true, animate: true)
    }
    
    private func hideToolbar() {
        if let window = NSApplication.shared.mainWindow {
            window.titleVisibility = .hidden
            window.toolbar = nil
        }
    }
}
