Skip to content

Commit

Permalink
Merge pull request #89 from Nanguage/weize-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway authored Dec 21, 2023
2 parents dc2f376 + 0c4b59b commit 722dd82
Showing 1 changed file with 40 additions and 39 deletions.
79 changes: 40 additions & 39 deletions src/imjoyApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ const builtinPlugins = [
"https://gist.githubusercontent.com/oeway/9c78d23c101f468e723888d05b6fac6d/raw/ImageJScriptEditor.imjoy.html",
"https://gist.githubusercontent.com/oeway/c9592f23c7ee147085f0504d2f3e993a/raw/CellPose-ImageJ.imjoy.html",
"https://gist.githubusercontent.com/oeway/e5c980fbf6582f25fde795262a7e33ec/raw/itk-vtk-viewer-imagej.imjoy.html",
"https://gist.githubusercontent.com/oeway/16d189e53d23cb2e26c3618ed6e40be6/raw/ImJoyModelRunner.imjoy.html"
"https://gist.githubusercontent.com/oeway/16d189e53d23cb2e26c3618ed6e40be6/raw/ImJoyModelRunner.imjoy.html",
"https://bioimage-io.github.io/bioengine-web-client/",
];
async function startImJoy(app, imjoy) {
await imjoy.start();
imjoy.event_bus.on("show_message", msg => {
imjoy.event_bus.on("show_message", (msg) => {
Snackbar.show({
text: msg,
pos: "bottom-left"
pos: "bottom-left",
});
});
imjoy.event_bus.on("close_window", w => {
imjoy.event_bus.on("close_window", (w) => {
app.closeWindow(w);
app.$forceUpdate();
});
imjoy.event_bus.on("plugin_loaded", p => {
imjoy.event_bus.on("plugin_loaded", (p) => {
// only add if it's not a window instance
if (!p.window_id) app.plugins[p.name] = p;
if (
Expand All @@ -31,7 +32,7 @@ async function startImJoy(app, imjoy) {
app.$forceUpdate();
});
let windowCount = 0;
imjoy.event_bus.on("add_window", async w => {
imjoy.event_bus.on("add_window", async (w) => {
windowCount++;
if (document.getElementById(w.window_id)) return;
if (w.dialog) {
Expand Down Expand Up @@ -95,7 +96,7 @@ async function startImJoy(app, imjoy) {
titleBar.addEventListener("dragend", () => {
elem.style.pointerEvents = "auto";
});
const observer = new MutationObserver(mutationsList => {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
// resizerBord div added during resizing
Expand All @@ -119,18 +120,18 @@ async function startImJoy(app, imjoy) {
app.loadPlugin(p);
}
app.loadPluginByQuery();
window.runImJoyPlugin = code => {
window.runImJoyPlugin = (code) => {
loader.style.display = "block";
imjoy.pm
.reloadPlugin({
code: code,
load_dependencies: true,
hot_reloading: true
hot_reloading: true,
})
.then(plugin => {
.then((plugin) => {
Snackbar.show({
text: `Plugin "${plugin.name}" loaded successfully.`,
pos: "bottom-left"
pos: "bottom-left",
});
app.plugins[plugin.name] = plugin;
app.$forceUpdate();
Expand All @@ -139,7 +140,7 @@ async function startImJoy(app, imjoy) {
} else {
Snackbar.show({
text: `No "run" function defined in Plugin "${plugin.name}".`,
pos: "bottom-left"
pos: "bottom-left",
});
}
})
Expand All @@ -148,18 +149,18 @@ async function startImJoy(app, imjoy) {
});
};

window.reloadImJoyPlugin = code => {
window.reloadImJoyPlugin = (code) => {
loader.style.display = "block";
imjoy.pm
.reloadPlugin({
code: code,
load_dependencies: true,
hot_reloading: true
hot_reloading: true,
})
.then(plugin => {
.then((plugin) => {
Snackbar.show({
text: `Plugin "${plugin.name}" loaded successfully.`,
pos: "bottom-left"
pos: "bottom-left",
});
app.plugins[plugin.name] = plugin;
app.$forceUpdate();
Expand All @@ -171,7 +172,7 @@ async function startImJoy(app, imjoy) {

window.loadPlugin = async function(uri) {
await imjoy.pm.reloadPluginRecursively({
uri
uri,
});
};

Expand All @@ -197,7 +198,7 @@ async function startImJoy(app, imjoy) {
_rtype: "ndarray",
_rshape: imgData.shape,
_rdtype: imgData.type,
_rvalue: imgData.bytes
_rvalue: imgData.bytes,
};
}
}
Expand Down Expand Up @@ -352,7 +353,7 @@ export async function setupImJoyApp(setAPI) {
plugins: {},
fullscreen: false,
imjoy: null,
active_plugin: null
active_plugin: null,
},
mounted() {
console.log(`ImJoy Core (v${imjoyCore.VERSION}) loaded.`);
Expand Down Expand Up @@ -398,24 +399,24 @@ export async function setupImJoyApp(setAPI) {
duration = duration || 5;
Snackbar.show({
text: msg,
pos: "bottom-left"
pos: "bottom-left",
});
await window.ij.showStatus(msg);
},
async showDialog(_plugin, config) {
config.dialog = true;
return await imjoy.pm.createWindow(_plugin, config);
}
}
},
},
});
this.imjoy = imjoy;
startImJoy(this, this.imjoy).then(() => {
imjoy.pm
.reloadPluginRecursively({
uri:
"https://imjoy-team.github.io/jupyter-engine-manager/Jupyter-Engine-Manager.imjoy.html"
"https://imjoy-team.github.io/jupyter-engine-manager/Jupyter-Engine-Manager.imjoy.html",
})
.then(enginePlugin => {
.then((enginePlugin) => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const engine = urlParams.get("engine");
Expand All @@ -425,25 +426,25 @@ export async function setupImJoyApp(setAPI) {
.createEngine({
name: "MyCustomEngine",
nbUrl: engine,
url: engine.split("?")[0]
url: engine.split("?")[0],
})
.then(() => {
console.log("Jupyter Engine connected!");
})
.catch(e => {
.catch((e) => {
console.error("Failed to connect to Jupyter Engine", e);
});
} else {
enginePlugin.api
.createEngine({
name: "MyBinder Engine",
url: "https://mybinder.org",
spec: spec || "oeway/imjoy-binder-image/master"
spec: spec || "oeway/imjoy-binder-image/master",
})
.then(() => {
console.log("Binder Engine connected!");
})
.catch(e => {
.catch((e) => {
console.error("Failed to connect to MyBinder Engine", e);
});
}
Expand All @@ -464,19 +465,19 @@ export async function setupImJoyApp(setAPI) {
this.imjoy.pm.imjoy_api.showDialog(null, {
src: "https://imjoy.io/#/app",
fullscreen: true,
passive: true
passive: true,
});
},
aboutImJoy() {
this.imjoy.pm.imjoy_api.showDialog(null, {
src: "https://imjoy.io/#/about",
passive: true
passive: true,
});
},
showAPIDocs() {
this.imjoy.pm.imjoy_api.createWindow(null, {
src: "https://imjoy.io/docs/#/api",
passive: true
passive: true,
});
},
async connectPlugin() {
Expand All @@ -498,7 +499,7 @@ export async function setupImJoyApp(setAPI) {
}
await plugin.api.run({
config: config,
data: {}
data: {},
});
}
} catch (e) {
Expand All @@ -516,14 +517,14 @@ export async function setupImJoyApp(setAPI) {
}
await plugin.api.run({
config: config,
data: {}
data: {},
});
},
showMessage(msg, duration) {
duration = duration || 5;
Snackbar.show({
text: msg,
pos: "bottom-left"
pos: "bottom-left",
});
},
loadPlugin(p) {
Expand All @@ -536,17 +537,17 @@ export async function setupImJoyApp(setAPI) {
}
this.imjoy.pm
.reloadPluginRecursively({
uri: p
uri: p,
})
.then(async plugin => {
.then(async (plugin) => {
this.plugins[plugin.name] = plugin;
if (!builtinPlugins.includes(plugin.config.origin))
this.showMessage(
`Plugin ${plugin.name} successfully loaded, you can now run it from the ImJoy plugin menu.`
);
this.$forceUpdate();
})
.catch(e => {
.catch((e) => {
console.error(e);
this.showMessage(`Failed to load the plugin, error: ${e}`);
});
Expand Down Expand Up @@ -578,8 +579,8 @@ export async function setupImJoyApp(setAPI) {
},
maximizeWindow() {
this.fullscreen = !this.fullscreen;
}
}
},
},
});
window.connectPlugin = async function() {
await app.connectPlugin();
Expand Down

0 comments on commit 722dd82

Please sign in to comment.