-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into r10s/fix-warnings
- Loading branch information
Showing
28 changed files
with
922 additions
and
302 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
|
||
jobs: | ||
build: | ||
runs-on: macos-14 | ||
runs-on: macos-15 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
|
This file contains 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
This file contains 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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
DcWebxdcWidget/Assets.xcassets/WidgetBackground.colorset/Contents.json
This file contains 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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
DcWebxdcWidget/Assets.xcassets/checklist.imageset/Contents.json
This file contains 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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "checklist.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
DcWebxdcWidget/Assets.xcassets/hello.imageset/Contents.json
This file contains 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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "hello.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
DcWebxdcWidget/Assets.xcassets/packabunchas.imageset/Contents.json
This file contains 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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "packabunchas.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+4.38 KB
DcWebxdcWidget/Assets.xcassets/packabunchas.imageset/packabunchas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
DcWebxdcWidget/Assets.xcassets/pixel.imageset/Contents.json
This file contains 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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "pixel.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
DcWebxdcWidget/Assets.xcassets/webxdc.imageset/Contents.json
This file contains 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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "webxdc.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,166 @@ | ||
import WidgetKit | ||
import SwiftUI | ||
import DcCore | ||
|
||
struct Provider: TimelineProvider { | ||
func placeholder(in context: Context) -> UsedWebxdcEntry { | ||
let limit: Int | ||
switch context.family { | ||
case .systemSmall: | ||
limit = 4 | ||
case .systemMedium: | ||
limit = 7 | ||
default: | ||
limit = 7 | ||
} | ||
|
||
let apps = [ | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 0, image: UIImage(named: "checklist"), title: "checklist"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 1, image: UIImage(named: "hello"), title: "hello"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 6, image: UIImage(named: "packabunchas"), title: "packabunchas"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 3, image: UIImage(named: "webxdc"), title: "webxdc"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 2, image: UIImage(named: "pixel"), title: "pixel"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 4, image: UIImage(named: "checklist"), title: "checklist"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 5, image: UIImage(named: "hello"), title: "hello"), | ||
WebxdcApp(accountId: 0, chatId: 0, messageId: 7, image: UIImage(named: "webxdc"), title: "webxdc"), | ||
] | ||
|
||
return UsedWebxdcEntry(date: Date(), apps: Array(apps.prefix(limit))) | ||
} | ||
|
||
func getSnapshot(in context: Context, completion: @escaping (UsedWebxdcEntry) -> Void) { | ||
let entry = placeholder(in: context) | ||
completion(entry) | ||
} | ||
|
||
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { | ||
/// ---------------------------------- | ||
/// **DO NOT** start dcAccounts.startIo() in widget. | ||
/// This works only for one process, and widgets may run concurrently to the main app in their own process. | ||
/// ---------------------------------- | ||
let dcAccounts = DcAccounts.shared | ||
dcAccounts.openDatabase(writeable: false) | ||
let dcContext = dcAccounts.getSelected() | ||
let chatId = 0 | ||
let ignore = Int32(0) | ||
|
||
let limit: Int | ||
switch context.family { | ||
case .systemSmall: limit = 4 | ||
case .systemMedium: limit = 8 | ||
default: limit = 8 | ||
} | ||
|
||
let messageIds: [Int] = Array(dcContext.getChatMedia(chatId: chatId, messageType: DC_MSG_WEBXDC, messageType2: ignore, messageType3: ignore).reversed().prefix(limit)) | ||
|
||
let apps = messageIds.compactMap { | ||
dcContext.getMessage(id: $0) | ||
}.compactMap { msg in | ||
let name = msg.getWebxdcAppName() | ||
let image = msg.getWebxdcPreviewImage() | ||
let accountId = dcContext.id | ||
let chatId = msg.chatId | ||
|
||
return WebxdcApp( | ||
accountId: accountId, | ||
chatId: chatId, | ||
messageId: msg.id, | ||
image: image, | ||
title: name | ||
) | ||
} | ||
|
||
let currentDate = Date() | ||
let entry = UsedWebxdcEntry(date: currentDate, apps: apps) | ||
let nextDate = Calendar.current.date(byAdding: .minute, value: 15, to: currentDate)! | ||
|
||
let timeline = Timeline(entries: [entry], policy: .after(nextDate)) | ||
completion(timeline) | ||
} | ||
} | ||
|
||
struct UsedWebxdcEntry: TimelineEntry { | ||
|
||
let date: Date | ||
let apps: [WebxdcApp] | ||
} | ||
|
||
struct WebxdcApp: Hashable, Identifiable { | ||
var id: Int { messageId } | ||
|
||
let accountId: Int | ||
let chatId: Int | ||
let messageId: Int | ||
|
||
let image: UIImage? | ||
let title: String | ||
|
||
var url: URL { | ||
var urlComponents = URLComponents() | ||
urlComponents.scheme = "chat.delta.deeplink" | ||
urlComponents.host = "webxdc" | ||
urlComponents.queryItems = [ | ||
URLQueryItem(name: "msgId", value: "\(messageId)"), | ||
URLQueryItem(name: "chatId", value: "\(chatId)"), | ||
URLQueryItem(name: "accountId", value: "\(accountId)"), | ||
] | ||
|
||
return urlComponents.url! | ||
} | ||
} | ||
|
||
struct DcWebxdcWidgetEntryView: View { | ||
var entry: Provider.Entry | ||
|
||
var body: some View { | ||
if entry.apps.isEmpty { | ||
Text(String.localized("widget_no_apps")) | ||
} else { | ||
let rows = [GridItem(.fixed(56)), GridItem(.fixed(56))] | ||
LazyHGrid(rows: rows) { | ||
ForEach(entry.apps) { app in | ||
WebXDCAppView(app: app).accessibilityLabel(Text(app.title)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct WebXDCAppView: View { | ||
var app: WebxdcApp | ||
|
||
var body: some View { | ||
Link(destination: app.url) { | ||
if let image = app.image { | ||
Image(uiImage: image) | ||
.resizable() | ||
.frame(width: 56, height: 56) | ||
.cornerRadius(12) | ||
} else { | ||
Color(.systemBackground) | ||
.frame(width: 56, height: 56) | ||
.cornerRadius(12) | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct DcWebxdcWidget: Widget { | ||
let kind: String = "DcWebxdcWidget" | ||
|
||
var body: some WidgetConfiguration { | ||
StaticConfiguration(kind: kind, provider: Provider()) { entry in | ||
if #available(iOS 17.0, *) { | ||
DcWebxdcWidgetEntryView(entry: entry) | ||
.containerBackground(.fill.tertiary, for: .widget) | ||
} else { | ||
DcWebxdcWidgetEntryView(entry: entry) | ||
.padding() | ||
.background() | ||
} | ||
} | ||
.supportedFamilies([.systemSmall, .systemMedium]) | ||
.configurationDisplayName(String.localized("widget_most_recent_apps_title")) | ||
.description(String.localized("widget_most_recent_apps_description")) | ||
} | ||
} |
This file contains 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,9 @@ | ||
import WidgetKit | ||
import SwiftUI | ||
|
||
@main | ||
struct DcWebxdcWidgetBundle: WidgetBundle { | ||
var body: some Widget { | ||
DcWebxdcWidget() | ||
} | ||
} |
This file contains 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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.widgetkit-extension</string> | ||
</dict> | ||
</dict> | ||
</plist> |
Oops, something went wrong.