mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-15 12:53:52 +01:00
blocking project loading for engines
This commit is contained in:
parent
d8e3a0a51b
commit
847f9d12a5
3 changed files with 38 additions and 2 deletions
|
|
@ -24,12 +24,23 @@ export function activate({services}) {
|
|||
engine.handler = handler;
|
||||
console.info(`engine "${id}" is ready`);
|
||||
}
|
||||
services.lifecycle.loadProjectRequest();
|
||||
}
|
||||
|
||||
function allEnginesReady() {
|
||||
for (let e of engines) {
|
||||
if (e.handler === NO_OP_HANDLER) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
services.craftEngines = {
|
||||
registerEngine,
|
||||
getRegisteredEngines: () => engines,
|
||||
engineReady
|
||||
engineReady,
|
||||
allEnginesReady
|
||||
};
|
||||
|
||||
engines.forEach(e => e.handler = NO_OP_HANDLER);
|
||||
|
|
@ -37,6 +48,8 @@ export function activate({services}) {
|
|||
}
|
||||
|
||||
function startEngine({id, url}) {
|
||||
console.info(`starting engine "${id}"...`);
|
||||
|
||||
let engineScript = document.createElement('script');
|
||||
engineScript.setAttribute('src', url);
|
||||
document.head.appendChild(engineScript);
|
||||
|
|
|
|||
20
web/app/cad/init/lifecyclePlugin.js
Normal file
20
web/app/cad/init/lifecyclePlugin.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import {createToken} from '../../../../modules/bus';
|
||||
|
||||
export function activate({bus, services}) {
|
||||
const startTime = performance.now();
|
||||
bus.enableState(APP_READY_TOKEN, false);
|
||||
bus.enableState(APP_PROJECT_LOADED, false);
|
||||
services.lifecycle = {
|
||||
loadProjectRequest: () => {
|
||||
if (bus.state[APP_READY_TOKEN] && !bus.state[APP_PROJECT_LOADED] && services.craftEngines.allEnginesReady()) {
|
||||
services.project.load();
|
||||
bus.dispatch(APP_PROJECT_LOADED, true);
|
||||
const onLoadTime = performance.now();
|
||||
console.log("project loaded, took: " + ((onLoadTime - startTime) / 1000).toFixed(2) + ' sec');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const APP_READY_TOKEN = createToken('app', 'ready');
|
||||
export const APP_PROJECT_LOADED = createToken('app', 'projectLoaded');
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import Bus from 'bus';
|
||||
import * as LifecyclePlugin from './lifecyclePlugin';
|
||||
import * as AppTabsPlugin from '../dom/appTabsPlugin';
|
||||
import * as DomPlugin from '../dom/domPlugin';
|
||||
import * as PickControlPlugin from '../scene/controls/pickControlPlugin';
|
||||
|
|
@ -22,12 +23,14 @@ import * as tpiPlugin from '../tpi/tpiPlugin';
|
|||
import * as PartModellerPlugin from '../part/partModellerPlugin';
|
||||
|
||||
import startReact from "../dom/startReact";
|
||||
import {APP_READY_TOKEN} from './lifecyclePlugin';
|
||||
|
||||
export default function startApplication(callback) {
|
||||
|
||||
let applicationPlugins = [PartModellerPlugin];
|
||||
|
||||
let preUIPlugins = [
|
||||
LifecyclePlugin,
|
||||
ProjectPlugin,
|
||||
StoragePlugin,
|
||||
AppTabsPlugin,
|
||||
|
|
@ -61,7 +64,7 @@ export default function startApplication(callback) {
|
|||
|
||||
startReact(context, () => {
|
||||
activatePlugins(plugins, context);
|
||||
context.services.project.load();
|
||||
context.bus.dispatch(APP_READY_TOKEN, true);
|
||||
context.services.viewer.render();
|
||||
callback(context);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue