feat: saveToken plugin for app groups on iOS

This will allow the share extension to access the Bearer token to send
images to the backend.
This commit is contained in:
2025-05-01 18:20:26 +01:00
parent c8d9ae7aff
commit 61e9258538
32 changed files with 857 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Package.resolved

View File

@@ -0,0 +1,32 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "tauri-plugin-ios-shared-token",
platforms: [
.macOS(.v10_13),
.iOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "tauri-plugin-ios-shared-token",
type: .static,
targets: ["tauri-plugin-ios-shared-token"]),
],
dependencies: [
.package(name: "Tauri", path: "../.tauri/tauri-api")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "tauri-plugin-ios-shared-token",
dependencies: [
.byName(name: "Tauri")
],
path: "Sources")
]
)

View File

@@ -0,0 +1,3 @@
# Tauri Plugin ios-shared-token
A description of this package.

View File

@@ -0,0 +1,34 @@
import SwiftRs
import Tauri
import UIKit
import WebKit
class SaveTokenArgs: Decodable {
var token: String?
}
let appGroupID = "group.com.haystack.com"
let sharedTokenKey = "sharedAuthToken"
class SharedToken: Plugin {
@objc func saveToken(_ invoke: Invoke) throws {
guard let args = try? invoke.parseArgs(SaveTokenArgs.self), let token = args.token else {
invoke.reject("Missing token argument")
return
}
// Access shared UserDefaults
guard let sharedDefaults = UserDefaults(suiteName: appGroupID) else {
invoke.reject("Could not access shared UserDefaults. Check App Group configuration.")
return
}
sharedDefaults.set(token, forKey: sharedTokenKey)
invoke.resolve()
}
}
@_cdecl("init_plugin_ios_shared_token")
func initPlugin() -> Plugin {
return SharedToken()
}

View File

@@ -0,0 +1,8 @@
import XCTest
@testable import ExamplePlugin
final class ExamplePluginTests: XCTestCase {
func testExample() throws {
let plugin = ExamplePlugin()
}
}