mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
Compare commits
4 Commits
5651c0f329
...
9a44d9e3a1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a44d9e3a1 | ||
|
|
17026e40db | ||
|
|
bd1ef3439e | ||
|
|
537759497a |
@ -26,6 +26,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
// ciphertext 需要放在最前面,有可能所有的推送数据都在密文里
|
||||
let processors: [NotificationContentProcessorItem] = [
|
||||
.ciphertext,
|
||||
.markdown,
|
||||
.level,
|
||||
.badge,
|
||||
.autoCopy,
|
||||
@ -33,7 +34,6 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
.setIcon,
|
||||
.setImage,
|
||||
.mute,
|
||||
.markdown,
|
||||
.call
|
||||
]
|
||||
|
||||
|
||||
@ -10,11 +10,6 @@ import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class ArchiveProcessor: NotificationContentProcessor {
|
||||
private lazy var realm: Realm? = {
|
||||
Realm.Configuration.defaultConfiguration = kRealmDefaultConfiguration
|
||||
return try? Realm()
|
||||
}()
|
||||
|
||||
func process(identifier: String, content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
|
||||
let userInfo = bestAttemptContent.userInfo
|
||||
|
||||
@ -34,23 +29,28 @@ class ArchiveProcessor: NotificationContentProcessor {
|
||||
let id = userInfo["id"] as? String
|
||||
let markdown = userInfo["markdown"] as? String
|
||||
|
||||
try? realm?.write {
|
||||
let message = Message()
|
||||
if let id, !id.isEmpty {
|
||||
message.id = id
|
||||
if let realm = {
|
||||
Realm.Configuration.defaultConfiguration = kRealmDefaultConfiguration
|
||||
return try? Realm()
|
||||
}() {
|
||||
try? realm.write {
|
||||
let message = Message()
|
||||
if let id, !id.isEmpty {
|
||||
message.id = id
|
||||
}
|
||||
message.title = title
|
||||
message.subtitle = subtitle
|
||||
message.body = body
|
||||
if let markdown, !markdown.isEmpty {
|
||||
message.body = markdown
|
||||
message.bodyType = Message.BodyType.markdown.rawValue
|
||||
}
|
||||
message.url = url
|
||||
message.image = image
|
||||
message.group = group
|
||||
message.createDate = Date()
|
||||
realm.add(message, update: .all)
|
||||
}
|
||||
message.title = title
|
||||
message.subtitle = subtitle
|
||||
message.body = body
|
||||
if let markdown, !markdown.isEmpty {
|
||||
message.body = markdown
|
||||
message.bodyType = Message.BodyType.markdown.rawValue
|
||||
}
|
||||
message.url = url
|
||||
message.image = image
|
||||
message.group = group
|
||||
message.createDate = Date()
|
||||
realm?.add(message, update: .all)
|
||||
}
|
||||
}
|
||||
return bestAttemptContent
|
||||
|
||||
@ -29,6 +29,14 @@ class MarkdownProcessor: NotificationContentProcessor {
|
||||
// 将 body 中的多个\n替换为单个\n,避免空行太多内容显示不完整。
|
||||
.replacingOccurrences(of: "\n\n+", with: "\n", options: .regularExpression)
|
||||
bestAttemptContent.body = body
|
||||
|
||||
/// 更新 APS 字段, 供之后的 Porgressor 使用
|
||||
var aps = userInfo["aps"] as? [String: Any] ?? [:]
|
||||
var alert = aps["alert"] as? [String: Any] ?? [:]
|
||||
alert["body"] = body
|
||||
aps["alert"] = alert
|
||||
bestAttemptContent.userInfo["aps"] = aps
|
||||
|
||||
return bestAttemptContent
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,4 +31,9 @@
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
|
||||
</body>
|
||||
|
||||
<!-- Cloudflare Web Analytics -->
|
||||
<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
|
||||
data-cf-beacon='{"token": "6ad048c5cd404e309d826a089e2826f1"}'></script>
|
||||
<!-- End Cloudflare Web Analytics -->
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user