Skip to content

Commit

Permalink
To-Do Widget – Url Scheme PoC (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
navtoj authored Oct 17, 2024
1 parent 7557bbe commit 3d16d42
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
54 changes: 54 additions & 0 deletions src/NotchBar/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

// set item icon

#if DEBUG
button.image = NSImage(systemSymbol: .sparkles)
#else
button.image = NSImage(systemSymbol: .sparkle)
#endif

// set item action

Expand Down Expand Up @@ -82,6 +86,56 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
window.orderFrontRegardless()
}

// To-Do URL Scheme

func application(_ application: NSApplication, open urls: [URL]) {
for url in urls {

// Process URL

guard let scheme = url.scheme else { return print("Invalid URL scheme.") }
#if DEBUG
print("scheme :", scheme) // notchbar
#endif

guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let path = components.path,
let params = components.queryItems else {
return print("Invalid URL path or params missing.")
}
#if DEBUG
print("path :", path) // todo
print("params :", params) // set=a todo item
#endif

// Validate Path

guard path == "todo" else { return print("Unknown URL Path:", path) }

// Process Params

for param in params {
guard let key = param.name as String?,
let value = param.value as String? else {
return print("Invalid URL Param:", param)
}
#if DEBUG
print("key :", key) // set
print("value :", value) // a todo item
#endif

// Handle Params

switch key {
case "set":
AppState.shared.setTodo(to: value)
default:
print("Unknown URL Param:", key)
}
}
}
}

func applicationWillTerminate(_ notification: Notification) {}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { false }
Expand Down
5 changes: 5 additions & 0 deletions src/NotchBar/Sources/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ final class AppState {
self.card = self.card == card ? nil : card
}

private(set) var todo: String = ""
func setTodo(to value: String) {
todo = value
}

// disallow direct instantiation

private init() {}
Expand Down
32 changes: 21 additions & 11 deletions src/NotchBar/Sources/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,33 @@ struct AppView: View {
// Widgets - Right

HStack {
WidgetView(
primary: MediaPrimary.init,
secondary: MediaSecondary.init,
overlay: .leading
)
HStack {
WidgetView(
primary: MediaPrimary.init,
secondary: MediaSecondary.init,
overlay: .leading
)

// Todo Widget Override

if !AppState.shared.todo.isEmpty {
Text(AppState.shared.todo)
.lineLimit(1)
} else {
WidgetView<ActiveAppPrimary, Never>(primary: ActiveAppPrimary.init)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
WidgetView<ActiveAppPrimary, Never>(primary: ActiveAppPrimary.init)
}
#if DEBUG
.border(.red)
.border(.green)
#endif
.frame(maxWidth: notch.minX, alignment: .trailing)
.frame(maxWidth: .infinity, alignment: .trailing)
#if DEBUG
.border(.blue)
.border(.yellow)
#endif
}
// .border(.red)
.frame(maxWidth: notch.minX, alignment: .leading)
// .border(.blue)
}
.frame(maxWidth: .infinity, maxHeight: NSScreen.builtIn.notch?.height ?? 31.5)
.padding(.horizontal)
Expand Down
11 changes: 9 additions & 2 deletions src/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ let project = Project(
name: "NotchBar",
destinations: .macOS,
product: .app,
bundleId: "com.navtoj.NotchBar",
bundleId: "com.navtoj.notchbar",
deploymentTargets: .macOS("14.6.1"),
infoPlist: .extendingDefault(with: [
"LSUIElement": true,
"LSApplicationCategoryType": "public.app-category.productivity",
"CFBundleShortVersionString": "0.0.3", // Public
"CFBundleVersion": "0", // Internal
"CFBundleVersion": "1", // Internal
"CFBundleURLTypes": .array([
.dictionary([
"CFBundleURLName": .string("com.navtoj.notchbar"),
"CFBundleURLSchemes": .array(["notchbar"]),
"CFBundleTypeRole": .string("Viewer"),
]),
]),
]),
sources: ["NotchBar/Sources/**"],
resources: ["NotchBar/Resources/**"],
Expand Down

0 comments on commit 3d16d42

Please sign in to comment.