forked from 1b-agent/opencadstudio-upstream
fix(plugins): gate on_load behind API v5
BREAKING CHANGE: plugins using on_load must target API v5 and declare api_version = 5. Refs #901
This commit is contained in:
1 parent
c527466791
commit
2842f6dc58
9 files changed
+43
-30
No files matched your search
@@ -56,9 +56,9 @@ pub fn run(socket_name: &str, cdylib_path: &Path) -> Result<(), Box<dyn std::err
|
||||
|
||||
if version >= 4 {
|
||||
let client = V4Client::connect_handshake(socket_name, &token)?;
|
||||
// Give the plugin a chance to set up worker threads / cache the request
|
||||
// sender before the host starts dispatching user commands.
|
||||
invoke_on_load(&mut *plugin, &client, &interactive);
|
||||
if version >= 5 {
|
||||
invoke_on_load(&mut *plugin, &client, &interactive)?;
|
||||
}
|
||||
run_v4(&mut *plugin, &interactive, client)
|
||||
} else {
|
||||
let client = IpcClient::connect(socket_name)?;
|
||||
@@ -70,11 +70,17 @@ pub fn run(socket_name: &str, cdylib_path: &Path) -> Result<(), Box<dyn std::err
|
||||
}
|
||||
}
|
||||
|
||||
fn invoke_on_load(plugin: &mut dyn BuiltinPlugin, client: &V4Client, interactive: &InteractiveRegistry) {
|
||||
fn invoke_on_load(
|
||||
plugin: &mut dyn BuiltinPlugin,
|
||||
client: &V4Client,
|
||||
interactive: &InteractiveRegistry,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut proxy = client.plugin_host_api(0, interactive.clone());
|
||||
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
plugin.on_load(&mut proxy)
|
||||
}));
|
||||
}))
|
||||
.map_err(|_| std::io::Error::other("plugin on_load() panicked"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_v3(
|
||||
|
||||
Reference in new issue
Block a user