From 51d126c09b69410b6d934a44c9baf9431522f882 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 12 Dec 2024 16:22:31 +0100 Subject: [PATCH] Add/retrieve Widget-Entries from Core (#2426) --- deltachat-ios.xcodeproj/project.pbxproj | 16 +++++++++++++++ deltachat-ios/DC/DcContext+Extension.swift | 24 ++++++++++++++++++++++ deltachat-ios/DC/DcContext.swift | 4 ++-- deltachat-ios/Model/WidgetEntry.swift | 6 ++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 deltachat-ios/DC/DcContext+Extension.swift create mode 100644 deltachat-ios/Model/WidgetEntry.swift diff --git a/deltachat-ios.xcodeproj/project.pbxproj b/deltachat-ios.xcodeproj/project.pbxproj index 34af36b5e..c47876aaa 100644 --- a/deltachat-ios.xcodeproj/project.pbxproj +++ b/deltachat-ios.xcodeproj/project.pbxproj @@ -223,6 +223,12 @@ D878C4FF2CF72AA0009AF551 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D878C4FE2CF72AA0009AF551 /* SwiftUI.framework */; }; D878C50C2CF72AA1009AF551 /* DcWebxdcWidget.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = D878C4FB2CF72AA0009AF551 /* DcWebxdcWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; D87C64672D01E4EF004472D6 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3060119E22DDE24000C1CE6F /* Localizable.strings */; }; + D89C456D2D0AF6A8005B1491 /* WidgetEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456C2D0AF6A8005B1491 /* WidgetEntry.swift */; }; + D89C456F2D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456E2D0AF7A5005B1491 /* DcContext+Extension.swift */; }; + D89C45702D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456E2D0AF7A5005B1491 /* DcContext+Extension.swift */; }; + D89C45712D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456E2D0AF7A5005B1491 /* DcContext+Extension.swift */; }; + D89C45722D0B0166005B1491 /* WidgetEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456C2D0AF6A8005B1491 /* WidgetEntry.swift */; }; + D89C45732D0B0166005B1491 /* WidgetEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89C456C2D0AF6A8005B1491 /* WidgetEntry.swift */; }; D8A072A02BED0FD8001A4C7C /* InstantOnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A0729F2BED0FD8001A4C7C /* InstantOnboardingView.swift */; }; D8C19DCE2C1B456700B32F6D /* SendContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C19DCD2C1B456700B32F6D /* SendContactViewController.swift */; }; D8C19DD02C1C9FFE00B32F6D /* ContactCardPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C19DCF2C1C95A900B32F6D /* ContactCardPreview.swift */; }; @@ -636,6 +642,8 @@ D878C4FB2CF72AA0009AF551 /* DcWebxdcWidget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = DcWebxdcWidget.appex; sourceTree = BUILT_PRODUCTS_DIR; }; D878C4FC2CF72AA0009AF551 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; }; D878C4FE2CF72AA0009AF551 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; }; + D89C456C2D0AF6A8005B1491 /* WidgetEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetEntry.swift; sourceTree = ""; }; + D89C456E2D0AF7A5005B1491 /* DcContext+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DcContext+Extension.swift"; sourceTree = ""; }; D8A0729F2BED0FD8001A4C7C /* InstantOnboardingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantOnboardingView.swift; sourceTree = ""; }; D8C19DCD2C1B456700B32F6D /* SendContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendContactViewController.swift; sourceTree = ""; }; D8C19DCF2C1C95A900B32F6D /* ContactCardPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactCardPreview.swift; sourceTree = ""; }; @@ -707,6 +715,7 @@ isa = PBXGroup; children = ( 304219D82440734A00516852 /* DcMsg+Extension.swift */, + D89C456E2D0AF7A5005B1491 /* DcContext+Extension.swift */, ); path = DC; sourceTree = ""; @@ -1018,6 +1027,7 @@ isa = PBXGroup; children = ( AE57C07F2552BBD0003CFE70 /* GalleryItem.swift */, + D89C456C2D0AF6A8005B1491 /* WidgetEntry.swift */, ); path = Model; sourceTree = ""; @@ -1617,6 +1627,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D89C45712D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */, 30C7D5F128F4808C0078D24C /* MessageCounter.swift in Sources */, 30C7D5F028F47F4F0078D24C /* InitialsBadge.swift in Sources */, 3057027F24C5B2F800D84EFC /* ChatListViewModel.swift in Sources */, @@ -1630,6 +1641,7 @@ 309D14DA28F482D300F7BA29 /* NSAttributedString+Extensions.swift in Sources */, 30E8F2132447285600CE2C90 /* ShareViewController.swift in Sources */, 30B2BD02278F1C1900889AA4 /* KeychainManager.swift in Sources */, + D89C45722D0B0166005B1491 /* WidgetEntry.swift in Sources */, 30152C9A25A5D92200377714 /* DetectorType.swift in Sources */, 30152CA025A5D97900377714 /* UIEdgeInsets+Extensions.swift in Sources */, 3067AAC72667F3FE00525036 /* ImageFormat.swift in Sources */, @@ -1673,6 +1685,7 @@ 3080A022277DE09900E74565 /* InputTextView.swift in Sources */, 30734326249A280B00BF9AD1 /* MediaQualityViewController.swift in Sources */, 3080A01C277DDB8A00E74565 /* InputBarAccessoryViewDelegate.swift in Sources */, + D89C456D2D0AF6A8005B1491 /* WidgetEntry.swift in Sources */, 30FDB70524D1C1000066C48D /* ChatViewController.swift in Sources */, 3080A013277DDABA00E74565 /* KeyboardNotification.swift in Sources */, AE52EA20229EB9F000C586C9 /* EditGroupViewController.swift in Sources */, @@ -1694,6 +1707,7 @@ 30F4E2942859213400ACA0D8 /* ChatListEditingBar.swift in Sources */, AE57C0802552BBD0003CFE70 /* GalleryItem.swift in Sources */, AE25F09022807AD800CDEA66 /* AvatarSelectionCell.swift in Sources */, + D89C456F2D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */, 30DDCBE928FCA1FA00465D22 /* PartialScreenPresentationController.swift in Sources */, 30A4149724F6EFBE00EC91EB /* InfoMessageCell.swift in Sources */, 302B84C6239676F0001C261F /* AvatarHelper.swift in Sources */, @@ -1836,6 +1850,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D89C45732D0B0166005B1491 /* WidgetEntry.swift in Sources */, + D89C45702D0AF7A5005B1491 /* DcContext+Extension.swift in Sources */, D8C7B6982CF87F5E003A6AD1 /* DcMsg+Extension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/deltachat-ios/DC/DcContext+Extension.swift b/deltachat-ios/DC/DcContext+Extension.swift new file mode 100644 index 000000000..66e7ffaea --- /dev/null +++ b/deltachat-ios/DC/DcContext+Extension.swift @@ -0,0 +1,24 @@ +import Foundation +import DcCore + +extension DcContext { + private static let key = "ui.ios.selected_apps_for_widget" + func shownWidgets() -> [WidgetEntry] { + guard let jsonData = getConfig(Self.key)?.data(using: .utf8) else { return [] } + + do { + let widgets = try JSONDecoder().decode([WidgetEntry].self, from: jsonData) + return widgets + } catch { + return [] + } + } + + func storeShownWidgets(_ widgets: [WidgetEntry]) { + guard let jsonData = try? JSONEncoder().encode(widgets), + let jsonString = String(data: jsonData, encoding: .utf8) + else { return } + + setConfig(Self.key, jsonString) + } +} diff --git a/deltachat-ios/DC/DcContext.swift b/deltachat-ios/DC/DcContext.swift index 9fd940eba..ecfad0b21 100644 --- a/deltachat-ios/DC/DcContext.swift +++ b/deltachat-ios/DC/DcContext.swift @@ -507,8 +507,8 @@ public class DcContext { } public func setConfig(_ key: String, _ value: String?) { - if let v = value { - dc_set_config(self.contextPointer, key, v) + if let value { + dc_set_config(self.contextPointer, key, value) } else { dc_set_config(self.contextPointer, key, nil) } diff --git a/deltachat-ios/Model/WidgetEntry.swift b/deltachat-ios/Model/WidgetEntry.swift new file mode 100644 index 000000000..05bdada0f --- /dev/null +++ b/deltachat-ios/Model/WidgetEntry.swift @@ -0,0 +1,6 @@ +import Foundation + +struct WidgetEntry: Codable, Equatable { + let accountId: Int + let messageId: Int +}