From 549aff5887d032d1cd9042ea95f18c73f76b9aa8 Mon Sep 17 00:00:00 2001 From: rxliuli Date: Thu, 5 Jan 2023 18:58:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=9C=8D=E5=8A=A1=E6=97=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20baseUrl=20=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/joplin-vscode-plugin/package.json | 2 +- .../src/config/AppConfig.ts | 17 ++- apps/joplin-vscode-plugin/src/extension.ts | 3 +- .../src/service/HandlerService.ts | 7 +- .../src/service/JoplinNoteCommandService.ts | 2 +- .../src/util/checkJoplinServer.ts | 9 +- .../package.json | 2 +- .../src/manifest.json | 27 ---- .../__tests__/convertManifest3To2.test.ts | 134 ++++++++++-------- .../src/utils/convertManifest3To2.ts | 29 ++-- 10 files changed, 117 insertions(+), 115 deletions(-) delete mode 100644 libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json diff --git a/apps/joplin-vscode-plugin/package.json b/apps/joplin-vscode-plugin/package.json index 877b1f35..f18f1d43 100644 --- a/apps/joplin-vscode-plugin/package.json +++ b/apps/joplin-vscode-plugin/package.json @@ -1,6 +1,6 @@ { "name": "joplin-vscode-plugin", - "version": "1.1.0", + "version": "1.1.1", "description": "%package.description%", "homepage": "https://joplin-utils.rxliuli.com/zh/joplin-vscode-plugin/", "repository": { diff --git a/apps/joplin-vscode-plugin/src/config/AppConfig.ts b/apps/joplin-vscode-plugin/src/config/AppConfig.ts index ecee706a..abb984ef 100644 --- a/apps/joplin-vscode-plugin/src/config/AppConfig.ts +++ b/apps/joplin-vscode-plugin/src/config/AppConfig.ts @@ -1,3 +1,4 @@ +import { config } from 'joplin-api' import * as vscode from 'vscode' export enum SortNotesTypeEnum { @@ -22,13 +23,15 @@ export class AppConfig { * reload joplin for vscode config */ loadConfig() { - const config = vscode.workspace.getConfiguration('joplin') - this.token = config.token - this.baseUrl = config.baseUrl - this.deleteConfirm = config.deleteConfirm - this.sortNotes = config.sortNotes - this.sortNotesType = config.sortNotesType - this.sortOrder = config.sortOrder + const c = vscode.workspace.getConfiguration('joplin') + this.token = c.token + this.baseUrl = c.baseUrl + this.deleteConfirm = c.deleteConfirm + this.sortNotes = c.sortNotes + this.sortNotesType = c.sortNotesType + this.sortOrder = c.sortOrder + config.baseUrl = this.baseUrl + config.token = this.token! if (process.env.DEBUG) { console.log( 'loadConfig: ', diff --git a/apps/joplin-vscode-plugin/src/extension.ts b/apps/joplin-vscode-plugin/src/extension.ts index cecc68b4..87d75649 100644 --- a/apps/joplin-vscode-plugin/src/extension.ts +++ b/apps/joplin-vscode-plugin/src/extension.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode' import { NoteExplorerProvider } from './model/NoteExplorerProvider' import { JoplinNoteCommandService } from './service/JoplinNoteCommandService' -import { TypeEnum } from 'joplin-api' +import { config, TypeEnum } from 'joplin-api' import { appConfig } from './config/AppConfig' import { HandlerService } from './service/HandlerService' import { checkJoplinServer } from './util/checkJoplinServer' @@ -36,6 +36,7 @@ export async function activate(context: vscode.ExtensionContext) { logger .add(new transports.File({ filename: path.resolve(logPath, 'error.log'), level: 'error' })) .add(new transports.File({ filename: path.resolve(logPath, 'combined.log') })) + logger.info(`joplin config, baseUrl: ${config.baseUrl}, token: ${typeof config.token}`) await init() if (!(await checkJoplinServer())) { return diff --git a/apps/joplin-vscode-plugin/src/service/HandlerService.ts b/apps/joplin-vscode-plugin/src/service/HandlerService.ts index 4a7a5695..b61beefb 100644 --- a/apps/joplin-vscode-plugin/src/service/HandlerService.ts +++ b/apps/joplin-vscode-plugin/src/service/HandlerService.ts @@ -1,9 +1,8 @@ import * as vscode from 'vscode' import { TextDocument, Uri } from 'vscode' -import { noteApi, resourceApi, TypeEnum } from 'joplin-api' +import { noteApi, resourceApi } from 'joplin-api' import { parse } from 'querystring' import { JoplinNoteCommandService } from './JoplinNoteCommandService' -import { JoplinTreeItem } from '../model/JoplinTreeItem' import { JoplinNoteUtil } from '../util/JoplinNoteUtil' import { OpenFileService } from '../util/OpenFileService' import { safePromise } from '../util/safePromise' @@ -35,13 +34,13 @@ export class HandlerService { if (!noteId) { return } - console.log('close note: ', noteId) + logger.info(`close note, noteId: ${noteId}, fileName: ${path.basename(e.fileName)}`) await remove(e.fileName) GlobalContext.openNoteMap.delete(noteId) GlobalContext.openNoteResourceMap.delete(noteId) } else if (GlobalContext.openResourceMap.has(e.uri.fsPath)) { const resourceId = GlobalContext.openResourceMap.get(e.fileName)! - console.log('close resourceId: ', resourceId) + logger.info(`close resource, id: ${resourceId}, fileName: ${path.basename(e.fileName)}`) await remove(e.fileName) GlobalContext.openResourceMap.delete(resourceId) } diff --git a/apps/joplin-vscode-plugin/src/service/JoplinNoteCommandService.ts b/apps/joplin-vscode-plugin/src/service/JoplinNoteCommandService.ts index 44eea179..fbf817be 100644 --- a/apps/joplin-vscode-plugin/src/service/JoplinNoteCommandService.ts +++ b/apps/joplin-vscode-plugin/src/service/JoplinNoteCommandService.ts @@ -226,7 +226,7 @@ export class JoplinNoteCommandService { const note = await noteApi.get(item.id, ['body', 'title']) const content = (note.title.startsWith('# ') ? '' : '# ') + note.title + '\n\n' + note.body await writeFile(tempNotePath, content) - logger.info('openNote write tempFile: ' + tempNotePath) + logger.info('openNote write tempFile: ' + path.basename(tempNotePath)) GlobalContext.openNoteMap.set(item.id, tempNotePath) GlobalContext.openNoteResourceMap.set(item.id, await noteApi.resourcesById(item.id)) await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(tempNotePath)) diff --git a/apps/joplin-vscode-plugin/src/util/checkJoplinServer.ts b/apps/joplin-vscode-plugin/src/util/checkJoplinServer.ts index 494f9566..fc2d17b3 100644 --- a/apps/joplin-vscode-plugin/src/util/checkJoplinServer.ts +++ b/apps/joplin-vscode-plugin/src/util/checkJoplinServer.ts @@ -10,6 +10,10 @@ export async function checkJoplinServer() { vscode.window.showErrorMessage( `Joplin's token/port is set incorrectly, unable to access Joplin service! Are you sure it is running and active?`, ) + if (!appConfig.token) { + vscode.window.showInformationMessage('Please configure joplin token first, and then restart VSCode!') + return false + } try { if (!(await joplinApi.ping())) { errMsg() @@ -21,9 +25,6 @@ export async function checkJoplinServer() { console.log('Error message: \n', e) return false } - if (!appConfig.token) { - vscode.window.showInformationMessage('Please configure joplin token first, and then restart VSCode!') - return false - } + return true } diff --git a/libs/vite-plugin-chrome-extension-dist-firefox/package.json b/libs/vite-plugin-chrome-extension-dist-firefox/package.json index ebaeff2c..49fba0ea 100644 --- a/libs/vite-plugin-chrome-extension-dist-firefox/package.json +++ b/libs/vite-plugin-chrome-extension-dist-firefox/package.json @@ -1,6 +1,6 @@ { "name": "@liuli-util/vite-plugin-chrome-extension-dist-firefox", - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "type": "module", "exports": { diff --git a/libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json b/libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json deleted file mode 100644 index e0f72108..00000000 --- a/libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "Joplin Search Integration", - "version": "0.2.1", - "description": "When using search, related Joplin notes are also displayed in the search results.", - "manifest_version": 3, - "background": { - "service_worker": "background.ts" - }, - "content_scripts": [ - { - "matches": [""], - "js": ["content-scripts/main.ts"] - } - ], - "action": { - "default_popup": "popup/index.html" - }, - "host_permissions": ["http://localhost:27583/*", "http://localhost:41184/*"], - "permissions": ["storage"], - "icons": { - "16": "assets/icon-16.png", - "32": "assets/icon-32.png", - "48": "assets/icon-48.png", - "128": "assets/icon-128.png" - }, - "options_page": "options/index.html" -} diff --git a/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts b/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts index a4a3abbf..ffa4fc64 100644 --- a/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts +++ b/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts @@ -1,64 +1,84 @@ import { expect, it } from 'vitest' import { convertManifest3To2 } from '../convertManifest3To2' -const v3 = { - name: 'Joplin Search Integration', - version: '0.2.1', - description: 'When using search, related Joplin notes are also displayed in the search results.', - manifest_version: 3, - background: { - service_worker: 'background.js', - }, - content_scripts: [ - { - matches: [''], - js: ['content-scripts/main.js'], +it('convertManifestChromeToFirefox', () => { + expect( + convertManifest3To2({ + name: 'Joplin Search Integration', + version: '0.2.1', + description: 'When using search, related Joplin notes are also displayed in the search results.', + manifest_version: 3, + background: { + service_worker: 'background.js', + }, + content_scripts: [ + { + matches: [''], + js: ['content-scripts/main.js'], + }, + ], + action: { + default_popup: 'popup/index.html', + }, + host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], + permissions: ['storage'], + icons: { + '16': 'assets/icon-16.png', + '32': 'assets/icon-32.png', + '48': 'assets/icon-48.png', + '128': 'assets/icon-128.png', + }, + options_page: 'options/index.html', + }), + ).deep.eq({ + name: 'Joplin Search Integration', + version: '0.2.1', + description: 'When using search, related Joplin notes are also displayed in the search results.', + manifest_version: 2, + background: { + scripts: ['background.js'], }, - ], - action: { - default_popup: 'popup/index.html', - }, - host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], - permissions: ['storage'], - icons: { - '16': 'assets/icon-16.png', - '32': 'assets/icon-32.png', - '48': 'assets/icon-48.png', - '128': 'assets/icon-128.png', - }, - options_page: 'options/index.html', -} - -const v2 = { - name: 'Joplin Search Integration', - version: '0.2.1', - description: 'When using search, related Joplin notes are also displayed in the search results.', - manifest_version: 2, - background: { - scripts: ['background.js'], - }, - content_scripts: [ - { - matches: [''], - js: ['content-scripts/main.js'], + content_scripts: [ + { + matches: [''], + js: ['content-scripts/main.js'], + }, + ], + browser_action: { + default_popup: 'popup/index.html', + }, + permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', ''], + icons: { + '16': 'assets/icon-16.png', + '32': 'assets/icon-32.png', + '48': 'assets/icon-48.png', + '128': 'assets/icon-128.png', + }, + options_ui: { + page: 'options/index.html', + browser_style: true, }, - ], - browser_action: { - default_popup: 'popup/index.html', - }, - permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', ''], - icons: { - '16': 'assets/icon-16.png', - '32': 'assets/icon-32.png', - '48': 'assets/icon-48.png', - '128': 'assets/icon-128.png', - }, - options_ui: { - page: 'options/index.html', - browser_style: true, - }, -} + }) +}) -it('convertManifestChromeToFirefox', () => { - expect(convertManifest3To2(v3)).deep.eq(v2) +it('basic', () => { + expect( + convertManifest3To2({ + name: 'Joplin Search Integration', + version: '0.2.1', + description: 'When using search, related Joplin notes are also displayed in the search results.', + manifest_version: 3, + background: { + service_worker: 'background.js', + }, + }), + ).deep.eq({ + name: 'Joplin Search Integration', + version: '0.2.1', + description: 'When using search, related Joplin notes are also displayed in the search results.', + manifest_version: 2, + background: { + scripts: ['background.js'], + }, + }) }) diff --git a/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/convertManifest3To2.ts b/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/convertManifest3To2.ts index b8c94e78..0a5ae873 100644 --- a/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/convertManifest3To2.ts +++ b/libs/vite-plugin-chrome-extension-dist-firefox/src/utils/convertManifest3To2.ts @@ -1,18 +1,23 @@ -import manifest3 from '../manifest.json' - -export function convertManifest3To2(manifest: typeof manifest3) { +export function convertManifest3To2(manifest: any) { const { background, action, manifest_version, host_permissions, permissions, options_page, ...other } = manifest - return { - ...other, - background: { + const r = other as any + r.manifest_version = 2 + if (background.service_worker) { + r.background = { scripts: [background.service_worker], - }, - browser_action: action, - manifest_version: 2, - permissions: [...permissions, ...(host_permissions ? [...host_permissions, ''] : [])], - options_ui: { + } + } + if (options_page) { + r.options_ui = { page: options_page, browser_style: true, - }, + } + } + if (action) { + r.browser_action = action + } + if (permissions) { + r.permissions = [...permissions, ...(host_permissions ? [...host_permissions, ''] : [])] } + return r }