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

Commit2198d3e

Browse files
feat: send push notifications for invalidcoder scheme URIs (#146)
Relates to#96.<img width="380" alt="image" src="https://github.com/user-attachments/assets/36316e23-ba6e-40f0-ba4d-228dd9c31006" /><img width="369" alt="image" src="https://github.com/user-attachments/assets/d9ff0c21-c4c7-485a-8767-ca1772ebecbf" />I've had to replace the **app** provisioning profile for this to build.
1 parent0cf2f28 commit2198d3e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

‎Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import FluidMenuBarExtra
22
import NetworkExtension
3+
import os
34
import SDWebImageSVGCoder
45
import SDWebImageSwiftUI
56
import SwiftUI
7+
import UserNotifications
68
import VPNLib
79

810
@main
@@ -36,13 +38,16 @@ struct DesktopApp: App {
3638

3739
@MainActor
3840
classAppDelegate:NSObject,NSApplicationDelegate{
41+
privatevarlogger=Logger(subsystem:Bundle.main.bundleIdentifier!, category:"app-delegate")
3942
privatevarmenuBar:MenuBarController?
4043
letvpn:CoderVPNService
4144
letstate:AppState
4245
letfileSyncDaemon:MutagenDaemon
4346
leturlHandler:URLHandler
47+
letnotifDelegate:NotifDelegate
4448

4549
overrideinit(){
50+
notifDelegate=NotifDelegate()
4651
vpn=CoderVPNService()
4752
letstate=AppState(onChange: vpn.configureTunnelProviderProtocol)
4853
vpn.onStart={
@@ -67,6 +72,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6772
}
6873
self.fileSyncDaemon= fileSyncDaemon
6974
urlHandler=URLHandler(state: state, vpn: vpn)
75+
// `delegate` is weak
76+
UNUserNotificationCenter.current().delegate= notifDelegate
7077
}
7178

7279
func applicationDidFinishLaunching(_:Notification){
@@ -141,9 +148,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
141148
// We only accept one at time, for now
142149
return
143150
}
144-
do{try urlHandler.handle(url)}catch{
145-
// TODO: Push notification
146-
print(error.description)
151+
do{try urlHandler.handle(url)}catchlet handleError{
152+
Task{
153+
do{
154+
tryawaitsendNotification(title:"Failed to handle link", body: handleError.description)
155+
}catchlet notifError{
156+
logger.error("Failed to send notification (\(handleError.description)):\(notifError)")
157+
}
158+
}
147159
}
148160
}
149161

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import UserNotifications
2+
3+
classNotifDelegate:NSObject,UNUserNotificationCenterDelegate{
4+
overrideinit(){
5+
super.init()
6+
}
7+
8+
// This function is required for notifications to appear as banners whilst the app is running.
9+
// We're effectively forwarding the notification back to the OS
10+
nonisolatedfunc userNotificationCenter(
11+
_:UNUserNotificationCenter,
12+
willPresent _:UNNotification
13+
)async->UNNotificationPresentationOptions{
14+
[.banner]
15+
}
16+
}
17+
18+
func sendNotification(title:String, body:String)asyncthrows{
19+
letnc=UNUserNotificationCenter.current()
20+
letgranted=tryawait nc.requestAuthorization(options:[.alert,.badge])
21+
guard grantedelse{
22+
return
23+
}
24+
letcontent=UNMutableNotificationContent()
25+
content.title= title
26+
content.body= body
27+
tryawait nc.add(.init(identifier:UUID().uuidString, content: content, trigger:nil))
28+
}

‎Coder-Desktop/project.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ targets:
147147
com.apple.developer.system-extension.install:true
148148
com.apple.security.application-groups:
149149
-$(TeamIdentifierPrefix)com.coder.Coder-Desktop
150+
aps-environment:development
150151
settings:
151152
base:
152153
ASSETCATALOG_COMPILER_APPICON_NAME:AppIcon# Sets the app icon to "AppIcon".

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp