From bbce81c065ce7df92c5d21c0266193a5d9959602 Mon Sep 17 00:00:00 2001 From: Xu Rui <39859875+Rengwang@users.noreply.github.com> Date: Sat, 28 Nov 2026 11:50:22 +0800 Subject: [PATCH] fix(akplugin): prefer framework-embedded AKInterface.bundle over legacy shared path --- PlayTools/Utils/AKPluginLoader.swift | 31 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/PlayTools/Utils/AKPluginLoader.swift b/PlayTools/Utils/AKPluginLoader.swift index 97700e46..5d6425fd 100644 --- a/PlayTools/Utils/AKPluginLoader.swift +++ b/PlayTools/Utils/AKPluginLoader.swift @@ -15,18 +15,25 @@ class AKInterface { } private static func loadPlugin() -> Plugin? { - // 1. Form the plugin's bundle URL - guard let bundleURL = Bundle.main.builtInPlugInsURL? - .appendingPathComponent("AKInterface") - .appendingPathExtension("bundle") else { return nil } + let frameworkBundle = Bundle(for: AKInterface.self) + let candidates: [URL?] = [ + frameworkBundle.builtInPlugInsURL?.appendingPathComponent("AKInterface.bundle"), + frameworkBundle.bundleURL.appendingPathComponent("PlugIns/AKInterface.bundle"), + frameworkBundle.bundleURL.appendingPathComponent("Versions/A/PlugIns/AKInterface.bundle"), + Bundle.main.builtInPlugInsURL? + .appendingPathComponent("AKInterface") + .appendingPathExtension("bundle") + ] - // 2. Create a bundle instance with the plugin URL - guard let bundle = Bundle(url: bundleURL) else { return nil } - - // 3. Load the bundle and our plugin class - guard let pluginClass = bundle.principalClass as? Plugin.Type else { return nil } - - // 4. Create an instance of the plugin class - return pluginClass.init() + for candidate in candidates { + guard let bundleURL = candidate, + FileManager.default.fileExists(atPath: bundleURL.path), + let bundle = Bundle(url: bundleURL), + let pluginClass = bundle.principalClass as? Plugin.Type else { + continue + } + return pluginClass.init() + } + return nil } }