diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index d8e96a50..8140d5ed 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 073695882B3AC757007249BE /* Libcore.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 073695722B39DA23007249BE /* Libcore.xcframework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 0736958B2B3AC96D007249BE /* Bundle+Properties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0736958A2B3AC96D007249BE /* Bundle+Properties.swift */; }; 0736958D2B3B79E0007249BE /* StatsEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0736958C2B3B79E0007249BE /* StatsEventHandler.swift */; }; + 0736958F2B3B8048007249BE /* PlatformMethodHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0736958E2B3B8047007249BE /* PlatformMethodHandler.swift */; }; 075637BA2B01583F005AFB8E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 60F1D4AAC33ACF5C8307310D /* Pods_Runner.framework */; }; 075637BB2B01583F005AFB8E /* Pods_Runner.framework in Embed Frameworks (2 items) */ = {isa = PBXBuildFile; fileRef = 60F1D4AAC33ACF5C8307310D /* Pods_Runner.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 075637BC2B015864005AFB8E /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03E392B72ADDA00E000ADF15 /* NetworkExtension.framework */; }; @@ -132,6 +133,7 @@ 0736957A2B39DE78007249BE /* Libcore.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Libcore.xcframework; path = Frameworks/Libcore.xcframework; sourceTree = ""; }; 0736958A2B3AC96D007249BE /* Bundle+Properties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Properties.swift"; sourceTree = ""; }; 0736958C2B3B79E0007249BE /* StatsEventHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsEventHandler.swift; sourceTree = ""; }; + 0736958E2B3B8047007249BE /* PlatformMethodHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformMethodHandler.swift; sourceTree = ""; }; 075637B22B0157CB005AFB8E /* libcore.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libcore.xcframework; path = ../libcore/bin/libcore.xcframework; sourceTree = ""; }; 07A63A832B1E728C00CAFA4D /* Release */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Release; path = ../build/ios/framework/release; sourceTree = ""; }; 07A63A842B1E72AE00CAFA4D /* App.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = App.xcframework; path = ../build/ios/framework/release/App.xcframework; sourceTree = ""; }; @@ -226,6 +228,7 @@ isa = PBXGroup; children = ( 03B516662AE6B93A00EA47E2 /* MethodHandler.swift */, + 0736958E2B3B8047007249BE /* PlatformMethodHandler.swift */, 03B516682AE7306B00EA47E2 /* StatusEventHandler.swift */, 03B5167A2AE79DB400EA47E2 /* FileMethodHandler.swift */, 03B5166A2AE7315E00EA47E2 /* AlertsEventHandler.swift */, @@ -680,6 +683,7 @@ 0736958D2B3B79E0007249BE /* StatsEventHandler.swift in Sources */, 03B516692AE7306B00EA47E2 /* StatusEventHandler.swift in Sources */, 032158B82ADDF8BF008D943B /* VPNManager.swift in Sources */, + 0736958F2B3B8048007249BE /* PlatformMethodHandler.swift in Sources */, 03B516672AE6B93A00EA47E2 /* MethodHandler.swift in Sources */, 03B5166D2AE7325500EA47E2 /* LogsEventHandler.swift in Sources */, 03E392D02ADDF1BD000ADF15 /* FilePath.swift in Sources */, diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 2b3fd695..95848ad7 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -22,6 +22,7 @@ import Libcore func registerHandlers() { MethodHandler.register(with: self.registrar(forPlugin: MethodHandler.name)!) + PlatformMethodHandler.register(with: self.registrar(forPlugin: PlatformMethodHandler.name)!) FileMethodHandler.register(with: self.registrar(forPlugin: FileMethodHandler.name)!) StatusEventHandler.register(with: self.registrar(forPlugin: StatusEventHandler.name)!) AlertsEventHandler.register(with: self.registrar(forPlugin: AlertsEventHandler.name)!) diff --git a/ios/Runner/Handlers/PlatformMethodHandler.swift b/ios/Runner/Handlers/PlatformMethodHandler.swift new file mode 100644 index 00000000..b79f48a9 --- /dev/null +++ b/ios/Runner/Handlers/PlatformMethodHandler.swift @@ -0,0 +1,41 @@ +// +// PlatformMethodHandler.swift +// Runner +// +// Created by Hiddify on 12/27/23. +// + +import Flutter +import Combine +import Libcore + +public class PlatformMethodHandler: NSObject, FlutterPlugin { + + public static let name = "\(Bundle.main.serviceIdentifier)/platform" + + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: Self.name, binaryMessenger: registrar.messenger()) + let instance = PlatformMethodHandler() + registrar.addMethodCallDelegate(instance, channel: channel) + instance.channel = channel + } + + private var channel: FlutterMethodChannel? + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "get_paths": + result(getPaths(args: call.arguments)) + default: + result(FlutterMethodNotImplemented) + } + } + + public func getPaths(args: Any?) -> [String:String] { + return [ + "base": FilePath.sharedDirectory.path, + "working": FilePath.workingDirectory.path, + "temp": FilePath.cacheDirectory.path + ] + } +} diff --git a/lib/core/directories/directories_provider.dart b/lib/core/directories/directories_provider.dart index 7e8d16eb..bdce6246 100644 --- a/lib/core/directories/directories_provider.dart +++ b/lib/core/directories/directories_provider.dart @@ -10,12 +10,12 @@ part 'directories_provider.g.dart'; @Riverpod(keepAlive: true) class AppDirectories extends _$AppDirectories with InfraLogger { - final _methodChannel = const MethodChannel("app.hiddify.com/platform"); + final _methodChannel = const MethodChannel("com.hiddify.app/platform"); @override Future build() async { final Directories dirs; - if (false&&Platform.isIOS) { + if (Platform.isIOS) { final paths = await _methodChannel.invokeMethod("get_paths"); loggy.debug("paths: $paths");