Skip to content

Commit

Permalink
Add EventViewer > ContentMainView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 18, 2023
1 parent fece577 commit 10afec5
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/apps/EventViewer/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AppDelegate: NSObject, NSApplicationDelegate {
defer: false
)
window!.title = "Karabiner-EventViewer"
window!.contentView = NSHostingView(rootView: ContentView(window: window))
window!.contentView = NSHostingView(rootView: ContentView())
window!.center()
window!.makeKeyAndOrderFront(self)

Expand Down
126 changes: 126 additions & 0 deletions src/apps/EventViewer/src/View/ContentMainView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import SwiftUI

enum NavigationTag: String {
case main
case frontmostApplication
case variables
case devices
case systemExtensions
case unknownEvents
case settings
}

struct ContentMainView: View {
@State private var selection: NavigationTag = .main

var body: some View {
VStack {
HStack {
VStack(alignment: .leading, spacing: 0) {
Button(
action: {
selection = .main
},
label: {
SidebarLabelView(text: "Main", systemImage: "magnifyingglass")
}
)
.sidebarButtonStyle(selected: selection == .main)

Button(
action: {
selection = .frontmostApplication
},
label: {
SidebarLabelView(text: "Frontmost Application", systemImage: "triangle.circle")
}
)
.sidebarButtonStyle(selected: selection == .frontmostApplication)

Button(
action: {
selection = .variables
},
label: {
SidebarLabelView(text: "Variables", systemImage: "cube")
}
)
.sidebarButtonStyle(selected: selection == .variables)

Button(
action: {
selection = .devices
},
label: {
SidebarLabelView(text: "Devices", systemImage: "keyboard")
}
)
.sidebarButtonStyle(selected: selection == .devices)

Button(
action: {
selection = .systemExtensions
},
label: {
SidebarLabelView(text: "System Extensions", systemImage: "puzzlepiece")
}
)
.sidebarButtonStyle(selected: selection == .systemExtensions)

Button(
action: {
selection = .unknownEvents
},
label: {
SidebarLabelView(text: "Unknown Events", systemImage: "questionmark.square.dashed")
}
)
.sidebarButtonStyle(selected: selection == .unknownEvents)

Button(
action: {
selection = .settings
},
label: {
SidebarLabelView(text: "Settings", systemImage: "gearshape")
}
)
.sidebarButtonStyle(selected: selection == .settings)

Spacer()
}
.frame(width: 250)

Divider()

switch selection {
case .main:
MainView()
case .frontmostApplication:
FrontmostApplicationView()
case .variables:
VariablesView()
case .devices:
DevicesView()
case .systemExtensions:
SystemExtensionsView()
case .unknownEvents:
UnknownEventsView()
case .settings:
SettingsView()
}
}
}
.frame(
minWidth: 1100,
maxWidth: .infinity,
minHeight: 650,
maxHeight: .infinity)
}
}

struct ContentMainView_Previews: PreviewProvider {
static var previews: some View {
ContentMainView()
}
}
116 changes: 4 additions & 112 deletions src/apps/EventViewer/src/View/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,122 +1,14 @@
import SwiftUI

enum NavigationTag: String {
case main
case frontmostApplication
case variables
case devices
case systemExtensions
case unknownEvents
case settings
}

struct ContentView: View {
let window: NSWindow?

@ObservedObject var inputMonitoringAlertData = InputMonitoringAlertData.shared
@State private var selection: NavigationTag = .main

var body: some View {
VStack {
if inputMonitoringAlertData.showing {
InputMonitoringAlertView(window: window)
} else {
HStack {
VStack(alignment: .leading, spacing: 0) {
Button(
action: {
selection = .main
},
label: {
SidebarLabelView(text: "Main", systemImage: "magnifyingglass")
}
)
.sidebarButtonStyle(selected: selection == .main)

Button(
action: {
selection = .frontmostApplication
},
label: {
SidebarLabelView(text: "Frontmost Application", systemImage: "triangle.circle")
}
)
.sidebarButtonStyle(selected: selection == .frontmostApplication)

Button(
action: {
selection = .variables
},
label: {
SidebarLabelView(text: "Variables", systemImage: "cube")
}
)
.sidebarButtonStyle(selected: selection == .variables)

Button(
action: {
selection = .devices
},
label: {
SidebarLabelView(text: "Devices", systemImage: "keyboard")
}
)
.sidebarButtonStyle(selected: selection == .devices)

Button(
action: {
selection = .systemExtensions
},
label: {
SidebarLabelView(text: "System Extensions", systemImage: "puzzlepiece")
}
)
.sidebarButtonStyle(selected: selection == .systemExtensions)

Button(
action: {
selection = .unknownEvents
},
label: {
SidebarLabelView(text: "Unknown Events", systemImage: "questionmark.square.dashed")
}
)
.sidebarButtonStyle(selected: selection == .unknownEvents)

Button(
action: {
selection = .settings
},
label: {
SidebarLabelView(text: "Settings", systemImage: "gearshape")
}
)
.sidebarButtonStyle(selected: selection == .settings)

Spacer()
}
.frame(width: 250)

Divider()

switch selection {
case .main:
MainView()
case .frontmostApplication:
FrontmostApplicationView()
case .variables:
VariablesView()
case .devices:
DevicesView()
case .systemExtensions:
SystemExtensionsView()
case .unknownEvents:
UnknownEventsView()
case .settings:
SettingsView()
}
ContentMainView()
.alert(isPresented: inputMonitoringAlertData.showing) {
InputMonitoringAlertView()
}
}
}
.frame(
minWidth: 1100,
Expand All @@ -128,6 +20,6 @@ struct ContentView: View {

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(window: nil)
ContentView()
}
}
10 changes: 6 additions & 4 deletions src/apps/EventViewer/src/View/InputMonitoringAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class InputMonitoringAlertData: ObservableObject {
}

struct InputMonitoringAlertView: View {
let window: NSWindow?

var body: some View {
VStack(alignment: .center, spacing: 20.0) {
Label(
Expand All @@ -35,6 +33,10 @@ struct InputMonitoringAlertView: View {
.aspectRatio(contentMode: .fit)
.frame(height: 300.0)
.border(Color.gray, width: 1)

SheetCloseButton {
InputMonitoringAlertData.shared.showing = false
}
}
.frame(width: 800)
.padding()
Expand All @@ -45,14 +47,14 @@ struct InputMonitoringAlertView: View {
string: "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent")!
NSWorkspace.shared.open(url)

window?.orderBack(self)
NSApp.miniaturizeAll(nil)
}
}

struct InputMonitoringAlertView_Previews: PreviewProvider {
static var previews: some View {
Group {
InputMonitoringAlertView(window: nil)
InputMonitoringAlertView()
.previewLayout(.sizeThatFits)
}
}
Expand Down

0 comments on commit 10afec5

Please sign in to comment.