From a70e70bea452249181df2aba6b7a769cace5ffe4 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Wed, 20 Sep 2023 13:03:04 +0200 Subject: [PATCH] 0.3.0 Set theme mode on upload --- manifest.json | 2 +- package-lock.json | 4 +-- package.json | 2 +- src/api.ts | 6 ++--- src/note.ts | 1 + src/settings.ts | 62 +++++++++++++++++++++++++++++++++++++---------- src/template.ts | 17 ++++++++++++- versions.json | 3 ++- 8 files changed, 75 insertions(+), 22 deletions(-) diff --git a/manifest.json b/manifest.json index 0b0fb8d..f5d91b3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "share-note", "name": "Share Note", - "version": "0.2.13", + "version": "0.3.0", "minAppVersion": "0.15.0", "description": "Share a note publicly with full styling. Data is stored encrypted on the server and only you have the key.", "author": "Alan Grainger", diff --git a/package-lock.json b/package-lock.json index 93cd36a..e4c0002 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "share-note", - "version": "0.2.5", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "share-note", - "version": "0.2.5", + "version": "0.3.0", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index 82d9705..e9fc163 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "share-note", - "version": "0.2.13", + "version": "0.3.0", "description": "Share a note publicly with full styling. Data is stored encrypted on the server and only you have the key.", "main": "main.js", "scripts": { diff --git a/src/api.ts b/src/api.ts index f0f0673..1bc39ab 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,8 +12,8 @@ const statusCodes: { [key: number]: string } = { } export interface UploadData { - filename: string; - content: string; + filename?: string; + content?: string; encoding?: string; } @@ -24,7 +24,7 @@ export default class API { this.plugin = plugin } - async post (endpoint: string, data: any = {}) { + async post (endpoint: string, data: UploadData = {}) { Object.assign(data, { id: this.plugin.settings.uid, key: this.plugin.settings.apiKey, diff --git a/src/note.ts b/src/note.ts index 213e8b8..6da7764 100644 --- a/src/note.ts +++ b/src/note.ts @@ -96,6 +96,7 @@ export default class Note { if (!this.plugin.settings.showFooter) { this.outputFile.removeFooter() } + this.outputFile.setThemeMode(this.plugin.settings.themeMode) // must be after setBodyClasses // Generate the HTML file for uploading this.dom = new DOMParser().parseFromString(this.content, 'text/html') diff --git a/src/settings.ts b/src/settings.ts index 36196de..f4f48af 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,12 +1,19 @@ import { App, PluginSettingTab, Setting, TextComponent } from 'obsidian' import SharePlugin from './main' +export enum ThemeMode { + 'Same as theme', + Dark, + Light +} + export interface ShareSettings { server: string; uid: string; apiKey: string; yamlField: string; noteWidth: string; + themeMode: ThemeMode; showFooter: boolean; removeYaml: boolean; clipboard: boolean; @@ -18,6 +25,7 @@ export const DEFAULT_SETTINGS: ShareSettings = { apiKey: '', yamlField: 'share', noteWidth: '700px', + themeMode: ThemeMode['Same as theme'], showFooter: true, removeYaml: true, clipboard: true @@ -37,6 +45,10 @@ export class ShareSettingsTab extends PluginSettingTab { containerEl.empty() + new Setting(containerEl) + .setName('Plugin setup') + .setHeading() + // API key new Setting(containerEl) .setName('API key') @@ -70,6 +82,26 @@ export class ShareSettingsTab extends PluginSettingTab { await this.plugin.saveSettings() })) + new Setting(containerEl) + .setName('Upload options') + .setHeading() + + // Show/hide the footer + new Setting(containerEl) + .setName('Light/Dark mode') + .setDesc('Choose the mode with which your files will be shared') + .addDropdown(dropdown => { + dropdown + .addOption('Same as theme', 'Same as theme') + .addOption('Dark', 'Dark') + .addOption('Light', 'Light') + .setValue(ThemeMode[this.plugin.settings.themeMode]) + .onChange(async value => { + this.plugin.settings.themeMode = ThemeMode[value as keyof typeof ThemeMode] + await this.plugin.saveSettings() + }) + }) + // Strip frontmatter new Setting(containerEl) .setName('Remove published frontmatter/YAML') @@ -84,19 +116,6 @@ export class ShareSettingsTab extends PluginSettingTab { }) }) - // Show/hide the footer - new Setting(containerEl) - .setName('Show the footer') - .addToggle(toggle => { - toggle - .setValue(this.plugin.settings.showFooter) - .onChange(async (value) => { - this.plugin.settings.showFooter = value - await this.plugin.saveSettings() - this.display() - }) - }) - // Copy to clipboard new Setting(containerEl) .setName('Copy the link to clipboard after sharing') @@ -110,6 +129,23 @@ export class ShareSettingsTab extends PluginSettingTab { }) }) + // Show/hide the footer + new Setting(containerEl) + .setName('Show the footer') + .addToggle(toggle => { + toggle + .setValue(this.plugin.settings.showFooter) + .onChange(async (value) => { + this.plugin.settings.showFooter = value + await this.plugin.saveSettings() + this.display() + }) + }) + + new Setting(containerEl) + .setName('Debug info') + .setHeading() + new Setting(containerEl) .setName('User ID') .setDesc('If you need it for debugging purposes, this is your user ID') diff --git a/src/template.ts b/src/template.ts index e858e6f..6618aef 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,6 +1,10 @@ // noinspection CssInvalidPropertyValue,HtmlRequiredLangAttribute,HtmlUnknownTarget +import { ThemeMode } from './settings' + /** + * CSS info: + * * .reading-view-extra gives a custom width for the note text. * .status-bar makes the status bar pinned to the right, rather than full-page. */ @@ -67,7 +71,7 @@ const html = ` document.body.classList.remove(...mobileClasses) } } - window.addEventListener('resize', toggleMobileClasses }) + window.addEventListener('resize', toggleMobileClasses ) toggleMobileClasses() function base64ToArrayBuffer(base64) { @@ -195,4 +199,15 @@ export default class Template { this.dom.head.appendChild(desc) this.dom.head.appendChild(ogDesc) } + + setThemeMode (mode: ThemeMode) { + if (mode === ThemeMode['Same as theme']) { + // Nothing to change + } else { + // Remove the existing theme + this.dom.body.removeClasses(['theme-dark', 'theme-light']) + // Add the preferred class + this.dom.body.addClasses(['theme-' + ThemeMode[mode]]) + } + } } diff --git a/versions.json b/versions.json index 5634fa2..8c7c4ac 100644 --- a/versions.json +++ b/versions.json @@ -19,5 +19,6 @@ "0.2.10": "0.15.0", "0.2.11": "0.15.0", "0.2.12": "0.15.0", - "0.2.13": "0.15.0" + "0.2.13": "0.15.0", + "0.3.0": "0.15.0" }