From 300dfda7058962f4835f421d43cb7f79851d68fa Mon Sep 17 00:00:00 2001 From: vgmoose Date: Sat, 30 Oct 2021 01:44:17 -0400 Subject: [PATCH] fix menu bar, more new UI changes --- GlassCon.xcodeproj/project.pbxproj | 4 +++ GlassController/ActionRowView.swift | 19 ++++++++--- GlassController/ContentView.swift | 22 +++++++++---- GlassController/GlassControllerApp.swift | 6 +++- GlassController/GlassDelegate.swift | 42 ++++++++++++++---------- GlassController/Info.plist | 4 +-- glass/GlassPreferences.swift | 33 ++++++++++++------- 7 files changed, 88 insertions(+), 42 deletions(-) diff --git a/GlassCon.xcodeproj/project.pbxproj b/GlassCon.xcodeproj/project.pbxproj index 0269874..2df4a75 100644 --- a/GlassCon.xcodeproj/project.pbxproj +++ b/GlassCon.xcodeproj/project.pbxproj @@ -349,6 +349,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_ASSET_PATHS = "\"GlassController/Preview Content\""; DEVELOPMENT_TEAM = 9UDT7LSCEF; @@ -373,6 +374,7 @@ INFOPLIST_FILE = GlassController/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -426,6 +428,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = "\"GlassController/Preview Content\""; DEVELOPMENT_TEAM = 9UDT7LSCEF; @@ -444,6 +447,7 @@ INFOPLIST_FILE = GlassController/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.1; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = llc.newt.apps.glass; diff --git a/GlassController/ActionRowView.swift b/GlassController/ActionRowView.swift index e0ac842..61bedf2 100644 --- a/GlassController/ActionRowView.swift +++ b/GlassController/ActionRowView.swift @@ -1,20 +1,26 @@ import SwiftUI struct ActionRowView: View { + let action: Action + + init(action: Action) { + self.action = action + } + var body: some View { HStack(alignment: .center) { HStack() { VStack(alignment: .leading) { - Text("5 Finger Swipe Down") + Text(action.activator.toString()) .fontWeight(.bold) .truncationMode(.tail) - Text("Global Gesture (Anywhere)") + Text(action.context.toString()) .font(.caption) .opacity(0.75) .truncationMode(.middle) } Spacer() - Text("⌃⌘⌥M") + Text(action.result.toString()) .font(.system(size: 20)) .frame(minWidth: 100) }.frame(maxWidth: 350) @@ -25,6 +31,11 @@ struct ActionRowView: View { struct ActionRowView_Previews: PreviewProvider { static var previews: some View { - ActionRowView() + ActionRowView( + action: Action( + KeyBinding(10), + Gesture(Gesture.UP, 4) + ) + ) } } diff --git a/GlassController/ContentView.swift b/GlassController/ContentView.swift index 4fa0118..44891e0 100644 --- a/GlassController/ContentView.swift +++ b/GlassController/ContentView.swift @@ -9,11 +9,18 @@ func delete(index: IndexSet) { struct ContentView: View { var body: some View { Text("This app allows you to configure different actions (such as key bindings) depending on gestures/input from the touchpad.").padding() - Button(action: { - print("ello") - }) { - Text("License") - }.padding() + HStack { + Button(action: { + GlassDelegate.glassView!.showGlass() + }) { + Text("Touchpad Preview") + }.padding() + Button(action: { + NSWorkspace.shared.open(URL(string: "https://github.com/vgmoose/GlassController")!) + }) { + Text("Source Code") + }.padding() + } HStack() { Text("Select Profile") // Dropdown(["hi", "no"]) @@ -23,7 +30,10 @@ struct ContentView: View { .bold() ScrollView(.horizontal) { ForEach(food, id: \.self) { data in - ActionRowView().padding() + ActionRowView(action: Action( + KeyBinding(10), + Gesture(Gesture.UP, 4) + )).padding() } } .padding() diff --git a/GlassController/GlassControllerApp.swift b/GlassController/GlassControllerApp.swift index 6e0594f..79c3cb6 100644 --- a/GlassController/GlassControllerApp.swift +++ b/GlassController/GlassControllerApp.swift @@ -5,7 +5,11 @@ struct GlassControllerApp: App { @NSApplicationDelegateAdaptor(GlassDelegate.self) var appDelegate var body: some Scene { WindowGroup { - ContentView() + ZStack { + EmptyView() + } + .hidden() +// ContentView() } } } diff --git a/GlassController/GlassDelegate.swift b/GlassController/GlassDelegate.swift index 58857cd..66c3166 100644 --- a/GlassController/GlassDelegate.swift +++ b/GlassController/GlassDelegate.swift @@ -22,6 +22,7 @@ class GlassDelegate : NSObject, NSApplicationDelegate var glassEnabled = true var menuBar: NSMenu? + var statusItem: NSStatusItem? override init(){ super.init() @@ -51,12 +52,17 @@ class GlassDelegate : NSObject, NSApplicationDelegate func showPreviewWindow() { - // window already being displayed, return - if previewWindow != nil { return } + // window already created, show it + if let pw = previewWindow { + pw.makeKeyAndOrderFront(nil) + return + } let window = NSWindow(contentRect: frameRect, styleMask: [.titled, .closable], backing: .buffered, defer: false) previewWindow = window; + window.isReleasedWhenClosed = false + view!.isHidden = false view!.needsDisplay = true window.contentView = view! @@ -78,7 +84,7 @@ class GlassDelegate : NSObject, NSApplicationDelegate func setupMenuBar() { - menuBar = NSMenu() + menuBar = NSApplication.shared.mainMenu let appMenuItem = NSMenuItem() menuBar!.addItem(appMenuItem) @@ -86,7 +92,7 @@ class GlassDelegate : NSObject, NSApplicationDelegate enabledMenuButton.state = getActivationState() enabledMenuButton.target = GlassPreferences.self appMenu.addItem(enabledMenuButton) - + let preferencesButton = NSMenuItem(title: "Preferences", action: #selector(GlassPreferences.showConfigWindow), keyEquivalent: "") preferencesButton.target = GlassPreferences.self appMenu.addItem(preferencesButton) @@ -94,35 +100,37 @@ class GlassDelegate : NSObject, NSApplicationDelegate // let previewButton = NSMenuItem(title: "Touchpad Preview", action: #selector(glassView.showGlass), keyEquivalent: "") // previewButton.target = glassView // appMenu.addItem(previewButton) - + appMenu.addItem(NSMenuItem.separator()) - + let selectors = [#selector(GlassPreferences.switchProfile1), #selector(GlassPreferences.switchProfile2), #selector(GlassPreferences.switchProfile3)] - + for x in 0..<3 { let item = NSMenuItem(title: GlassPreferences.slotNames[x], action: selectors[x], keyEquivalent: "") item.target = GlassPreferences.self profileItems.append(item) appMenu.addItem(item) } - + appMenu.addItem(NSMenuItem.separator()) - - + + let item = NSMenuItem(title: "Restart", action: #selector(GlassPreferences.restartListeners), keyEquivalent: "") item.target = GlassPreferences.self appMenu.addItem(item) - + appMenu.addItem(NSMenuItem(title: "Quit", action: Selector("terminate:"), keyEquivalent: "")) - + appMenuItem.submenu = appMenu - let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) - statusItem.button!.title = "🔳" - statusItem.button!.sizeToFit() - statusItem.menu = appMenu + statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) + statusItem!.button!.title = "🔳" + statusItem!.button!.sizeToFit() + statusItem!.isVisible = true + statusItem!.menu = appMenu + } func applicationDidFinishLaunching(_ notification: Notification) @@ -139,6 +147,6 @@ class GlassDelegate : NSObject, NSApplicationDelegate NSApp.activate(ignoringOtherApps: true) // hide the dock icon (same as LSUIElement true in Info.plist) -// NSApp.setActivationPolicy(.accessory) + NSApp.setActivationPolicy(.accessory) } } diff --git a/GlassController/Info.plist b/GlassController/Info.plist index 7c49390..6ba8cf0 100644 --- a/GlassController/Info.plist +++ b/GlassController/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) LSApplicationCategoryType public.app-category.productivity LSMinimumSystemVersion diff --git a/glass/GlassPreferences.swift b/glass/GlassPreferences.swift index fdf87d8..28de477 100644 --- a/glass/GlassPreferences.swift +++ b/glass/GlassPreferences.swift @@ -81,17 +81,17 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource inner.addSubview(importB) // the + and - buttons for actions - let controls = NSSegmentedControl() - controls.frame = NSMakeRect(0, 0, 100, 30) - controls.frame.origin = CGPoint(x: 5, y: 70) - controls.segmentCount = 2 - controls.setLabel("+", forSegment: 0) - controls.setLabel("-", forSegment: 1) - controls.segmentStyle = .smallSquare - if #available(OSX 10.10.3, *) { - controls.trackingMode = .momentary - } - inner.addSubview(controls) +// let controls = NSSegmentedControl() +// controls.frame = NSMakeRect(0, 0, 100, 30) +// controls.frame.origin = CGPoint(x: 5, y: 70) +// controls.segmentCount = 2 +// controls.setLabel("+", forSegment: 0) +// controls.setLabel("-", forSegment: 1) +// controls.segmentStyle = .smallSquare +// if #available(OSX 10.10.3, *) { +// controls.trackingMode = .momentary +// } +// inner.addSubview(controls) // the current regions on the touchpad and action mappings let tableContainer = NSScrollView(frame:NSMakeRect(0, 0, WIDTH, HEIGHT-100)) @@ -114,13 +114,21 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource func numberOfRows(in tableView: NSTableView) -> Int { - return glassDelegate.view!.actions.count; + let count = glassDelegate.view!.actions.count + if count == 0 { + return 1 + } + return count } func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { + let count = glassDelegate.view!.actions.count + if count == 0 { + return "No actions exist in this profile. See the Readme for more information." + } return glassDelegate.view!.actions[row].getValue((tableColumn?.identifier)!.rawValue) } @@ -137,6 +145,7 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource @objc static func showConfigWindow() { let window = GlassPreferences(GlassDelegate.singleton!) + window.isReleasedWhenClosed = false window.cascadeTopLeft(from: NSMakePoint(20, 20)) window.title = "GlassCon Preferences" window.makeKeyAndOrderFront(nil)