More plugins: splashscreen and importmap (#938)

This PR move codes from main.ts into two new plugins:

- splashscreen (formerly known as py-loader)
- importmap

The old setting config.autoclose_loader is still supported but deprecated; the new setting is config.splashscreen.autoclose.

Moreover, it does a small refactoring around UserError: now UserErrors are correctly caught even if they are raised from within afterRuntimeLoad.
This commit is contained in:
Antonio Cuni
2022-11-16 18:08:17 +01:00
committed by GitHub
parent b79ceea7a8
commit 41ebaaf366
19 changed files with 498 additions and 284 deletions

View File

@@ -1,5 +1,6 @@
import type { AppConfig } from './pyconfig';
import type { Runtime } from './runtime';
import type { UserError } from './exceptions';
export class Plugin {
@@ -38,6 +39,19 @@ export class Plugin {
*/
afterSetup(runtime: Runtime) {
}
/** Startup complete. The interpreter is initialized and ready, user
* scripts have been executed: the main initialization logic ends here and
* the page is ready to accept user interactions.
*/
afterStartup(runtime: Runtime) {
}
/** Called when an UserError is raised
*/
onUserError(error: UserError) {
}
}
@@ -48,8 +62,9 @@ export class PluginManager {
this._plugins = [];
}
add(p: Plugin) {
this._plugins.push(p);
add(...plugins: Plugin[]) {
for (const p of plugins)
this._plugins.push(p);
}
configure(config: AppConfig) {
@@ -66,4 +81,14 @@ export class PluginManager {
for (const p of this._plugins)
p.afterSetup(runtime);
}
afterStartup(runtime: Runtime) {
for (const p of this._plugins)
p.afterStartup(runtime);
}
onUserError(error: UserError) {
for (const p of this._plugins)
p.onUserError(error);
}
}