1use std::collections::HashMap;
2
3pub trait PluginServiceBridge: Send + Sync + 'static {
6 fn as_any(&self) -> &dyn std::any::Any;
8
9 fn translate(&self, plugin_name: &str, key: &str, args: &HashMap<String, String>) -> String;
11
12 fn current_locale(&self) -> String;
14
15 fn set_js_execution_state(&self, state: String);
17
18 fn clear_js_execution_state(&self);
20
21 fn get_theme_schema(&self) -> serde_json::Value;
23
24 fn get_builtin_themes(&self) -> serde_json::Value;
26
27 fn register_plugin_strings(
29 &self,
30 _plugin_name: &str,
31 _strings: HashMap<String, HashMap<String, String>>,
32 ) {
33 }
34
35 fn unregister_plugin_strings(&self, _plugin_name: &str) {}
37
38 fn register_command(&self, command: crate::command::Command);
40
41 fn unregister_command(&self, name: &str);
43
44 fn unregister_commands_by_prefix(&self, prefix: &str);
46
47 fn unregister_commands_by_plugin(&self, plugin_name: &str);
49
50 fn plugins_dir(&self) -> std::path::PathBuf;
52
53 fn config_dir(&self) -> std::path::PathBuf;
55
56 fn data_dir(&self) -> std::path::PathBuf;
59
60 fn get_theme_data(&self, _name: &str) -> Option<serde_json::Value> {
62 None
63 }
64
65 fn save_theme_file(&self, _name: &str, _content: &str) -> Result<String, String> {
68 Err("not implemented".to_string())
69 }
70
71 fn theme_file_exists(&self, _name: &str) -> bool {
73 false
74 }
75}
76
77pub struct NoopServiceBridge;
79
80impl PluginServiceBridge for NoopServiceBridge {
81 fn as_any(&self) -> &dyn std::any::Any {
82 self
83 }
84 fn translate(&self, _plugin_name: &str, key: &str, _args: &HashMap<String, String>) -> String {
85 key.to_string()
86 }
87 fn current_locale(&self) -> String {
88 "en".to_string()
89 }
90 fn set_js_execution_state(&self, _state: String) {}
91 fn clear_js_execution_state(&self) {}
92 fn get_theme_schema(&self) -> serde_json::Value {
93 serde_json::Value::Null
94 }
95 fn get_builtin_themes(&self) -> serde_json::Value {
96 serde_json::Value::Null
97 }
98 fn register_plugin_strings(
99 &self,
100 _plugin_name: &str,
101 _strings: HashMap<String, HashMap<String, String>>,
102 ) {
103 }
104 fn unregister_plugin_strings(&self, _plugin_name: &str) {}
105 fn register_command(&self, _command: crate::command::Command) {}
106 fn unregister_command(&self, _name: &str) {}
107 fn unregister_commands_by_prefix(&self, _prefix: &str) {}
108 fn unregister_commands_by_plugin(&self, _plugin_name: &str) {}
109 fn plugins_dir(&self) -> std::path::PathBuf {
110 std::path::PathBuf::from("/tmp/plugins")
111 }
112 fn config_dir(&self) -> std::path::PathBuf {
113 std::path::PathBuf::from("/tmp/config")
114 }
115 fn data_dir(&self) -> std::path::PathBuf {
116 std::path::PathBuf::from("/tmp/data")
117 }
118}