From a250917e2d4344bccedd156564708fe6abc86f0f Mon Sep 17 00:00:00 2001 From: benji300 Date: Mon, 17 May 2021 22:51:57 +0200 Subject: [PATCH] Update to latest API version + fixed vulnerabilities --- CHANGELOG.md | 4 + api/Global.d.ts | 6 +- api/Joplin.d.ts | 13 ++ api/JoplinPlugins.d.ts | 17 ++ api/JoplinSettings.d.ts | 9 +- api/JoplinWorkspace.d.ts | 2 +- api/types.ts | 49 ++++- package-lock.json | 13 +- src/settings.ts | 456 +++++++++++++++++++-------------------- 9 files changed, 325 insertions(+), 244 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e1b72..d0fb29c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Escape html characters from note titles before using them as tab titles +### Removed + +- Bundled font packages (FontAwesome, Roboto). Use built-in versions now + ## [1.3.0] - 2021-03-09 ### Added diff --git a/api/Global.d.ts b/api/Global.d.ts index 1bc9783..686ccf1 100644 --- a/api/Global.d.ts +++ b/api/Global.d.ts @@ -1,14 +1,14 @@ import Plugin from '../Plugin'; import Joplin from './Joplin'; +/** + * @ignore + */ /** * @ignore */ export default class Global { private joplin_; - private requireWhiteList_; constructor(implementation: any, plugin: Plugin, store: any); get joplin(): Joplin; - private requireWhiteList; - require(filePath: string): any; get process(): any; } diff --git a/api/Joplin.d.ts b/api/Joplin.d.ts index 2d5ee2c..e30586e 100644 --- a/api/Joplin.d.ts +++ b/api/Joplin.d.ts @@ -49,4 +49,17 @@ export default class Joplin { get views(): JoplinViews; get interop(): JoplinInterop; get settings(): JoplinSettings; + /** + * It is not possible to bundle native packages with a plugin, because they + * need to work cross-platforms. Instead access to certain useful native + * packages is provided using this function. + * + * Currently these packages are available: + * + * - [sqlite3](https://www.npmjs.com/package/sqlite3) + * - [fs-extra](https://www.npmjs.com/package/fs-extra) + * + * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/nativeModule) + */ + require(_path: string): any; } diff --git a/api/JoplinPlugins.d.ts b/api/JoplinPlugins.d.ts index 56e7e8d..a1e4a83 100644 --- a/api/JoplinPlugins.d.ts +++ b/api/JoplinPlugins.d.ts @@ -23,4 +23,21 @@ export default class JoplinPlugins { * @deprecated Use joplin.contentScripts.register() */ registerContentScript(type: ContentScriptType, id: string, scriptPath: string): Promise; + /** + * Gets the plugin own data directory path. Use this to store any + * plugin-related data. Unlike [[installationDir]], any data stored here + * will be persisted. + */ + dataDir(): Promise; + /** + * Gets the plugin installation directory. This can be used to access any + * asset that was packaged with the plugin. This directory should be + * considered read-only because any data you store here might be deleted or + * re-created at any time. To store new persistent data, use [[dataDir]]. + */ + installationDir(): Promise; + /** + * @deprecated Use joplin.require() + */ + require(_path: string): any; } diff --git a/api/JoplinSettings.d.ts b/api/JoplinSettings.d.ts index 82e4ab3..a22b907 100644 --- a/api/JoplinSettings.d.ts +++ b/api/JoplinSettings.d.ts @@ -22,11 +22,18 @@ export default class JoplinSettings { private get keyPrefix(); private namespacedKey; /** - * Registers a new setting. Note that registering a setting item is dynamic and will be gone next time Joplin starts. + * Registers new settings. + * Note that registering a setting item is dynamic and will be gone next time Joplin starts. * What it means is that you need to register the setting every time the plugin starts (for example in the onStart event). * The setting value however will be preserved from one launch to the next so there is no risk that it will be lost even if for some * reason the plugin fails to start at some point. */ + registerSettings(settings: Record): Promise; + /** + * @deprecated Use joplin.settings.registerSettings() + * + * Registers a new setting. + */ registerSetting(key: string, settingItem: SettingItem): Promise; /** * Registers a new setting section. Like for registerSetting, it is dynamic and needs to be done every time the plugin starts. diff --git a/api/JoplinWorkspace.d.ts b/api/JoplinWorkspace.d.ts index 90914af..2291757 100644 --- a/api/JoplinWorkspace.d.ts +++ b/api/JoplinWorkspace.d.ts @@ -35,7 +35,7 @@ export default class JoplinWorkspace { */ onNoteContentChange(callback: Function): Promise; /** - * Called when the content of a note changes. + * Called when the content of the current note changes. */ onNoteChange(handler: ItemChangeHandler): Promise; /** diff --git a/api/types.ts b/api/types.ts index c8110fb..ed817ba 100644 --- a/api/types.ts +++ b/api/types.ts @@ -330,16 +330,57 @@ export enum SettingItemType { export interface SettingItem { value: any; type: SettingItemType; - public: boolean; - label: string; + label: string; description?: string; - isEnum?: boolean; + + /** + * A public setting will appear in the Configuration screen and will be + * modifiable by the user. A private setting however will not appear there, + * and can only be changed programmatically. You may use this to store some + * values that you do not want to directly expose. + */ + public: boolean; + + /** + * You would usually set this to a section you would have created + * specifically for the plugin. + */ section?: string; - options?: any; + + /** + * To create a setting with multiple options, set this property to `true`. + * That setting will render as a dropdown list in the configuration screen. + */ + isEnum?: boolean; + + /** + * This property is required when `isEnum` is `true`. In which case, it + * should contain a map of value => label. + */ + options?: Record; + + /** + * Reserved property. Not used at the moment. + */ appTypes?: string[]; + + /** + * Set this to `true` to store secure data, such as passwords. Any such + * setting will be stored in the system keychain if one is available. + */ secure?: boolean; + + /** + * An advanced setting will be moved under the "Advanced" button in the + * config screen. + */ advanced?: boolean; + + /** + * Set the min, max and step values if you want to restrict an int setting + * to a particular range. + */ minimum?: number; maximum?: number; step?: number; diff --git a/package-lock.json b/package-lock.json index 1d3a35b..8e5cc1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3359,9 +3359,9 @@ } }, "ssri": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.0.tgz", - "integrity": "sha512-aq/pz989nxVYwn16Tsbj1TqFpD5LLrQxHf5zaHuieFV+R0Bbr4y8qUsOA45hXT/N4/9UNXTarBjnjVmjSOVaAA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", + "integrity": "sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ==", "dev": true, "requires": { "minipass": "^3.1.1" @@ -4618,10 +4618,9 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", - "dev": true + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" }, "yallist": { "version": "4.0.0", diff --git a/src/settings.ts b/src/settings.ts index 3cb8685..dec1b0b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -185,242 +185,242 @@ export class Settings { * Register settings section with all options and intially read them at the end. */ async register() { - // settings section + // register settings in own section await joplin.settings.registerSection('note.tabs.settings', { label: 'Note Tabs', iconName: 'fas fa-window-maximize' }); - - // private settings - await joplin.settings.registerSetting('noteTabs', { - value: [], - type: SettingItemType.Array, - section: 'note.tabs.settings', - public: false, - label: 'Note tabs' - }); - this._noteTabs = await joplin.settings.value('noteTabs'); - - // general settings - await joplin.settings.registerSetting('enableDragAndDrop', { - value: this._enableDragAndDrop, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Enable drag & drop of tabs', - description: 'If disabled, position of tabs can be change via commands or move buttons.' - }); - await joplin.settings.registerSetting('showTodoCheckboxes', { - value: this._showTodoCheckboxes, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Show to-do checkboxes on tabs', - description: 'If enabled, to-dos can be completed directly on the tabs.' - }); - await joplin.settings.registerSetting('showBreadcrumbs', { - value: this._showBreadcrumbs, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Show breadcrumbs', - description: 'Display full breadcrumbs for selected note. Displayed below the tabs in horizontal layout only.' - }); - await joplin.settings.registerSetting('showNavigationButtons', { - value: this._showNavigationButtons, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Show navigation buttons', - description: 'Display history backward and forward buttons. Displayed below the tabs in horizontal layout only.' - }); - await joplin.settings.registerSetting('showChecklistStatus', { - value: this._showChecklistStatus, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Show checklist completion status', - description: 'Display completion status of all checklists in the selected note. Displayed below the tabs in horizontal layout only.' - }); - await joplin.settings.registerSetting('pinEditedNotes', { - value: this._pinEditedNotes, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Automatically pin notes when edited', - description: 'Pin notes automatically as soon as the title, content or any other attribute changes.' - }); - await joplin.settings.registerSetting('unpinCompletedTodos', { - value: this._unpinCompletedTodos, - type: SettingItemType.Bool, - section: 'note.tabs.settings', - public: true, - label: 'Automatically unpin completed to-dos', - description: 'Unpin notes automatically as soon as the to-do status changes to completed. ' + - 'Removes the tab completely unless it is the selected note.' - }); - await joplin.settings.registerSetting('addBehavior', { - value: AddBehavior.Temporary, - type: SettingItemType.Int, - section: 'note.tabs.settings', - isEnum: true, - public: true, - label: 'Add tab behavior', - description: 'Specify how new tabs are added to the panel. Either as temporary or directly as pinned tab. ' + - 'Only one temporary (italic font) tab exists at a time.', - options: { - '0': 'Temporary', - '1': 'Pinned' + await joplin.settings.registerSettings({ + // private settings + noteTabs: { + value: [], + type: SettingItemType.Array, + section: 'note.tabs.settings', + public: false, + label: 'Note tabs' }, - }); - await joplin.settings.registerSetting('unpinBehavior', { - value: UnpinBehavior.Keep, - type: SettingItemType.Int, - section: 'note.tabs.settings', - isEnum: true, - public: true, - label: 'Unpin active tab behavior', - description: 'Specify the behavior when unpinning the current active tab. ' + - 'Either keep the active tab selected (may replaces the temporary one) or select another one, depending on the setting.', - options: { - '0': 'Keep selected', - '1': 'Select last active tab', - '2': 'Select left tab', - '3': 'Select right tab' + // general settings + enableDragAndDrop: { + value: this._enableDragAndDrop, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Enable drag & drop of tabs', + description: 'If disabled, position of tabs can be change via commands or move buttons.' }, - }); - await joplin.settings.registerSetting('layoutMode', { - value: LayoutMode.Auto, - type: SettingItemType.Int, - section: 'note.tabs.settings', - isEnum: true, - public: true, - label: 'Force tabs layout', - description: 'Force tabs horizontal or vertical layout. If Auto, the layout switches automatically at a width of about 400px. Requires restart to be applied.', - options: { - '0': 'Auto', - '1': 'Horizontal', - '2': 'Vertical' + showTodoCheckboxes: { + value: this._showTodoCheckboxes, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Show to-do checkboxes on tabs', + description: 'If enabled, to-dos can be completed directly on the tabs.' }, + showBreadcrumbs: { + value: this._showBreadcrumbs, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Show breadcrumbs', + description: 'Display full breadcrumbs for selected note. Displayed below the tabs in horizontal layout only.' + }, + showNavigationButtons: { + value: this._showNavigationButtons, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Show navigation buttons', + description: 'Display history backward and forward buttons. Displayed below the tabs in horizontal layout only.' + }, + showChecklistStatus: { + value: this._showChecklistStatus, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Show checklist completion status', + description: 'Display completion status of all checklists in the selected note. Displayed below the tabs in horizontal layout only.' + }, + pinEditedNotes: { + value: this._pinEditedNotes, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Automatically pin notes when edited', + description: 'Pin notes automatically as soon as the title, content or any other attribute changes.' + }, + unpinCompletedTodos: { + value: this._unpinCompletedTodos, + type: SettingItemType.Bool, + section: 'note.tabs.settings', + public: true, + label: 'Automatically unpin completed to-dos', + description: 'Unpin notes automatically as soon as the to-do status changes to completed. ' + + 'Removes the tab completely unless it is the selected note.' + }, + addBehavior: { + value: AddBehavior.Temporary, + type: SettingItemType.Int, + section: 'note.tabs.settings', + isEnum: true, + public: true, + label: 'Add tab behavior', + description: 'Specify how new tabs are added to the panel. Either as temporary or directly as pinned tab. ' + + 'Only one temporary (italic font) tab exists at a time.', + options: { + '0': 'Temporary', + '1': 'Pinned' + } + }, + unpinBehavior: { + value: UnpinBehavior.Keep, + type: SettingItemType.Int, + section: 'note.tabs.settings', + isEnum: true, + public: true, + label: 'Unpin active tab behavior', + description: 'Specify the behavior when unpinning the current active tab. ' + + 'Either keep the active tab selected (may replaces the temporary one) or select another one, depending on the setting.', + options: { + '0': 'Keep selected', + '1': 'Select last active tab', + '2': 'Select left tab', + '3': 'Select right tab' + } + }, + layoutMode: { + value: LayoutMode.Auto, + type: SettingItemType.Int, + section: 'note.tabs.settings', + isEnum: true, + public: true, + label: 'Force tabs layout', + description: 'Force tabs horizontal or vertical layout. If Auto, the layout switches automatically at a width of about 400px. Requires restart to be applied.', + options: { + '0': 'Auto', + '1': 'Horizontal', + '2': 'Vertical' + } + }, + // advanced settings + tabHeight: { + value: this._tabHeight, + type: SettingItemType.Int, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Note Tabs height (px)', + description: 'Height of the tabs. Row height in vertical layout.' + }, + minTabWidth: { + value: this._minTabWidth, + type: SettingItemType.Int, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Minimum Tab width (px)', + description: 'Minimum width of one tab in pixel.' + }, + maxTabWidth: { + value: this._maxTabWidth, + type: SettingItemType.Int, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Maximum Tab width (px)', + description: 'Maximum width of one tab in pixel.' + }, + breadcrumbsMaxWidth: { + value: this._breadcrumbsMaxWidth, + type: SettingItemType.Int, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Maximum breadcrumb width (px)', + description: 'Maximum width of one breadcrumb in pixel.' + }, + fontFamily: { + value: this._fontFamily, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Font family', + description: "Font family used in the panel. Font families other than 'default' must be installed on the system. If the font is incorrect or empty, it might default to a generic sans-serif font. (default: App default)" + }, + fontSize: { + value: this._fontSize, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Font size', + description: "Font size used in the panel. Values other than 'default' must be specified in valid CSS syntax, e.g. '13px'. (default: App default font size)" + }, + mainBackground: { + value: this._background, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Background color', + description: 'Main background color of the panel. (default: Note list background color)' + }, + hoverBackground: { + value: this._hoverBackground, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Hover Background color', + description: 'Background color used when hovering a favorite. (default: Note list hover color)' + }, + activeBackground: { + value: this._actBackground, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Active background color', + description: 'Background color of the current active tab. (default: Editor background color)' + }, + breadcrumbsBackground: { + value: this._breadcrumbsBackground, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Infobar background color', + description: 'Background color of the info bar (incl. breadcrumbs, etc.) below the tabs. (default: Editor background color)' + }, + mainForeground: { + value: this._foreground, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Foreground color', + description: 'Foreground color used for text and icons. (default: App faded color)' + }, + activeForeground: { + value: this._actForeground, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Active foreground color', + description: 'Foreground color of the current active tab. (default: Editor font color)' + }, + dividerColor: { + value: this._dividerColor, + type: SettingItemType.String, + section: 'note.tabs.settings', + public: true, + advanced: true, + label: 'Divider color', + description: 'Color of the divider between the tabs. (default: App default border color)' + } }); - // advanced settings - await joplin.settings.registerSetting('tabHeight', { - value: this._tabHeight, - type: SettingItemType.Int, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Note Tabs height (px)', - description: 'Height of the tabs. Row height in vertical layout.' - }); - await joplin.settings.registerSetting('minTabWidth', { - value: this._minTabWidth, - type: SettingItemType.Int, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Minimum Tab width (px)', - description: 'Minimum width of one tab in pixel.' - }); - await joplin.settings.registerSetting('maxTabWidth', { - value: this._maxTabWidth, - type: SettingItemType.Int, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Maximum Tab width (px)', - description: 'Maximum width of one tab in pixel.' - }); - await joplin.settings.registerSetting('breadcrumbsMaxWidth', { - value: this._breadcrumbsMaxWidth, - type: SettingItemType.Int, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Maximum breadcrumb width (px)', - description: 'Maximum width of one breadcrumb in pixel.' - }); - await joplin.settings.registerSetting('fontFamily', { - value: this._fontFamily, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Font family', - description: "Font family used in the panel. Font families other than 'default' must be installed on the system. If the font is incorrect or empty, it might default to a generic sans-serif font. (default: App default)" - }); - await joplin.settings.registerSetting('fontSize', { - value: this._fontSize, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Font size', - description: "Font size used in the panel. Values other than 'default' must be specified in valid CSS syntax, e.g. '13px'. (default: App default font size)" - }); - await joplin.settings.registerSetting('mainBackground', { - value: this._background, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Background color', - description: 'Main background color of the panel. (default: Note list background color)' - }); - await joplin.settings.registerSetting('hoverBackground', { - value: this._hoverBackground, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Hover Background color', - description: 'Background color used when hovering a favorite. (default: Note list hover color)' - }); - await joplin.settings.registerSetting('activeBackground', { - value: this._actBackground, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Active background color', - description: 'Background color of the current active tab. (default: Editor background color)' - }); - await joplin.settings.registerSetting('breadcrumbsBackground', { - value: this._breadcrumbsBackground, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Infobar background color', - description: 'Background color of the info bar (incl. breadcrumbs, etc.) below the tabs. (default: Editor background color)' - }); - await joplin.settings.registerSetting('mainForeground', { - value: this._foreground, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Foreground color', - description: 'Foreground color used for text and icons. (default: App faded color)' - }); - await joplin.settings.registerSetting('activeForeground', { - value: this._actForeground, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Active foreground color', - description: 'Foreground color of the current active tab. (default: Editor font color)' - }); - await joplin.settings.registerSetting('dividerColor', { - value: this._dividerColor, - type: SettingItemType.String, - section: 'note.tabs.settings', - public: true, - advanced: true, - label: 'Divider color', - description: 'Color of the divider between the tabs. (default: App default border color)' - }); + this._noteTabs = await joplin.settings.value('noteTabs'); // initially read settings await this.read();