2020-10-09 19:35:46 +02:00
|
|
|
import bridge from '../bridge';
|
|
|
|
|
|
|
|
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 {
|
2020-11-12 21:29:22 +02:00
|
|
|
dialogs: JoplinViewsDialogs;
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Joplin {
|
|
|
|
views: JoplinViews;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Components {
|
2020-11-12 21:29:22 +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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|