Skip to content

Commit

Permalink
Merge branch 'release/3.61.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Sep 23, 2023
2 parents 7144e51 + fa1f66a commit ca799b3
Show file tree
Hide file tree
Showing 61 changed files with 785 additions and 192 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ For more information on how to use the following functions, please see [characte

## Changelogs

### [v3.60.1](https://github.com/purocean/yn/releases/tag/v3.60.1) 2023-09-05

[Windows](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-win-x64-3.60.1.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-mac-arm64-3.60.1.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-mac-x64-3.60.1.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-linux-x86_64-3.60.1.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-linux-amd64-3.60.1.deb)

1. feat: add double-click sidebar title to focus on the currently open document function
2. feat: optimize editing experience, adjust editor automatic wrapping, symbol pairing and other details
3. feat: add "Add File" function to the sidebar context menu
4. feat: upgrade PlantUML to v1.2023.10
5. feat: upgrade markdown-it-multimd-table to 4.2.3
6. fix: fix mind map memory leak issue
7. refactor(plugin): rename `ctx.editor.getIsDefault` to `ctx.editor.isDefault`
8. refactor(plugin): add `ctx.editor.isDirty` method
9. feat(plugin): add `DOC_PRE_ENSURE_CURRENT_FILE_SAVED`, `DOC_PRE_SWITCH` hooks
10. feat(plugin): add `ctx.utils.waitCondition` method
### [v3.61.1](https://github.com/purocean/yn/releases/tag/v3.61.1) 2023-09-23

[Windows](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-win-x64-3.60.1.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-mac-arm64-3.60.1.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-mac-x64-3.60.1.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-linux-x86_64-3.60.1.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-linux-amd64-3.60.1.deb)

1. feat: application-associated Markdown files: supports opening files directly in the file manager and dragging them into the application to open files. Non-warehouse files will be rendered in safe mode
2. feat: configuration items: The rendering configuration adds more configurations of the `markdown-it-multimd-table` plug-in; the editor adds a configuration to control whether to display suggestion prompts when typing.
3. feat: editing experience optimization: when dragging a document or image from the sidebar into the editor, a document link or image link is automatically inserted; when a link is pasted after selecting text, the link is automatically inserted and the selected text is used as the link text.
4. feat: optimize the speed of checking updates: the application will sometimes check for updates through yank-note.com
5. feat: optimize the interface UI: adjust the context menu, optimize the rendering of external link icons so that they do not wrap separately, and align the numbers displayed in the sidebar and outline as much as possible, etc.
6. feat: optimize interaction: when the search panel in the warehouse is displayed, the search box will be automatically focused and text selected;
7. feat: the edited file will be added to the application icon context menu in the taskbar or Dock for quick opening.
8. feat: upgrade Electron to 22.3.24
9. fix: when inserting attachments or linked files, the file name containing special characters cannot be displayed as a Markdown link.
10. feat(plugin): add `ctx.base.getAllRepos` `ctx.doc.getAllRepos` `ctx.doc.switchDocByPath` methods

[More release notes](https://github.com/purocean/yn/releases)

Expand Down
28 changes: 14 additions & 14 deletions README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@

## 更新日志

### [v3.60.1](https://github.com/purocean/yn/releases/tag/v3.60.1) 2023-09-05

[Windows](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-win-x64-3.60.1.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-mac-arm64-3.60.1.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-mac-x64-3.60.1.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-linux-x86_64-3.60.1.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.60.1/Yank-Note-linux-amd64-3.60.1.deb)

1. feat: 增加双击侧栏标题聚焦当前打开文档功能
2. feat: 优化编辑体验,调整编辑器自动包裹、符号配对等细节功能
3. feat: 侧栏上下文菜单增加“添加文件”功能
4. feat: 升级 PlantUML 到 v1.2023.10
5. feat: 升级 markdown-it-multimd-table 到 4.2.3
6. fix: 修复脑图内存泄露问题
7. refactor(plugin): `ctx.editor.getIsDefault` 更名为 `ctx.editor.isDefault`
8. refactor(plugin): 增加 `ctx.editor.isDirty` 方法
9. feat(plugin): 增加 `DOC_PRE_ENSURE_CURRENT_FILE_SAVED`, `DOC_PRE_SWITCH` 钩子
10. feat(plugin): 增加 `ctx.utils.waitCondition` 方法
### [v3.61.1](https://github.com/purocean/yn/releases/tag/v3.61.1) 2023-09-23

[Windows](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-win-x64-3.60.1.exe) | [macOS arm64](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-mac-arm64-3.60.1.dmg) | [macOS x64](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-mac-x64-3.60.1.dmg) | [Linux AppImage](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-linux-x86_64-3.60.1.AppImage) | [Linux deb](https://github.com/purocean/yn/releases/download/v3.61.1/Yank-Note-linux-amd64-3.60.1.deb)

1. feat: 应用关联 Markdown 文件:支持在文件管理器中直接打开、拖拽到应用内打开文件。非仓库文件将以安全模式渲染
2. feat: 配置项:渲染配置增加 `markdown-it-multimd-table` 插件更多配置;编辑器增加控制是否键入时候展示建议提示的配置
3. feat: 编辑体验优化:从侧栏拖动文档或图片到编辑器中时,自动插入文档链接或图片链接;选中文本后粘贴链接时,自动插入链接并以选中文本作为链接文本
4. feat: 优化检查更新速度:应用在一些时候会通过 yank-note.com 检查更新
5. feat: 优化界面 UI:调整上下文菜单、优化渲染外链图标不单独换行、侧栏和大纲中的显示的数字尽量对齐等
6. feat: 优化交互:仓库内搜索面板展示时自动聚焦搜索框并选中文本;
7. feat: 编辑过的文件将添加到任务栏或 Dock 中应用图标上下文菜单中,方便快速打开
8. feat: 升级 Electron 到 22.3.24
9. fix: 修复插入附件或链接文件时,文件名中包含特殊字符不能展示为 Markdown 链接的问题
10. feat(plugin): 增加 `ctx.base.getAllRepos` `ctx.doc.getAllRepos` `ctx.doc.switchDocByPath` 方法

[更多发布说明](https://github.com/purocean/yn/releases)

Expand Down
10 changes: 9 additions & 1 deletion electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@
"afterSign": "scripts/notarize.js",
"nsis": {
"perMachine": false
}
},
"fileAssociations": [
{
"ext": "md",
"name": "Markdown File",
"description": "Markdown File",
"role": "Editor"
}
]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yank.note",
"version": "3.60.1",
"version": "3.61.1",
"description": "Yank Note: A highly extensible Markdown editor, designed for productivity.",
"main": "dist/main/app.js",
"license": "AGPL-3.0",
Expand Down Expand Up @@ -41,6 +41,7 @@
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"ip": "^1.1.5",
"jsonrpc-bridge": "^0.0.4",
"jsonwebtoken": "^9.0.0",
"koa": "^2.13.1",
"koa-body": "^4.2.0",
Expand Down Expand Up @@ -102,7 +103,7 @@
"canvas-confetti": "^1.6.0",
"crypto-js": "^3.3.0",
"dom-to-image": "^2.6.0",
"electron": "22.3.17",
"electron": "22.3.24",
"electron-builder": "^23.6.0",
"electron-notarize": "^1.2.2",
"eslint": "^7.11.0",
Expand Down
73 changes: 62 additions & 11 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { protocol, app, Menu, Tray, powerMonitor, dialog, OpenDialogOptions, scr
import type TBrowserWindow from 'electron'
import * as path from 'path'
import * as os from 'os'
import * as fs from 'fs-extra'
import * as yargs from 'yargs'
import httpServer from './server'
import store from './storage'
Expand All @@ -12,6 +13,7 @@ import { transformProtocolRequest } from './protocol'
import startup from './startup'
import { registerAction } from './action'
import { registerShortcut } from './shortcut'
import { initJSONRPCClient, jsonRPCClient } from './jsonrpc'
import { $t } from './i18n'
import { getProxyAgent } from './proxy-agent'
import config from './config'
Expand All @@ -31,7 +33,7 @@ const isLinux = os.platform() === 'linux'

let urlMode: 'scheme' | 'dev' | 'prod' = 'scheme'
let skipBeforeUnloadCheck = false
let mainWindowIsReady = false
let macOpenFilePath = ''

const trayEnabled = !(yargs.argv['disable-tray'])
const backendPort = Number(yargs.argv.port) || config.get('server.port', 3044)
Expand All @@ -55,6 +57,16 @@ let fullscreen = false
let win: TBrowserWindow.BrowserWindow | null = null
let tray: Tray | null = null

const getOpenFilePathFromArgv = (argv: string[]) => {
const filePath = [...argv].reverse().find(x =>
x !== process.argv[0] &&
!x.startsWith('-') &&
!x.endsWith('app.js')
)

return filePath ? path.resolve(process.cwd(), filePath) : null
}

const getUrl = (mode?: typeof urlMode) => {
mode = mode ?? urlMode

Expand Down Expand Up @@ -234,13 +246,27 @@ const createWindow = () => {
win.setMenu(null)
win && win.loadURL(getUrl())
restoreWindowBounds()
win.on('ready-to-show', () => {
if (!mainWindowIsReady && config.get('hide-main-window-on-startup', false)) {
win.once('ready-to-show', () => {
// open file from argv
const filePath = macOpenFilePath || getOpenFilePathFromArgv(process.argv)
if (filePath) {
win?.show()
tryOpenFile(filePath)
return
}

// reset macOpenFilePath
macOpenFilePath = ''

// hide window on startup
if (config.get('hide-main-window-on-startup', false)) {
hideWindow()
} else {
win!.show()
win?.show()
}
mainWindowIsReady = true
})

win.on('ready-to-show', () => {
skipBeforeUnloadCheck = false
})

Expand Down Expand Up @@ -270,11 +296,13 @@ const createWindow = () => {
fullscreen = false
})

win!.webContents.on('will-navigate', (e) => {
initJSONRPCClient(win.webContents)

win.webContents.on('will-navigate', (e) => {
e.preventDefault()
})

win!.webContents.on('will-prevent-unload', (e) => {
win.webContents.on('will-prevent-unload', (e) => {
if (skipBeforeUnloadCheck) {
e.preventDefault()
}
Expand Down Expand Up @@ -378,7 +406,7 @@ const showSetting = (key?: string) => {
}

showWindow()
win.webContents.executeJavaScript(`window.ctx.setting.showSettingPanel(${key ? `'${key}'` : ''});`, true)
jsonRPCClient.call.ctx.setting.showSettingPanel(key)
}

const toggleFullscreen = () => {
Expand Down Expand Up @@ -458,6 +486,18 @@ function refreshMenus () {
}
}

async function tryOpenFile (path: string) {
console.log('tryOpenFile', path)
const stat = await fs.stat(path)

if (stat.isFile()) {
jsonRPCClient.call.ctx.doc.switchDocByPath(path)
showWindow()
} else {
win && dialog.showMessageBox(win, { message: 'Yank Note only support open file.' })
}
}

registerAction('show-main-window', showWindow)
registerAction('hide-main-window', hideWindow)
registerAction('toggle-fullscreen', toggleFullscreen)
Expand All @@ -480,13 +520,24 @@ const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.exit()
} else {
app.on('second-instance', () => {
app.on('second-instance', (e, argv) => {
// only check last param of argv.
const path = getOpenFilePathFromArgv([argv[argv.length - 1]])
if (path) {
tryOpenFile(path)
}

showWindow()
})

app.on('open-file', (e) => {
win && dialog.showMessageBox(win, { message: 'Yank Note dose not support opening files directly.' })
app.on('open-file', (e, path) => {
e.preventDefault()

if (!win || win.webContents.isLoading()) {
macOpenFilePath = path
} else {
tryOpenFile(path)
}
})

app.on('ready', () => {
Expand Down
36 changes: 36 additions & 0 deletions src/main/jsonrpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { app, ipcMain } from 'electron'
import { JSONRPCClient, JSONRPCClientChannel, JSONRPCError, JSONRPCRequest, JSONRPCResult } from 'jsonrpc-bridge'

type Ctx = {
setting: {
showSettingPanel: (key?: string) => void
},
doc: {
switchDocByPath: (path: string) => Promise<void>
},
}

class ElectronMainClientChannel implements JSONRPCClientChannel {
webContent: Electron.WebContents

constructor (webContent: Electron.WebContents) {
this.webContent = webContent
}

send (message: JSONRPCRequest<any[]>): void {
this.webContent.send('jsonrpc', message)
}

setMessageHandler (callback: (message: Partial<JSONRPCResult<any> & JSONRPCError>) => void): void {
ipcMain.on('jsonrpc', (_event, message) => {
callback(message)
})
}
}

export let jsonRPCClient: JSONRPCClient<{ ctx: Ctx }>

export function initJSONRPCClient (webContent: Electron.WebContents) {
const clientChannel: JSONRPCClientChannel = new ElectronMainClientChannel(webContent)
jsonRPCClient = new JSONRPCClient(clientChannel, { debug: !app.isPackaged })
}
7 changes: 5 additions & 2 deletions src/main/server/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as crypto from 'crypto'
import * as yargs from 'yargs'
import AdmZip from 'adm-zip'
import dayjs from 'dayjs'
import { DEFAULT_EXCLUDE_REGEX, DOC_HISTORY_MAX_CONTENT_LENGTH, ENCRYPTED_MARKDOWN_FILE_EXT, isEncryptedMarkdownFile, isMarkdownFile, MARKDOWN_FILE_EXT } from '../../share/misc'
import { DEFAULT_EXCLUDE_REGEX, DOC_HISTORY_MAX_CONTENT_LENGTH, ENCRYPTED_MARKDOWN_FILE_EXT, isEncryptedMarkdownFile, isMarkdownFile, MARKDOWN_FILE_EXT, ROOT_REPO_NAME_PREFIX } from '../../share/misc'
import { createStreamResponse } from '../helper'
import { HISTORY_DIR } from '../constant'
import config from '../config'
Expand Down Expand Up @@ -41,7 +41,10 @@ function getExcludeRegex () {
}

function withRepo<T> (repo = 'main', callback: (repoPath: string, ...targetPath: string[]) => Promise<T>, ...target: string[]): Promise<T> {
const repoPath = repository.getPath(repo)
const repoPath = repo.startsWith(ROOT_REPO_NAME_PREFIX)
? repo.substring(ROOT_REPO_NAME_PREFIX.length)
: repository.getPath(repo)

if (!repoPath) {
throw new Error(`repo ${repo} not exists.`)
}
Expand Down
36 changes: 32 additions & 4 deletions src/main/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,27 @@ const checkPermission = (ctx: any, next: any) => {
throw new Error('Forbidden')
}

const isAdmin = (ctx: any) => ctx.req.jwt && ctx.req.jwt.role === 'admin'

const checkIsAdmin = (ctx: any) => {
if (!isAdmin(ctx)) {
throw new Error('Forbidden')
}
}

const checkPrivateRepo = (ctx: any, repo: string) => {
if (repo.startsWith('__')) {
checkIsAdmin(ctx)
}
}

const fileContent = async (ctx: any, next: any) => {
if (ctx.path === '/api/file') {
if (ctx.method === 'GET') {
const { repo, path, asBase64 } = ctx.query

checkPrivateRepo(ctx, repo)

const content = await file.read(repo, path)

ctx.body = result('ok', 'success', {
Expand Down Expand Up @@ -180,8 +197,12 @@ const attachment = async (ctx: any, next: any) => {
await file.upload(repo, buffer, path)
ctx.body = result('ok', 'success', path)
} else if (ctx.method === 'GET') {
ctx.type = mime.getType(ctx.query.path)
ctx.body = await file.read(ctx.query.repo, ctx.query.path)
const { repo, path } = ctx.query

checkPrivateRepo(ctx, repo)

ctx.type = mime.getType(path)
ctx.body = await file.read(repo, path)
}
} else {
await next()
Expand Down Expand Up @@ -402,13 +423,20 @@ const setting = async (ctx: any, next: any) => {
if (ctx.path.startsWith('/api/settings')) {
if (ctx.method === 'GET') {
const getSettings = () => {
if (ctx.req.jwt && ctx.req.jwt.role === 'admin') {
if (isAdmin(ctx)) {
return config.getAll()
} else {
const data = { ...config.getAll() }
data.repositories = {}
data.mark = []
delete data['server.jwt-secret']

// remove sensitive data
Object.keys(data).forEach((key) => {
if (key.endsWith('-token') || key.endsWith('-secret')) {
delete data[key]
}
})

delete data.license
delete data.extensions
return data
Expand Down
Loading

1 comment on commit ca799b3

@vercel
Copy link

@vercel vercel bot commented on ca799b3 Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

yn-api-doc – ./

yn-api-doc-git-master-purocean.vercel.app
yn-api-doc.vercel.app
yn-api-doc-purocean.vercel.app

Please sign in to comment.