2020-11-07 17:59:37 +02:00
|
|
|
// import { EditorCommand } from '@joplin/lib/services/plugins/api/types';
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
import bridge from '../bridge';
|
|
|
|
|
|
|
|
// interface JoplinWorkspace {
|
|
|
|
// execEditorCommand(command:EditorCommand):Promise<string>
|
|
|
|
// }
|
|
|
|
|
|
|
|
interface JoplinViewsDialogs {
|
2020-11-12 21:13:28 +02:00
|
|
|
showMessageBox(message: string): Promise<number>;
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface JoplinViews {
|
|
|
|
dialogs: JoplinViewsDialogs
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Joplin {
|
|
|
|
// workspace: JoplinWorkspace;
|
|
|
|
views: JoplinViews;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Components {
|
2020-11-12 21:13:28 +02:00
|
|
|
[key: string]: any,
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class PlatformImplementation {
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
private static instance_: PlatformImplementation;
|
|
|
|
private joplin_: Joplin;
|
|
|
|
private components_: Components;
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
public static instance(): PlatformImplementation {
|
2020-10-09 19:35:46 +02:00
|
|
|
if (!this.instance_) this.instance_ = new PlatformImplementation();
|
|
|
|
return this.instance_;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.components_ = {};
|
|
|
|
|
|
|
|
this.joplin_ = {
|
|
|
|
views: {
|
|
|
|
dialogs: {
|
2020-11-12 21:13:28 +02:00
|
|
|
showMessageBox: async function(message: string) {
|
2020-10-09 19:35:46 +02:00
|
|
|
return bridge().showMessageBox(message);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
registerComponent(name: string, component: any) {
|
2020-10-09 19:35:46 +02:00
|
|
|
this.components_[name] = component;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
unregisterComponent(name: string) {
|
2020-10-09 19:35:46 +02:00
|
|
|
delete this.components_[name];
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
public get joplin(): Joplin {
|
2020-10-09 19:35:46 +02:00
|
|
|
return this.joplin_;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|