Skip to content

Commit

Permalink
Merge branch 'main' into r10s/fix-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag authored Dec 18, 2024
2 parents b88d75f + 51e19ad commit 81ddc88
Show file tree
Hide file tree
Showing 28 changed files with 922 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:

jobs:
build:
runs-on: macos-14
runs-on: macos-15
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

- Access your most recent Webxdc-apps from the Homescreen using our shiny new widget (#2406)
- Don't show message-input when forwarding (#2435)
- Long-tap links for copying to clipboard (#2445)

## v1.50.3

Expand Down
6 changes: 6 additions & 0 deletions DcWebxdcWidget/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
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 DcWebxdcWidget/Assets.xcassets/checklist.imageset/Contents.json
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 DcWebxdcWidget/Assets.xcassets/hello.imageset/Contents.json
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 DcWebxdcWidget/Assets.xcassets/packabunchas.imageset/Contents.json
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
}
}
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 DcWebxdcWidget/Assets.xcassets/pixel.imageset/Contents.json
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 DcWebxdcWidget/Assets.xcassets/webxdc.imageset/Contents.json
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.
166 changes: 166 additions & 0 deletions DcWebxdcWidget/DcWebxdcWidget.swift
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"))
}
}
9 changes: 9 additions & 0 deletions DcWebxdcWidget/DcWebxdcWidgetBundle.swift
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()
}
}
11 changes: 11 additions & 0 deletions DcWebxdcWidget/Info.plist
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>
Loading

0 comments on commit 81ddc88

Please sign in to comment.