diff --git a/.changes/swift-build-older-versions.md b/.changes/swift-build-older-versions.md new file mode 100644 index 000000000..41666a915 --- /dev/null +++ b/.changes/swift-build-older-versions.md @@ -0,0 +1,15 @@ +--- +"barcode-scanner": patch +"biometric": patch +"clipboard-manager": patch +"dialog": patch +"geolocation": patch +"haptics": patch +"log-plugin": patch +"nfc": patch +"notification": patch +"shell": patch +"store": patch +--- + +Explicitly set a minimum macOS version for the Swift package. diff --git a/plugins/barcode-scanner/ios/Package.swift b/plugins/barcode-scanner/ios/Package.swift index aafb41c3f..cf39b8128 100644 --- a/plugins/barcode-scanner/ios/Package.swift +++ b/plugins/barcode-scanner/ios/Package.swift @@ -10,7 +10,8 @@ import PackageDescription let package = Package( name: "tauri-plugin-barcode-scanner", platforms: [ - .iOS(.v13) + .macOS(.v10_13), + .iOS(.v13), ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/plugins/biometric/ios/Package.swift b/plugins/biometric/ios/Package.swift index 34c9f87e1..7860f476e 100644 --- a/plugins/biometric/ios/Package.swift +++ b/plugins/biometric/ios/Package.swift @@ -8,7 +8,8 @@ import PackageDescription let package = Package( name: "tauri-plugin-biometric", platforms: [ - .iOS(.v13) + .macOS(.v10_13), + .iOS(.v13), ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/plugins/clipboard-manager/ios/Package.swift b/plugins/clipboard-manager/ios/Package.swift index f6200857d..6da5303eb 100644 --- a/plugins/clipboard-manager/ios/Package.swift +++ b/plugins/clipboard-manager/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-clipboard-manager", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-clipboard-manager", - type: .static, - targets: ["tauri-plugin-clipboard-manager"]), - ], - 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-clipboard-manager", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-clipboard-manager", + 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-clipboard-manager", + type: .static, + targets: ["tauri-plugin-clipboard-manager"]) + ], + 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-clipboard-manager", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/dialog/ios/Package.swift b/plugins/dialog/ios/Package.swift index 45a58a430..f8983f14a 100644 --- a/plugins/dialog/ios/Package.swift +++ b/plugins/dialog/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-dialog", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-dialog", - type: .static, - targets: ["tauri-plugin-dialog"]), - ], - 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-dialog", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-dialog", + 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-dialog", + type: .static, + targets: ["tauri-plugin-dialog"]) + ], + 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-dialog", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/geolocation/ios/Package.swift b/plugins/geolocation/ios/Package.swift index c19847830..f8cfb73f6 100644 --- a/plugins/geolocation/ios/Package.swift +++ b/plugins/geolocation/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-geolocation", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-geolocation", - type: .static, - targets: ["tauri-plugin-geolocation"]), - ], - 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-geolocation", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-geolocation", + 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-geolocation", + type: .static, + targets: ["tauri-plugin-geolocation"]) + ], + 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-geolocation", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/haptics/ios/Package.swift b/plugins/haptics/ios/Package.swift index c70145b0b..a64b98907 100644 --- a/plugins/haptics/ios/Package.swift +++ b/plugins/haptics/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-haptics", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-haptics", - type: .static, - targets: ["tauri-plugin-haptics"]), - ], - 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-haptics", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-haptics", + 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-haptics", + type: .static, + targets: ["tauri-plugin-haptics"]) + ], + 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-haptics", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/log/ios/Package.swift b/plugins/log/ios/Package.swift index 4afbbbdba..1571f22eb 100644 --- a/plugins/log/ios/Package.swift +++ b/plugins/log/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-log", - platforms: [ - .iOS(.v11), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-log", - type: .static, - targets: ["tauri-plugin-log"]), - ], - 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-log", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-log", + platforms: [ + .macOS(.v10_13), + .iOS(.v11), + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "tauri-plugin-log", + type: .static, + targets: ["tauri-plugin-log"]) + ], + 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-log", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/nfc/ios/Package.swift b/plugins/nfc/ios/Package.swift index e8f1f19ad..a028db7d3 100644 --- a/plugins/nfc/ios/Package.swift +++ b/plugins/nfc/ios/Package.swift @@ -8,7 +8,8 @@ import PackageDescription let package = Package( name: "tauri-plugin-nfc", platforms: [ - .iOS(.v13) + .macOS(.v10_13), + .iOS(.v13), ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/plugins/notification/ios/Package.swift b/plugins/notification/ios/Package.swift index 9b6818696..bbd6df9e7 100644 --- a/plugins/notification/ios/Package.swift +++ b/plugins/notification/ios/Package.swift @@ -3,33 +3,32 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT - - import PackageDescription let package = Package( - name: "tauri-plugin-notification", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-notification", - type: .static, - targets: ["tauri-plugin-notification"]), - ], - 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-notification", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-notification", + 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-notification", + type: .static, + targets: ["tauri-plugin-notification"]) + ], + 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-notification", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/shell/ios/Package.swift b/plugins/shell/ios/Package.swift index fa5d363d0..c7b2a7aae 100644 --- a/plugins/shell/ios/Package.swift +++ b/plugins/shell/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-shell", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-shell", - type: .static, - targets: ["tauri-plugin-shell"]), - ], - 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-shell", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-shell", + 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-shell", + type: .static, + targets: ["tauri-plugin-shell"]) + ], + 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-shell", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/plugins/store/.tauri/tauri-api/.gitignore b/plugins/store/.tauri/tauri-api/.gitignore deleted file mode 100644 index 5922fdaa5..000000000 --- a/plugins/store/.tauri/tauri-api/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -/.build -/Packages -/*.xcodeproj -xcuserdata/ -DerivedData/ -.swiftpm/config/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc -Package.resolved diff --git a/plugins/store/.tauri/tauri-api/Package.swift b/plugins/store/.tauri/tauri-api/Package.swift deleted file mode 100644 index c7a733230..000000000 --- a/plugins/store/.tauri/tauri-api/Package.swift +++ /dev/null @@ -1,40 +0,0 @@ -// swift-tools-version:5.3 -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import PackageDescription - -let package = Package( - name: "Tauri", - platforms: [ - .macOS(.v10_13), - .iOS(.v11), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "Tauri", - type: .static, - targets: ["Tauri"]) - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(name: "SwiftRs", url: "https://github.com/Brendonovich/swift-rs", from: "1.0.0") - ], - 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", - dependencies: [ - .byName(name: "SwiftRs") - ], - path: "Sources" - ), - .testTarget( - name: "TauriTests", - dependencies: ["Tauri"] - ), - ] -) diff --git a/plugins/store/.tauri/tauri-api/README.md b/plugins/store/.tauri/tauri-api/README.md deleted file mode 100644 index 52c3f1c7f..000000000 --- a/plugins/store/.tauri/tauri-api/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Tauri - -Tauri iOS API. diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/Channel.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/Channel.swift deleted file mode 100644 index add065c74..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/Channel.swift +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import Foundation - -let CHANNEL_PREFIX = "__CHANNEL__:" -let channelDataKey = CodingUserInfoKey(rawValue: "sendChannelData")! - -public class Channel: Decodable { - public let id: UInt64 - let handler: (UInt64, String) -> Void - - public required init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let channelDef = try container.decode(String.self) - - let components = channelDef.components(separatedBy: CHANNEL_PREFIX) - if components.count < 2 { - throw DecodingError.dataCorruptedError( - in: container, - debugDescription: "Invalid channel definition from \(channelDef)" - ) - - } - guard let channelId = UInt64(components[1]) else { - throw DecodingError.dataCorruptedError( - in: container, - debugDescription: "Invalid channel ID from \(channelDef)" - ) - } - - guard let handler = decoder.userInfo[channelDataKey] as? (UInt64, String) -> Void else { - throw DecodingError.dataCorruptedError( - in: container, - debugDescription: "missing userInfo for Channel handler. This is a Tauri issue" - ) - } - - self.id = channelId - self.handler = handler - } - - func serialize(_ data: JsonValue) -> String { - do { - return try data.jsonRepresentation() ?? "\"Failed to serialize payload\"" - } catch { - return "\"\(error)\"" - } - } - - public func send(_ data: JsonObject) { - send(.dictionary(data)) - } - - public func send(_ data: JsonValue) { - handler(id, serialize(data)) - } - - public func send(_ data: T) throws { - let json = try JSONEncoder().encode(data) - handler(id, String(decoding: json, as: UTF8.self)) - } - -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/Invoke.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/Invoke.swift deleted file mode 100644 index b1b5dbfe5..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/Invoke.swift +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import Foundation -import UIKit - -@objc public class Invoke: NSObject { - public let command: String - let callback: UInt64 - let error: UInt64 - let data: String - let sendResponse: (UInt64, String?) -> Void - let sendChannelData: (UInt64, String) -> Void - - public init( - command: String, callback: UInt64, error: UInt64, - sendResponse: @escaping (UInt64, String?) -> Void, - sendChannelData: @escaping (UInt64, String) -> Void, data: String - ) { - self.command = command - self.callback = callback - self.error = error - self.data = data - self.sendResponse = sendResponse - self.sendChannelData = sendChannelData - } - - public func parseArgs(_ type: T.Type) throws -> T { - let jsonData = self.data.data(using: .utf8)! - let decoder = JSONDecoder() - decoder.userInfo[channelDataKey] = sendChannelData - return try decoder.decode(type, from: jsonData) - } - - func serialize(_ data: JsonValue) -> String { - do { - return try data.jsonRepresentation() ?? "\"Failed to serialize payload\"" - } catch { - return "\"\(error)\"" - } - } - - public func resolve() { - sendResponse(callback, nil) - } - - public func resolve(_ data: JsonObject) { - resolve(.dictionary(data)) - } - - public func resolve(_ data: JsonValue) { - sendResponse(callback, serialize(data)) - } - - public func resolve(_ data: T) { - do { - let json = try JSONEncoder().encode(data) - sendResponse(callback, String(decoding: json, as: UTF8.self)) - } catch { - sendResponse(self.error, "\"\(error)\"") - } - } - - public func reject( - _ message: String, code: String? = nil, error: Error? = nil, data: JsonValue? = nil - ) { - let payload: NSMutableDictionary = [ - "message": message - ] - - if let code = code { - payload["code"] = code - } - - if let error = error { - payload["error"] = error - } - - if let data = data { - switch data { - case .dictionary(let dict): - for entry in dict { - payload[entry.key] = entry.value - } - } - } - - sendResponse(self.error, serialize(.dictionary(payload as! JsonObject))) - } - - public func unimplemented() { - unimplemented("not implemented") - } - - public func unimplemented(_ message: String) { - reject(message) - } - - public func unavailable() { - unavailable("not available") - } - - public func unavailable(_ message: String) { - reject(message) - } -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/JSTypes.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/JSTypes.swift deleted file mode 100644 index 8fd5d2f29..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/JSTypes.swift +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import Foundation - -// declare our empty protocol, and conformance, for typing -public protocol JSValue {} -extension String: JSValue {} -extension Bool: JSValue {} -extension Int: JSValue {} -extension Float: JSValue {} -extension Double: JSValue {} -extension NSNumber: JSValue {} -extension NSNull: JSValue {} -extension Array: JSValue {} -extension Date: JSValue {} -extension Dictionary: JSValue where Key == String, Value == JSValue {} - -// convenience aliases -public typealias JSObject = [String: JSValue] -public typealias JSArray = [JSValue] diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/JsonValue.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/JsonValue.swift deleted file mode 100644 index c3043511b..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/JsonValue.swift +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import Foundation - -public typealias JsonObject = [String: Any] - -public enum JsonValue { - case dictionary(JsonObject) - - enum SerializationError: Error { - case invalidObject - } - - public func jsonRepresentation(includingFields: JsonObject? = nil) throws -> String? { - switch self { - case .dictionary(var dictionary): - if let fields = includingFields { - dictionary.merge(fields) { (current, _) in current } - } - dictionary = prepare(dictionary: dictionary) - guard JSONSerialization.isValidJSONObject(dictionary) else { - throw SerializationError.invalidObject - } - let data = try JSONSerialization.data(withJSONObject: dictionary, options: []) - return String(data: data, encoding: .utf8) - } - } - - private static let formatter = ISO8601DateFormatter() - - private func prepare(dictionary: JsonObject) -> JsonObject { - return dictionary.mapValues { (value) -> Any in - if let date = value as? Date { - return JsonValue.formatter.string(from: date) - } else if let aDictionary = value as? JsonObject { - return prepare(dictionary: aDictionary) - } else if let anArray = value as? [Any] { - return prepare(array: anArray) - } - return value - } - } - - private func prepare(array: [Any]) -> [Any] { - return array.map { (value) -> Any in - if let date = value as? Date { - return JsonValue.formatter.string(from: date) - } else if let aDictionary = value as? JsonObject { - return prepare(dictionary: aDictionary) - } else if let anArray = value as? [Any] { - return prepare(array: anArray) - } - return value - } - } -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/Logger.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/Logger.swift deleted file mode 100644 index 9fa6e3fe7..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/Logger.swift +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import os.log -import UIKit - -/// Wrapper class for os_log function -public class Logger { - private static var _enabled = false - public static var enabled: Bool { - get { - #if DEBUG - return true - #else - return _enabled - #endif - } - set { - Logger._enabled = newValue - } - } - - static func log(_ items: Any..., category: String, type: OSLogType) { - if Logger.enabled { - var message = "" - let last = items.count - 1 - for (index, item) in items.enumerated() { - message += "\(item)" - if index != last { - message += " " - } - } - let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "-", category: category) - os_log("%{public}@", log: log, type: type, String(message.prefix(4068))) - } - } - - public static func debug(_ items: Any..., category: String = "app") { - #if DEBUG - Logger.log(items, category: category, type: OSLogType.default) - #else - Logger.log(items, category: category, type: OSLogType.debug) - #endif - } - - public static func info(_ items: Any..., category: String = "app") { - #if DEBUG - Logger.log(items, category: category, type: OSLogType.default) - #else - Logger.log(items, category: category, type: OSLogType.info) - #endif - } - - public static func error(_ items: Any..., category: String = "app") { - Logger.log(items, category: category, type: OSLogType.error) - } -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/Plugin/Plugin.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/Plugin/Plugin.swift deleted file mode 100644 index 7ce67f9b2..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/Plugin/Plugin.swift +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import WebKit -import os.log - -struct RegisterListenerArgs: Decodable { - let event: String - let handler: Channel -} - -struct RemoveListenerArgs: Decodable { - let event: String - let channelId: UInt64 -} - -open class Plugin: NSObject { - public let manager: PluginManager = PluginManager.shared - var config: String = "{}" - private var listeners = [String: [Channel]]() - - internal func setConfig(_ config: String) { - self.config = config - } - - public func parseConfig(_ type: T.Type) throws -> T { - let jsonData = self.config.data(using: .utf8)! - let decoder = JSONDecoder() - return try decoder.decode(type, from: jsonData) - } - - @objc open func load(webview: WKWebView) {} - - @objc open func checkPermissions(_ invoke: Invoke) { - invoke.resolve() - } - - @objc open func requestPermissions(_ invoke: Invoke) { - invoke.resolve() - } - - public func trigger(_ event: String, data: JSObject) { - if let eventListeners = listeners[event] { - for channel in eventListeners { - channel.send(data) - } - } - } - - public func trigger(_ event: String, data: T) throws { - if let eventListeners = listeners[event] { - for channel in eventListeners { - try channel.send(data) - } - } - } - - @objc func registerListener(_ invoke: Invoke) throws { - let args = try invoke.parseArgs(RegisterListenerArgs.self) - - if var eventListeners = listeners[args.event] { - eventListeners.append(args.handler) - } else { - listeners[args.event] = [args.handler] - } - - invoke.resolve() - } - - @objc func removeListener(_ invoke: Invoke) throws { - let args = try invoke.parseArgs(RemoveListenerArgs.self) - - if let eventListeners = listeners[args.event] { - - listeners[args.event] = eventListeners.filter { $0.id != args.channelId } - } - - invoke.resolve() - } -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/Tauri.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/Tauri.swift deleted file mode 100644 index 9a9c40e3d..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/Tauri.swift +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import Foundation -import SwiftRs -import UIKit -import WebKit -import os.log - -class PluginHandle { - var instance: Plugin - var loaded = false - - init(plugin: Plugin) { - instance = plugin - } -} - -public class PluginManager { - static let shared: PluginManager = PluginManager() - public var viewController: UIViewController? - var plugins: [String: PluginHandle] = [:] - var ipcDispatchQueue = DispatchQueue(label: "ipc") - public var isSimEnvironment: Bool { - #if targetEnvironment(simulator) - return true - #else - return false - #endif - } - - public func assetUrl(fromLocalURL url: URL?) -> URL? { - guard let inputURL = url else { - return nil - } - - return URL(string: "asset://localhost")!.appendingPathComponent(inputURL.path) - } - - func onWebviewCreated(_ webview: WKWebView) { - for (_, handle) in plugins { - if !handle.loaded { - handle.instance.load(webview: webview) - } - } - } - - func load(name: String, plugin: P, config: String, webview: WKWebView?) { - plugin.setConfig(config) - let handle = PluginHandle(plugin: plugin) - if let webview = webview { - handle.instance.load(webview: webview) - handle.loaded = true - } - plugins[name] = handle - } - - func invoke(name: String, invoke: Invoke) { - if let plugin = plugins[name] { - ipcDispatchQueue.async { - let selectorWithThrows = Selector(("\(invoke.command):error:")) - if plugin.instance.responds(to: selectorWithThrows) { - var error: NSError? = nil - withUnsafeMutablePointer(to: &error) { - let methodIMP: IMP! = plugin.instance.method(for: selectorWithThrows) - unsafeBitCast( - methodIMP, to: (@convention(c) (Any?, Selector, Invoke, OpaquePointer) -> Void).self)( - plugin.instance, selectorWithThrows, invoke, OpaquePointer($0)) - } - if let error = error { - invoke.reject("\(error)") - // TODO: app crashes without this leak - let _ = Unmanaged.passRetained(error) - } - } else { - let selector = Selector(("\(invoke.command):")) - if plugin.instance.responds(to: selector) { - plugin.instance.perform(selector, with: invoke) - } else { - invoke.reject("No command \(invoke.command) found for plugin \(name)") - } - } - } - } else { - invoke.reject("Plugin \(name) not initialized") - } - } -} - -extension PluginManager: NSCopying { - public func copy(with zone: NSZone? = nil) -> Any { - return self - } -} - -@_cdecl("register_plugin") -func registerPlugin(name: SRString, plugin: NSObject, config: SRString, webview: WKWebView?) { - PluginManager.shared.load( - name: name.toString(), - plugin: plugin as! Plugin, - config: config.toString(), - webview: webview - ) -} - -@_cdecl("on_webview_created") -func onWebviewCreated(webview: WKWebView, viewController: UIViewController) { - PluginManager.shared.viewController = viewController - PluginManager.shared.onWebviewCreated(webview) -} - -@_cdecl("run_plugin_command") -func runCommand( - id: Int, - name: SRString, - command: SRString, - data: SRString, - callback: @escaping @convention(c) (Int, Bool, UnsafePointer) -> Void, - sendChannelData: @escaping @convention(c) (UInt64, UnsafePointer) -> Void -) { - let callbackId: UInt64 = 0 - let errorId: UInt64 = 1 - let invoke = Invoke( - command: command.toString(), callback: callbackId, error: errorId, - sendResponse: { (fn: UInt64, payload: String?) -> Void in - let success = fn == callbackId - callback(id, success, payload ?? "null") - }, - sendChannelData: { (id: UInt64, payload: String) -> Void in - sendChannelData(id, payload) - }, data: data.toString()) - PluginManager.shared.invoke(name: name.toString(), invoke: invoke) -} diff --git a/plugins/store/.tauri/tauri-api/Sources/Tauri/UiUtils.swift b/plugins/store/.tauri/tauri-api/Sources/Tauri/UiUtils.swift deleted file mode 100644 index 4097596e2..000000000 --- a/plugins/store/.tauri/tauri-api/Sources/Tauri/UiUtils.swift +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2019-2024 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -import UIKit - -public class UIUtils { - public static func centerPopover(rootViewController: UIViewController?, popoverController: UIViewController) { - if let viewController = rootViewController { - popoverController.popoverPresentationController?.sourceRect = CGRect(x: viewController.view.center.x, y: viewController.view.center.y, width: 0, height: 0) - popoverController.popoverPresentationController?.sourceView = viewController.view - popoverController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up - } - } -} diff --git a/plugins/store/ios/Package.swift b/plugins/store/ios/Package.swift index fdf5f69a8..51ba6bf65 100644 --- a/plugins/store/ios/Package.swift +++ b/plugins/store/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-store", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-store", - type: .static, - targets: ["tauri-plugin-store"]), - ], - 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-store", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-store", + 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-store", + type: .static, + targets: ["tauri-plugin-store"]) + ], + 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-store", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] ) diff --git a/shared/template/ios/Package.swift b/shared/template/ios/Package.swift index e4f53f0b0..e4ebd0672 100644 --- a/shared/template/ios/Package.swift +++ b/shared/template/ios/Package.swift @@ -6,28 +6,29 @@ import PackageDescription let package = Package( - name: "tauri-plugin-{{ plugin_name }}", - platforms: [ - .iOS(.v13), - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "tauri-plugin-{{ plugin_name }}", - type: .static, - targets: ["tauri-plugin-{{ plugin_name }}"]), - ], - 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-{{ plugin_name }}", - dependencies: [ - .byName(name: "Tauri") - ], - path: "Sources") - ] + name: "tauri-plugin-{{ plugin_name }}", + 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-{{ plugin_name }}", + type: .static, + targets: ["tauri-plugin-{{ plugin_name }}"]) + ], + 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-{{ plugin_name }}", + dependencies: [ + .byName(name: "Tauri") + ], + path: "Sources") + ] )