Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
ethanndickson merged 2 commits intomainfromethan/push-notif
May 12, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletionsCoder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
import FluidMenuBarExtra
import NetworkExtension
import os
import SDWebImageSVGCoder
import SDWebImageSwiftUI
import SwiftUI
import UserNotifications
import VPNLib

@main
Expand DownExpand Up@@ -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 = {
Expand All@@ -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) {
Expand DownExpand Up@@ -141,9 +148,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// We only accept one at time, for now
return
}
do { try urlHandler.handle(url) } catch {
// TODO: Push notification
print(error.description)
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)")
}
}
}
}

Expand Down
28 changes: 28 additions & 0 deletionsCoder-Desktop/Coder-Desktop/Notifications.swift
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
settings:
base:
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon # Sets the app icon to "AppIcon".
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp