Skip to content

Commit

Permalink
fix ui
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyun6 committed Nov 25, 2024
1 parent 342eaa5 commit 82e7de6
Show file tree
Hide file tree
Showing 46 changed files with 406 additions and 148 deletions.
4 changes: 4 additions & 0 deletions QuickRecorder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
181724052BE3BEA600F5F539 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 181724042BE3BEA600F5F539 /* Sparkle */; };
181724082BE3BF7300F5F539 /* Sparkle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181724072BE3BF7300F5F539 /* Sparkle.swift */; };
1821F2972CF40752004A2EC0 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1821F2962CF40752004A2EC0 /* WindowAccessor.swift */; };
1821F2E82CF4B226004A2EC0 /* ContentViewNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1821F2E72CF4B226004A2EC0 /* ContentViewNew.swift */; };
184506CE2C69213400AFDA45 /* MatrixColorSelector in Frameworks */ = {isa = PBXBuildFile; productRef = 184506CD2C69213400AFDA45 /* MatrixColorSelector */; };
184CAEC72BDCCC2300D61D57 /* AVContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CAEC62BDCCC2300D61D57 /* AVContext.swift */; };
184CAEC92BDDEC6800D61D57 /* AppBlockSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CAEC82BDDEC6800D61D57 /* AppBlockSelector.swift */; };
Expand Down Expand Up @@ -47,6 +48,7 @@
180B54602CCF45E800A5D5FD /* GroupForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupForm.swift; sourceTree = "<group>"; };
181724072BE3BF7300F5F539 /* Sparkle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sparkle.swift; sourceTree = "<group>"; };
1821F2962CF40752004A2EC0 /* WindowAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowAccessor.swift; sourceTree = "<group>"; };
1821F2E72CF4B226004A2EC0 /* ContentViewNew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewNew.swift; sourceTree = "<group>"; };
184CAEC62BDCCC2300D61D57 /* AVContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVContext.swift; sourceTree = "<group>"; };
184CAEC82BDDEC6800D61D57 /* AppBlockSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppBlockSelector.swift; sourceTree = "<group>"; };
1862BF902BD5494F003ED522 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = "zh-Hans"; path = "zh-Hans.lproj/Credits.rtf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +157,7 @@
children = (
18D3BDFE2BCE5E4B006CFFC0 /* StatusBar.swift */,
18D3BDEC2BCE5DC1006CFFC0 /* ContentView.swift */,
1821F2E72CF4B226004A2EC0 /* ContentViewNew.swift */,
18FEBDAF2BD2C0D1003F09BC /* SettingsView.swift */,
18D3BE002BCEB1BF006CFFC0 /* AppSelector.swift */,
18FEBDAB2BD01E82003F09BC /* WinSelector.swift */,
Expand Down Expand Up @@ -269,6 +272,7 @@
184CAEC92BDDEC6800D61D57 /* AppBlockSelector.swift in Sources */,
184CAEC72BDCCC2300D61D57 /* AVContext.swift in Sources */,
18D3BDFF2BCE5E4B006CFFC0 /* StatusBar.swift in Sources */,
1821F2E82CF4B226004A2EC0 /* ContentViewNew.swift in Sources */,
18D3BE042BCEC847006CFFC0 /* SCContext.swift in Sources */,
18775C202BE21F38008333EF /* iDeviceSelector.swift in Sources */,
18D3BDED2BCE5DC1006CFFC0 /* ContentView.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions QuickRecorder/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0x2B",
"green" : "0x3A",
"red" : "0xCD"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0x5D",
"green" : "0x6A",
"red" : "0xEC"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions QuickRecorder/Assets.xcassets/Others/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
File renamed without changes
File renamed without changes
File renamed without changes
6 changes: 6 additions & 0 deletions QuickRecorder/Assets.xcassets/Settings/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
69 changes: 34 additions & 35 deletions QuickRecorder/QuickRecorderApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
var presenterType = "OFF"
var frameQueue = FixedLengthArray<CMTime>(maxLength: 20)
@AppStorage("showOnDock") private var showOnDock: Bool = true
//var lastTime = CMTime(value: 0, timescale: 600)
@AppStorage("showMenubar") private var showMenubar: Bool = false

func mousePointerReLocation(event: NSEvent) {
if event.type == .scrollWheel { return }
Expand Down Expand Up @@ -165,39 +165,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
func applicationWillTerminate(_ aNotification: Notification) {
if SCContext.stream != nil { SCContext.stopRecording() }
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if SCContext.stream == nil {
let w1 = NSApp.windows.filter({ !$0.title.contains("Item-0") && !$0.title.isEmpty && $0.isVisible })
let w2 = w1.filter({ !$0.title.contains(".qma") })
if (!w1.isEmpty && w2.isEmpty) || w1.isEmpty {
var mainPanel: NSPanel!
if #available(macOS 13, *) {
mainPanel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 927, height: 100), styleMask: [.fullSizeContentView, .nonactivatingPanel], backing: .buffered, defer: false)
} else {
mainPanel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 800, height: 100), styleMask: [.fullSizeContentView, .nonactivatingPanel], backing: .buffered, defer: false)
}
mainPanel.contentView = NSHostingView(rootView: ContentView())
mainPanel.title = "QuickRecorder".local
mainPanel.isOpaque = false
mainPanel.level = .floating
mainPanel.isRestorable = false
mainPanel.backgroundColor = .clear
mainPanel.isReleasedWhenClosed = false
mainPanel.isMovableByWindowBackground = true
mainPanel.collectionBehavior = [.canJoinAllSpaces]
mainPanel.center()
if let screen = mainPanel.screen {
let wX = (screen.frame.width - mainPanel.frame.width) / 2 + screen.frame.minX
let wY = (screen.frame.height - mainPanel.frame.height) / 2 + screen.frame.minY
mainPanel.setFrameOrigin(NSPoint(x: wX, y: wY))
}
mainPanel.orderFront(self)
if #unavailable(macOS 13) { NSApp.activate(ignoringOtherApps: true) }
}
}
return false
}

func application(_ application: NSApplication, open urls: [URL]) {
for url in urls {
Expand Down Expand Up @@ -251,7 +218,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
)

if ud.integer(forKey: "highRes") == 0 { ud.setValue(2, forKey: "highRes") }
if !ud.bool(forKey: "showOnDock") && !ud.bool(forKey: "showMenubar") { ud.setValue(true, forKey: "showOnDock") }
if ud.bool(forKey: "showOnDock") { NSApp.setActivationPolicy(.regular) }

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
Expand Down Expand Up @@ -320,6 +286,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
controlPanel.titlebarAppearsTransparent = true
controlPanel.isMovableByWindowBackground = true

KeyboardShortcuts.onKeyDown(for: .showPanel) { _ = self.applicationShouldHandleReopen(NSApp, hasVisibleWindows: true) }
KeyboardShortcuts.onKeyDown(for: .saveFrame) { if SCContext.stream != nil { SCContext.saveFrame = true }}
KeyboardShortcuts.onKeyDown(for: .screenMagnifier) { if SCContext.stream != nil { SCContext.isMagnifierEnabled.toggle() }}
KeyboardShortcuts.onKeyDown(for: .stop) { if SCContext.stream != nil { SCContext.stopRecording() }}
Expand Down Expand Up @@ -349,6 +316,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
return
}
}

updateStatusBar()
}

Expand All @@ -357,6 +325,37 @@ class AppDelegate: NSObject, NSApplicationDelegate, SCStreamDelegate, SCStreamOu
if showOnDock { _ = applicationShouldHandleReopen(NSApp, hasVisibleWindows: true) }
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if SCContext.stream == nil {
let w1 = NSApp.windows.filter({ !$0.title.contains("Item-0") && !$0.title.isEmpty && $0.isVisible })
let w2 = w1.filter({ !$0.title.contains(".qma") })
if (!w1.isEmpty && w2.isEmpty) || w1.isEmpty {
let offset = (!showOnDock && !showMenubar) ? 128 : 0
let width = isMacOS12 ? 800 : 927
let mainPanel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: width + offset, height: 100), styleMask: [.fullSizeContentView, .nonactivatingPanel], backing: .buffered, defer: false)
mainPanel.contentView = NSHostingView(rootView: ContentView())
mainPanel.title = "QuickRecorder".local
mainPanel.isOpaque = false
mainPanel.level = .floating
mainPanel.isRestorable = false
mainPanel.backgroundColor = .clear
mainPanel.isReleasedWhenClosed = false
mainPanel.isMovableByWindowBackground = true
mainPanel.collectionBehavior = [.canJoinAllSpaces]
mainPanel.center()
if let screen = mainPanel.screen {
let wX = (screen.frame.width - mainPanel.frame.width) / 2 + screen.frame.minX
let wY = (screen.frame.height - mainPanel.frame.height) / 2 + screen.frame.minY
mainPanel.setFrameOrigin(NSPoint(x: wX, y: wY))
}
mainPanel.orderFront(self)
if #unavailable(macOS 13) { NSApp.activate(ignoringOtherApps: true) }
PopoverState.shared.isShowing = false
}
}
return false
}

func openSettingPanel() {
NSApp.activate(ignoringOtherApps: true)
if #available(macOS 14, *) {
Expand Down
4 changes: 2 additions & 2 deletions QuickRecorder/SCContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class SCContext {
let alert = AppDelegate.shared.createAlert(title: "Permission Required",
message: "QuickRecorder needs permission to record your microphone.",
button1: "Open Settings",
button2: "Quit")
button2: "Cancel")
if alert.runModal() == .alertFirstButtonReturn {
NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone")!)
}
Expand All @@ -250,7 +250,7 @@ class SCContext {
let alert = AppDelegate.shared.createAlert(title: "Permission Required",
message: "QuickRecorder needs screen recording permissions, even if you only intend on recording audio.",
button1: "Open Settings",
button2: "Quit")
button2: "Cancel")
if alert.runModal() == .alertFirstButtonReturn {
NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")!)
}
Expand Down
3 changes: 1 addition & 2 deletions QuickRecorder/ViewModel/AreaSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct resizeView: View {
var screen: SCDisplay!

var body: some View {
VStack(spacing: 10) {
VStack(alignment: .leading, spacing: 10) {
HStack(spacing: 4) {
Text("Area Size:")
TextField("", value: $areaWidth, formatter: NumberFormatter())
Expand Down Expand Up @@ -64,7 +64,6 @@ struct resizeView: View {
Text("Output Size:")
let scale = Int(screen.nsScreen!.backingScaleFactor)
Text(" \(highRes == 2 ? areaWidth * scale : areaWidth) x \(highRes == 2 ? areaHeight * scale : areaHeight)")
Spacer()
}
}.onAppear{ focusedField = .width }
}
Expand Down
Loading

0 comments on commit 82e7de6

Please sign in to comment.