diff --git a/ishare/App.swift b/ishare/App.swift index 3df6d11..a8d0954 100644 --- a/ishare/App.swift +++ b/ishare/App.swift @@ -13,7 +13,7 @@ import FinderSync struct ishare: App { @Default(.menuBarAppIcon) var menuBarAppIcon @StateObject private var appState = AppState() - @NSApplicationDelegateAdaptor private var appDeletate : AppDelegate + @NSApplicationDelegateAdaptor private var appDelegate : AppDelegate var body: some Scene { MenuBarExtra() { @@ -30,9 +30,34 @@ struct ishare: App { } class AppDelegate: NSObject, NSApplicationDelegate { + static private(set) var shared: AppDelegate! = nil + func application(_ application: NSApplication, open urls: [URL]) { if urls.count == 1 { importIscu(urls.first!) } - } + } + + lazy var statusBarItem: NSStatusItem = { + return NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) + }() + + var isIconShown = false + + func applicationDidFinishLaunching(_ notification: Notification) { + AppDelegate.shared = self + if let button = statusBarItem.button { + button.action = #selector(toggleIcon) + } + } + + @objc func toggleIcon(_ sender: AnyObject) { + isIconShown.toggle() + + if isIconShown { + statusBarItem.button?.image = NSImage(systemSymbolName: "stop.fill", accessibilityDescription: "Stop Icon") + } else { + statusBarItem.button?.image = nil + } + } } diff --git a/ishare/Util/ScreenRecording.swift b/ishare/Util/ScreenRecording.swift index f03bbbd..f390e54 100644 --- a/ishare/Util/ScreenRecording.swift +++ b/ishare/Util/ScreenRecording.swift @@ -6,6 +6,8 @@ // import Foundation +import AppKit +import Cocoa enum RecordingType: String { case SCREEN = "-t" @@ -14,5 +16,6 @@ enum RecordingType: String { } func recordScreen(type: RecordingType, display: Int = 1) -> Void { - + print("recording") + AppDelegate.shared.toggleIcon(AppDelegate.shared as AnyObject) } diff --git a/ishare/Views/MainMenuView.swift b/ishare/Views/MainMenuView.swift index 912d1a2..29b64c1 100644 --- a/ishare/Views/MainMenuView.swift +++ b/ishare/Views/MainMenuView.swift @@ -44,7 +44,7 @@ struct MainMenuView: View { let screen = NSScreen.screens[index] let screenName = screen.localizedName Button("Record \(screenName)") { - // captureScreen(type: .SCREEN, display: index + 1) + recordScreen(type: .SCREEN, display: index + 1) }.keyboardShortcut(index == 0 ? .recordScreen : .noKeybind) } }