Skip to content

Commit

Permalink
add stop recording button to menubar
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian committed Jul 24, 2023
1 parent 7d4e629 commit a27e9b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
29 changes: 27 additions & 2 deletions ishare/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
}
}
5 changes: 4 additions & 1 deletion ishare/Util/ScreenRecording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//

import Foundation
import AppKit
import Cocoa

enum RecordingType: String {
case SCREEN = "-t"
Expand All @@ -14,5 +16,6 @@ enum RecordingType: String {
}

func recordScreen(type: RecordingType, display: Int = 1) -> Void {

print("recording")
AppDelegate.shared.toggleIcon(AppDelegate.shared as AnyObject)
}
2 changes: 1 addition & 1 deletion ishare/Views/MainMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit a27e9b7

Please sign in to comment.