From 3b35ab6581ed3bc1788780d6fcf906c85f47b63f Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 3 Jul 2022 14:32:29 +0100 Subject: [PATCH] Plugins: Added joplin.versionInfo method --- .eslintignore | 3 ++ .gitignore | 3 ++ .../plugins/PlatformImplementation.ts | 29 ++++++----- .../plugins/BasePlatformImplementation.ts | 50 +++++++++++++++++++ packages/lib/services/plugins/api/Joplin.ts | 9 +++- packages/lib/services/plugins/api/types.ts | 6 +++ yarn.lock | 15 ++---- 7 files changed, 90 insertions(+), 25 deletions(-) create mode 100644 packages/lib/services/plugins/BasePlatformImplementation.ts diff --git a/.eslintignore b/.eslintignore index 964f1c4e6..accbdf6c8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1489,6 +1489,9 @@ packages/lib/services/keychain/KeychainServiceDriver.node.js.map packages/lib/services/keychain/KeychainServiceDriverBase.d.ts packages/lib/services/keychain/KeychainServiceDriverBase.js packages/lib/services/keychain/KeychainServiceDriverBase.js.map +packages/lib/services/plugins/BasePlatformImplementation.d.ts +packages/lib/services/plugins/BasePlatformImplementation.js +packages/lib/services/plugins/BasePlatformImplementation.js.map packages/lib/services/plugins/BasePluginRunner.d.ts packages/lib/services/plugins/BasePluginRunner.js packages/lib/services/plugins/BasePluginRunner.js.map diff --git a/.gitignore b/.gitignore index 55e212247..1996083a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1479,6 +1479,9 @@ packages/lib/services/keychain/KeychainServiceDriver.node.js.map packages/lib/services/keychain/KeychainServiceDriverBase.d.ts packages/lib/services/keychain/KeychainServiceDriverBase.js packages/lib/services/keychain/KeychainServiceDriverBase.js.map +packages/lib/services/plugins/BasePlatformImplementation.d.ts +packages/lib/services/plugins/BasePlatformImplementation.js +packages/lib/services/plugins/BasePlatformImplementation.js.map packages/lib/services/plugins/BasePluginRunner.d.ts packages/lib/services/plugins/BasePluginRunner.js packages/lib/services/plugins/BasePluginRunner.js.map diff --git a/packages/app-desktop/services/plugins/PlatformImplementation.ts b/packages/app-desktop/services/plugins/PlatformImplementation.ts index ab5efc8dd..813e24eef 100644 --- a/packages/app-desktop/services/plugins/PlatformImplementation.ts +++ b/packages/app-desktop/services/plugins/PlatformImplementation.ts @@ -1,19 +1,12 @@ import bridge from '../bridge'; import { Implementation as WindowImplementation } from '@joplin/lib/services/plugins/api/JoplinWindow'; import { injectCustomStyles } from '@joplin/lib/CssUtils'; +import { VersionInfo } from '@joplin/lib/services/plugins/api/types'; +import Setting from '@joplin/lib/models/Setting'; +import { reg } from '@joplin/lib/registry'; +import BasePlatformImplementation, { Joplin } from '@joplin/lib/services/plugins/BasePlatformImplementation'; const { clipboard, nativeImage } = require('electron'); - -interface JoplinViewsDialogs { - showMessageBox(message: string): Promise; -} - -interface JoplinViews { - dialogs: JoplinViewsDialogs; -} - -interface Joplin { - views: JoplinViews; -} +const packageInfo = require('../../packageInfo'); interface Components { [key: string]: any; @@ -22,7 +15,7 @@ interface Components { // PlatformImplementation provides access to platform specific dependencies, // such as the clipboard, message dialog, etc. It allows having the same plugin // API for all platforms, but with different implementations. -export default class PlatformImplementation { +export default class PlatformImplementation extends BasePlatformImplementation { private static instance_: PlatformImplementation; private joplin_: Joplin; @@ -33,6 +26,14 @@ export default class PlatformImplementation { return this.instance_; } + public get versionInfo(): VersionInfo { + return { + version: packageInfo.version, + syncVersion: Setting.value('syncVersion'), + profileVersion: reg.db().version(), + }; + } + public get clipboard() { return clipboard; } @@ -48,6 +49,8 @@ export default class PlatformImplementation { } public constructor() { + super(); + this.components_ = {}; this.joplin_ = { diff --git a/packages/lib/services/plugins/BasePlatformImplementation.ts b/packages/lib/services/plugins/BasePlatformImplementation.ts new file mode 100644 index 000000000..00c3dccf2 --- /dev/null +++ b/packages/lib/services/plugins/BasePlatformImplementation.ts @@ -0,0 +1,50 @@ +// PlatformImplementation provides access to platform specific dependencies, +// such as the clipboard, message dialog, etc. It allows having the same plugin + +import { VersionInfo } from './api/types'; +import { Implementation as WindowImplementation } from './api/JoplinWindow'; + +export interface JoplinViewsDialogs { + showMessageBox(message: string): Promise; +} + +export interface JoplinViews { + dialogs: JoplinViewsDialogs; +} + +export interface Joplin { + views: JoplinViews; +} + +// API for all platforms, but with different implementations. +export default class BasePlatformImplementation { + + public get versionInfo(): VersionInfo { + throw new Error('Not implemented'); + } + + public get clipboard(): any { + throw new Error('Not implemented'); + } + + public get nativeImage(): any { + throw new Error('Not implemented'); + } + + public get window(): WindowImplementation { + throw new Error('Not implemented'); + } + + public registerComponent(_name: string, _component: any) { + throw new Error('Not implemented'); + } + + public unregisterComponent(_name: string) { + throw new Error('Not implemented'); + } + + public get joplin(): Joplin { + throw new Error('Not implemented'); + } + +} diff --git a/packages/lib/services/plugins/api/Joplin.ts b/packages/lib/services/plugins/api/Joplin.ts index d549db2c4..526ce1156 100644 --- a/packages/lib/services/plugins/api/Joplin.ts +++ b/packages/lib/services/plugins/api/Joplin.ts @@ -10,6 +10,7 @@ import JoplinSettings from './JoplinSettings'; import JoplinContentScripts from './JoplinContentScripts'; import JoplinClipboard from './JoplinClipboard'; import JoplinWindow from './JoplinWindow'; +import BasePlatformImplementation from '../BasePlatformImplementation'; /** * This is the main entry point to the Joplin API. You can access various services using the provided accessors. @@ -36,8 +37,10 @@ export default class Joplin { private contentScripts_: JoplinContentScripts = null; private clipboard_: JoplinClipboard = null; private window_: JoplinWindow = null; + private implementation_: BasePlatformImplementation = null; - public constructor(implementation: any, plugin: Plugin, store: any) { + public constructor(implementation: BasePlatformImplementation, plugin: Plugin, store: any) { + this.implementation_ = implementation; this.data_ = new JoplinData(); this.plugins_ = new JoplinPlugins(plugin); this.workspace_ = new JoplinWorkspace(store); @@ -117,4 +120,8 @@ export default class Joplin { // Just a stub. Implementation has to be done within plugin process, in plugin_index.js } + public async versionInfo() { + return this.implementation_.versionInfo; + } + } diff --git a/packages/lib/services/plugins/api/types.ts b/packages/lib/services/plugins/api/types.ts index 640d08399..f8ac2cf29 100644 --- a/packages/lib/services/plugins/api/types.ts +++ b/packages/lib/services/plugins/api/types.ts @@ -221,6 +221,12 @@ export enum ModelType { Command = 16, } +export interface VersionInfo { + version: string; + profileVersion: number; + syncVersion: number; +} + // ================================================================= // Menu types // ================================================================= diff --git a/yarn.lock b/yarn.lock index d3fd170fd..722a43a66 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9200,17 +9200,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.30001280": - version: 1.0.30001285 - resolution: "caniuse-lite@npm:1.0.30001285" - checksum: 03abdcea913961f4484a7e9494482a0e8a32d6b2305e3922196d0672897c043ac2e1ce884c69730921400c7cddb41ae27a9fcfdaa7d82d11a75d7331393ab5c6 - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001286": - version: 1.0.30001291 - resolution: "caniuse-lite@npm:1.0.30001291" - checksum: ae24be79227036564ccd2ab8a0be8793a2e650941607a9f3e68a967db08d90cf17ded0382c2ce87063051b7200e618ec83bdb12f423ed60665922dc4d8eb8f78 +"caniuse-lite@npm:^1.0.30001280, caniuse-lite@npm:^1.0.30001286": + version: 1.0.30001362 + resolution: "caniuse-lite@npm:1.0.30001362" + checksum: bd35704a81aa8ca12e952c2276d205109a5d10bd7d0fb767c27ee9bdbc8011c5c99a9772833701d68ed2fe7143f1744258c1cc440dd7ea4584a1354f6dac9f0a languageName: node linkType: hard