chore: add build artifacts, map assets, and routing data

This commit is contained in:
Hamza-Ayed
2026-09-19 12:34:24 +03:00
parent aa2b9f131f
commit 43ad2e0ad4
327 changed files with 52421 additions and 1810 deletions
@@ -11,11 +11,14 @@
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
6452485AAFBDAE2B1C618E39 /* ValhallaConfigModels in Frameworks */ = {isa = PBXBuildFile; productRef = FD514B9B10F0E71DD5394485 /* ValhallaConfigModels */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; };
7884E86A2EC3CC0800C636F2 /* ValhallaBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8692EC3CC0800C636F2 /* ValhallaBridge.swift */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
9959400011B20A358E042FCE /* Valhalla in Frameworks */ = {isa = PBXBuildFile; productRef = 86A5F3421875A95923223EE8 /* Valhalla */; };
D7A13A93F5CA92A6B51F5E94 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEB74182945ED5DCE2C8D602 /* Pods_Runner.framework */; };
/* End PBXBuildFile section */
@@ -57,6 +60,7 @@
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
7884E8692EC3CC0800C636F2 /* ValhallaBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValhallaBridge.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
@@ -75,6 +79,8 @@
buildActionMask = 2147483647;
files = (
D7A13A93F5CA92A6B51F5E94 /* Pods_Runner.framework in Frameworks */,
9959400011B20A358E042FCE /* Valhalla in Frameworks */,
6452485AAFBDAE2B1C618E39 /* ValhallaConfigModels in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -149,6 +155,7 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */,
7884E8692EC3CC0800C636F2 /* ValhallaBridge.swift */,
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
);
path = Runner;
@@ -208,6 +215,10 @@
dependencies = (
);
name = Runner;
packageProductDependencies = (
86A5F3421875A95923223EE8 /* Valhalla */,
FD514B9B10F0E71DD5394485 /* ValhallaConfigModels */,
);
productName = Runner;
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
productType = "com.apple.product-type.application";
@@ -241,6 +252,10 @@
Base,
);
mainGroup = 97C146E51CF9000F007C117D;
packageReferences = (
A72B5EA0F88BAD178AD3FAE1 /* XCRemoteSwiftPackageReference "valhalla-mobile" */,
188781D3791B2E42EA69105C /* XCRemoteSwiftPackageReference "valhalla-openapi-models-swift" */,
);
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
projectDirPath = "";
projectRoot = "";
@@ -383,6 +398,7 @@
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */,
7884E86A2EC3CC0800C636F2 /* ValhallaBridge.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -459,7 +475,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -544,7 +560,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -589,7 +605,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -601,7 +617,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -640,7 +656,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -730,6 +746,38 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
188781D3791B2E42EA69105C /* XCRemoteSwiftPackageReference "valhalla-openapi-models-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Rallista/valhalla-openapi-models-swift.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.5.0;
};
};
A72B5EA0F88BAD178AD3FAE1 /* XCRemoteSwiftPackageReference "valhalla-mobile" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/rallista/valhalla-mobile.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.6.1;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
86A5F3421875A95923223EE8 /* Valhalla */ = {
isa = XCSwiftPackageProductDependency;
package = A72B5EA0F88BAD178AD3FAE1 /* XCRemoteSwiftPackageReference "valhalla-mobile" */;
productName = Valhalla;
};
FD514B9B10F0E71DD5394485 /* ValhallaConfigModels */ = {
isa = XCSwiftPackageProductDependency;
package = 188781D3791B2E42EA69105C /* XCRemoteSwiftPackageReference "valhalla-openapi-models-swift" */;
productName = ValhallaConfigModels;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
@@ -0,0 +1,42 @@
{
"originHash" : "1e398f34548ef20369f5ad933ca831a1bc612478ad6f4765a644f48d9de0c964",
"pins" : [
{
"identity" : "anycodable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Flight-School/AnyCodable",
"state" : {
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
"version" : "0.6.7"
}
},
{
"identity" : "light-swift-untar",
"kind" : "remoteSourceControl",
"location" : "https://github.com/UInt2048/Light-Swift-Untar.git",
"state" : {
"revision" : "fcff1f1b82373ea64b9565a364f63ffe7fdecf9f",
"version" : "1.0.4"
}
},
{
"identity" : "valhalla-mobile",
"kind" : "remoteSourceControl",
"location" : "https://github.com/rallista/valhalla-mobile.git",
"state" : {
"revision" : "b4ba416430498982bac604dd1a6b2771b0c12178",
"version" : "0.6.1"
}
},
{
"identity" : "valhalla-openapi-models-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Rallista/valhalla-openapi-models-swift.git",
"state" : {
"revision" : "16a7fae2dccb75393f580aa07570e969e89e3bde",
"version" : "0.5.2"
}
}
],
"version" : 3
}
@@ -0,0 +1,42 @@
{
"originHash" : "1e398f34548ef20369f5ad933ca831a1bc612478ad6f4765a644f48d9de0c964",
"pins" : [
{
"identity" : "anycodable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Flight-School/AnyCodable",
"state" : {
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
"version" : "0.6.7"
}
},
{
"identity" : "light-swift-untar",
"kind" : "remoteSourceControl",
"location" : "https://github.com/UInt2048/Light-Swift-Untar.git",
"state" : {
"revision" : "fcff1f1b82373ea64b9565a364f63ffe7fdecf9f",
"version" : "1.0.4"
}
},
{
"identity" : "valhalla-mobile",
"kind" : "remoteSourceControl",
"location" : "https://github.com/rallista/valhalla-mobile.git",
"state" : {
"revision" : "b4ba416430498982bac604dd1a6b2771b0c12178",
"version" : "0.6.1"
}
},
{
"identity" : "valhalla-openapi-models-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Rallista/valhalla-openapi-models-swift.git",
"state" : {
"revision" : "16a7fae2dccb75393f580aa07570e969e89e3bde",
"version" : "0.5.2"
}
}
],
"version" : 3
}
@@ -3,6 +3,8 @@ import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
private let valhallaBridge = ValhallaBridge()
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
@@ -12,5 +14,6 @@ import UIKit
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
valhallaBridge.register(with: engineBridge.applicationRegistrar.messenger())
}
}
@@ -1,122 +1 @@
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@1x.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@1x.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@1x.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "Icon-App-1024x1024@1x.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
{"images":[{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@3x.png","scale":"3x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@3x.png","scale":"3x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@3x.png","scale":"3x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@1x.png","scale":"1x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@3x.png","scale":"3x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@1x.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@1x.png","scale":"1x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@1x.png","scale":"1x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@2x.png","scale":"2x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@1x.png","scale":"1x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@2x.png","scale":"2x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@1x.png","scale":"1x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@2x.png","scale":"2x"},{"size":"83.5x83.5","idiom":"ipad","filename":"Icon-App-83.5x83.5@2x.png","scale":"2x"},{"size":"1024x1024","idiom":"ios-marketing","filename":"Icon-App-1024x1024@1x.png","scale":"1x"}],"info":{"version":1,"author":"xcode"}}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 762 B

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 45 KiB

@@ -0,0 +1,189 @@
import Flutter
import UIKit
#if canImport(Valhalla)
import Valhalla
import ValhallaConfigModels
#endif
/// ============================================================================
/// [ValhallaBridge] - جسر التوجيه المحلي لمحرك Valhalla على iOS
/// ============================================================================
/// English:
/// Swift bridge connecting Flutter's MethodChannel (intaleq_tactical/valhalla)
/// to the native Valhalla offline routing engine on iOS.
/// The Jordan tile extract (valhalla_tiles.tar) downloaded by
/// OfflineRoutingPackageService into <Documents>/routing/jordan is opened by
/// the C++ engine through ValhallaConfig(tileExtractTar:), and every route
/// request runs 100% on-device with zero network usage.
///
/// العربية:
/// جسر سويفت يربط قناة فلاتر بمحرك Valhalla الأصلي على iOS. يفتح المحرك ملف
/// غراف طرق الأردن المنزّل من مجلد الحزمة ويحسب المسارات محلياً بالكامل مع
/// ارتفاعات SRTM وأسماء الشوارع الحقيقية وتعليمات انعطاف عربية.
/// ============================================================================
class ValhallaBridge: NSObject {
static let channelName = "intaleq_tactical/valhalla"
/// Serial queue guarding engine lifecycle + routing calls (C++ actor is not thread-safe).
private let engineQueue = DispatchQueue(label: "com.intaleq.tactical.valhalla")
#if canImport(Valhalla)
private var engine: Valhalla?
private var engineDir: String?
#endif
func register(with messenger: FlutterBinaryMessenger) {
let channel = FlutterMethodChannel(name: ValhallaBridge.channelName, binaryMessenger: messenger)
channel.setMethodCallHandler { [weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) in
guard let self = self else { return }
switch call.method {
case "ensureReady":
let args = call.arguments as? [String: Any]
let regionDir = args?["regionDir"] as? String
self.handleEnsureReady(regionDirPath: regionDir, result: result)
case "route":
let args = call.arguments as? [String: Any]
guard let requestJson = args?["request"] as? String else {
result(FlutterError(code: "BAD_ARGS", message: "Missing request JSON", details: nil))
return
}
self.handleRoute(requestJson: requestJson, result: result)
case "release":
self.releaseEngine()
result(true)
default:
result(FlutterMethodNotImplemented)
}
}
}
// MARK: - ensureReady
private func handleEnsureReady(regionDirPath: String?, result: @escaping FlutterResult) {
let dir = Self.resolveRegionDir(regionDirPath)
let tarPath = Self.findTar(named: "valhalla_tiles.tar", in: dir)?.path
guard let tarPath = tarPath else {
result(FlutterError(
code: "DIR_NOT_FOUND",
message: "Routing package not installed at \(dir.path) — download it from the server while online",
details: nil))
return
}
#if canImport(Valhalla)
engineQueue.async { [weak self] in
guard let self = self else { return }
// إعادة الاستخدام إن كان المحرك مبنياً على نفس الحزمة
if let engine = self.engine, self.engineDir == dir.path {
result(true)
return
}
self.releaseEngineLocked()
do {
let config = try ValhallaConfig(tileExtractTar: URL(fileURLWithPath: tarPath))
self.engine = try Valhalla(config)
self.engineDir = dir.path
NSLog("[ValhallaBridge] engine ready against \(tarPath)")
DispatchQueue.main.async { result(true) }
} catch {
NSLog("[ValhallaBridge] engine init failed: \(error)")
DispatchQueue.main.async {
result(FlutterError(code: "ENGINE_INIT_FAILED",
message: "\(error)",
details: nil))
}
}
}
#else
result(FlutterError(
code: "FALLBACK_SYNTHETIC",
message: "Valhalla SPM package is not linked into this build target",
details: nil))
#endif
}
// MARK: - route
private func handleRoute(requestJson: String, result: @escaping FlutterResult) {
#if canImport(Valhalla)
engineQueue.async { [weak self] in
guard let self = self, let engine = self.engine else {
DispatchQueue.main.async {
result(FlutterError(code: "NOT_READY",
message: "Call ensureReady before route",
details: nil))
}
return
}
// route(rawRequest:) يعيد JSON خاماً؛ أخطاء المحرك تعود داخل الجسم
// بصيغة {"code": int, "message": str} ويفكّها طرف Dart مباشرة.
let rawResponse = engine.route(rawRequest: requestJson)
DispatchQueue.main.async { result(rawResponse) }
}
#else
result(FlutterError(
code: "FALLBACK_SYNTHETIC",
message: "Valhalla SPM package is not linked into this build target",
details: nil))
#endif
}
// MARK: - release
func releaseEngine() {
#if canImport(Valhalla)
engineQueue.async { [weak self] in
self?.releaseEngineLocked()
}
#else
// no-op
#endif
}
#if canImport(Valhalla)
/// Must be called on engineQueue.
private func releaseEngineLocked() {
engine = nil
engineDir = nil
}
#endif
// MARK: - Helpers
private static func resolveRegionDir(_ regionDirPath: String?) -> URL {
if let path = regionDirPath {
return URL(fileURLWithPath: path, isDirectory: true)
}
let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
return docs.appendingPathComponent("routing/jordan", isDirectory: true)
}
/// بحث تكراري عن ملف الغراف داخل مجلد الحزمة (البنية قد تختلف بين الإصدارات)
private static func findTar(named name: String, in dir: URL) -> URL? {
let fm = FileManager.default
var isDir: ObjCBool = false
guard fm.fileExists(atPath: dir.path, isDirectory: &isDir), isDir.boolValue else {
return nil
}
if fm.fileExists(atPath: dir.appendingPathComponent(name).path) {
return dir.appendingPathComponent(name)
}
guard let children = try? fm.contentsOfDirectory(at: dir, includingPropertiesForKeys: [.isDirectoryKey]) else {
return nil
}
for child in children {
let isChildDir = (try? child.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
if isChildDir, let found = findTar(named: name, in: child) {
return found
}
}
return nil
}
}