diff --git a/wox.plugin.host.python/src/wox_plugin_host/jsonrpc.py b/wox.plugin.host.python/src/wox_plugin_host/jsonrpc.py index 9a40be97a..aab510c9b 100644 --- a/wox.plugin.host.python/src/wox_plugin_host/jsonrpc.py +++ b/wox.plugin.host.python/src/wox_plugin_host/jsonrpc.py @@ -68,29 +68,46 @@ async def load_plugin(ctx: Context, request: Dict[str, Any]) -> None: if path.exists(deps_dir) and deps_dir not in sys.path: sys.path.append(deps_dir) - # Combine plugin directory and entry file to get full path - full_entry_path: str = path.join(plugin_directory, entry) - - # Import the plugin module - spec = importlib.util.spec_from_file_location("plugin", full_entry_path) - if spec is None or spec.loader is None: - raise ImportError(f"Could not load plugin from {full_entry_path}") - - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - - if not hasattr(module, "plugin"): - raise AttributeError("Plugin module does not have a 'plugin' attribute") - - plugin_instances[plugin_id] = PluginInstance( - plugin=module.plugin, - api=None, - module_path=full_entry_path, - actions={}, - refreshes={}, - ) + try: + # Add the parent directory to Python path + parent_dir = path.dirname(plugin_directory) + if parent_dir not in sys.path: + sys.path.append(parent_dir) + + # Convert entry path to module path + # e.g., "killprocess/main.py" -> "dist.killprocess.main" + plugin_dir_name = path.basename(plugin_directory) + entry_without_ext = entry.replace(".py", "").replace("/", ".") + module_path = f"{plugin_dir_name}.{entry_without_ext}" + + await logger.info( + ctx.get_trace_id(), + f"module_path: {module_path}, plugin_dir_name: {plugin_dir_name}, entry_without_ext: {entry_without_ext}", + ) + + # Import the module + module = importlib.import_module(module_path) + + if not hasattr(module, "plugin"): + raise AttributeError("Plugin module does not have a 'plugin' attribute") + + plugin_instances[plugin_id] = PluginInstance( + plugin=module.plugin, + api=None, + module_path=plugin_directory, + actions={}, + refreshes={}, + ) + + await logger.info(ctx.get_trace_id(), f"<{plugin_name}> load plugin successfully") + except Exception as e: + error_stack = traceback.format_exc() + await logger.error( + ctx.get_trace_id(), + f"<{plugin_name}> load plugin failed: {str(e)}\nStack trace:\n{error_stack}", + ) + raise e - await logger.info(ctx.get_trace_id(), f"<{plugin_name}> load plugin successfully") except Exception as e: error_stack = traceback.format_exc() await logger.error( diff --git a/wox.ui.flutter/wox/lib/main.dart b/wox.ui.flutter/wox/lib/main.dart index ef1257c3f..7fa9106bc 100644 --- a/wox.ui.flutter/wox/lib/main.dart +++ b/wox.ui.flutter/wox/lib/main.dart @@ -219,12 +219,6 @@ class _WoxAppState extends State with WindowListener, ProtocolListener { return; } - // switch to the launcher view if in setting view - var launcherController = Get.find(); - if (launcherController.isInSettingView.value) { - launcherController.isInSettingView.value = false; - } - WoxApi.instance.onFocusLost(); } diff --git a/wox.ui.flutter/wox/lib/modules/launcher/wox_launcher_controller.dart b/wox.ui.flutter/wox/lib/modules/launcher/wox_launcher_controller.dart index f044e580b..55d96d7ed 100644 --- a/wox.ui.flutter/wox/lib/modules/launcher/wox_launcher_controller.dart +++ b/wox.ui.flutter/wox/lib/modules/launcher/wox_launcher_controller.dart @@ -219,6 +219,11 @@ class WoxLauncherController extends GetxController { await clearQueryResults(); } + // switch to the launcher view if in setting view + if (isInSettingView.value) { + isInSettingView.value = false; + } + await WoxApi.instance.onHide(currentQuery.value); }