- Notifications
You must be signed in to change notification settings - Fork3
feat: send push notifications for invalidcoder
scheme URIs#146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 15 additions & 3 deletionsCoder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import FluidMenuBarExtra | ||
import NetworkExtension | ||
import os | ||
import SDWebImageSVGCoder | ||
import SDWebImageSwiftUI | ||
import SwiftUI | ||
import UserNotifications | ||
import VPNLib | ||
@main | ||
@@ -36,13 +38,16 @@ struct DesktopApp: App { | ||
@MainActor | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
private var logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "app-delegate") | ||
private var menuBar: MenuBarController? | ||
let vpn: CoderVPNService | ||
let state: AppState | ||
let fileSyncDaemon: MutagenDaemon | ||
let urlHandler: URLHandler | ||
let notifDelegate: NotifDelegate | ||
override init() { | ||
notifDelegate = NotifDelegate() | ||
vpn = CoderVPNService() | ||
let state = AppState(onChange: vpn.configureTunnelProviderProtocol) | ||
vpn.onStart = { | ||
@@ -67,6 +72,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { | ||
} | ||
self.fileSyncDaemon = fileSyncDaemon | ||
urlHandler = URLHandler(state: state, vpn: vpn) | ||
// `delegate` is weak | ||
UNUserNotificationCenter.current().delegate = notifDelegate | ||
} | ||
func applicationDidFinishLaunching(_: Notification) { | ||
@@ -141,9 +148,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { | ||
// We only accept one at time, for now | ||
return | ||
} | ||
do { try urlHandler.handle(url) } catch let handleError { | ||
Task { | ||
do { | ||
try await sendNotification(title: "Failed to handle link", body: handleError.description) | ||
} catch let notifError { | ||
logger.error("Failed to send notification (\(handleError.description)): \(notifError)") | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
} | ||
} | ||
} | ||
28 changes: 28 additions & 0 deletionsCoder-Desktop/Coder-Desktop/Notifications.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import UserNotifications | ||
class NotifDelegate: NSObject, UNUserNotificationCenterDelegate { | ||
override init() { | ||
super.init() | ||
} | ||
// This function is required for notifications to appear as banners whilst the app is running. | ||
// We're effectively forwarding the notification back to the OS | ||
nonisolated func userNotificationCenter( | ||
_: UNUserNotificationCenter, | ||
willPresent _: UNNotification | ||
) async -> UNNotificationPresentationOptions { | ||
[.banner] | ||
} | ||
} | ||
func sendNotification(title: String, body: String) async throws { | ||
let nc = UNUserNotificationCenter.current() | ||
let granted = try await nc.requestAuthorization(options: [.alert, .badge]) | ||
guard granted else { | ||
return | ||
} | ||
let content = UNMutableNotificationContent() | ||
content.title = title | ||
content.body = body | ||
try await nc.add(.init(identifier: UUID().uuidString, content: content, trigger: nil)) | ||
} |
1 change: 1 addition & 0 deletionsCoder-Desktop/project.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -147,6 +147,7 @@ targets: | ||
com.apple.developer.system-extension.install: true | ||
com.apple.security.application-groups: | ||
- $(TeamIdentifierPrefix)com.coder.Coder-Desktop | ||
aps-environment: development | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
settings: | ||
base: | ||
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon # Sets the app icon to "AppIcon". | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.