Skip to content

Commit

Permalink
fix: 修复插件检查服务时没有使用 baseUrl 的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
rxliuli committed Jan 5, 2023
1 parent 190e33f commit 549aff5
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 115 deletions.
2 changes: 1 addition & 1 deletion apps/joplin-vscode-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
17 changes: 10 additions & 7 deletions apps/joplin-vscode-plugin/src/config/AppConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { config } from 'joplin-api'
import * as vscode from 'vscode'

export enum SortNotesTypeEnum {
Expand All @@ -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: ',
Expand Down
3 changes: 2 additions & 1 deletion apps/joplin-vscode-plugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions apps/joplin-vscode-plugin/src/service/HandlerService.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 5 additions & 4 deletions apps/joplin-vscode-plugin/src/util/checkJoplinServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
27 changes: 0 additions & 27 deletions libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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: ['<all_urls>'],
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: ['<all_urls>'],
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: ['<all_urls>'],
js: ['content-scripts/main.js'],
content_scripts: [
{
matches: ['<all_urls>'],
js: ['content-scripts/main.js'],
},
],
browser_action: {
default_popup: 'popup/index.html',
},
permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', '<all_urls>'],
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/*', '<all_urls>'],
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'],
},
})
})
Original file line number Diff line number Diff line change
@@ -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, '<all_urls>'] : [])],
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, '<all_urls>'] : [])]
}
return r
}

0 comments on commit 549aff5

Please sign in to comment.