From a774220b56312c9f38c5817b84dccb1577a016c3 Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 27 Apr 2020 17:09:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Layout.vue | 2 +- frontend/src/store/app.js | 13 +- help/FEATURES.md | 3 +- src/app.ts | 228 +++++++++++++++-------------- src/server/constant.ts | 3 +- src/server/file.ts | 9 ++ src/server/repository.ts | 2 +- 7 files changed, 132 insertions(+), 128 deletions(-) diff --git a/frontend/src/components/Layout.vue b/frontend/src/components/Layout.vue index 3562e925..f6ea74bf 100644 --- a/frontend/src/components/Layout.vue +++ b/frontend/src/components/Layout.vue @@ -24,7 +24,7 @@ - diff --git a/frontend/src/store/app.js b/frontend/src/store/app.js index 71882514..9e58e7c9 100644 --- a/frontend/src/store/app.js +++ b/frontend/src/store/app.js @@ -124,18 +124,7 @@ export default { commit('setMarkedFiles', files) }, async fetchRepositories ({ commit }) { - const initReposParam = window.$args().get('init-repos') - - let initRepos = null - if (initReposParam) { - try { - initRepos = JSON.parse(initReposParam) - } catch (error) { - console.error(error) - } - } - - const repos = initRepos || (await file.fetchRepositories()) + const repos = await file.fetchRepositories() commit('setRepositories', repos) }, async fetchTree ({ commit }, repo) { diff --git a/help/FEATURES.md b/help/FEATURES.md index b820caaa..a54c4bf3 100644 --- a/help/FEATURES.md +++ b/help/FEATURES.md @@ -301,9 +301,10 @@ xml 代码块 第一行注释需要有 `--drawio--` 文字 名称 | 作用 | 默认值 | 说明 | 示例 ----------------- | ------------ | ----- | ----------------------- | ---- --port | 服务器监听端口 | 3044 | 端口 | --port=8080 +--disable-tray | 禁用常驻托盘 | false | true/false | --disable-tray --readonly | 编辑器只读 | false | true/false | --readonly --show-status-bar | 显示状态栏 | true | true/false | --show-status-bar=false ---init-repos | 初始仓库列表 | 无 | json 字符串,注意命令行转义 | --init-repos='{\"test\":\"D:/test\",\"b\":\"E:/test\"}' +--data-dir | 数据目录 | 无 | 目录路径字符串 | --data-dir='./.data' --init-repo | 初始仓库名 | 无 | 字符串 | --init-repo='test' --init-file | 加载文件路径 | 无 | 文件路径,相对于仓库路径 | --init-file='/1.md' diff --git a/src/app.ts b/src/app.ts index ea2889e7..cbfa30d6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,6 +10,7 @@ const opn = require('opn') let isDev = false +const showTray = !(yargs.argv['disable-tray']) const backendPort = Number(yargs.argv.port) || 3044 const devFrontendPort = 8066 @@ -17,7 +18,6 @@ const getUrl = () => { const args = Object.entries(yargs.argv).filter(x => [ 'readonly', 'show-status-bar', - 'init-repos', 'init-repo', 'init-file', ].includes(x[0])) @@ -66,8 +66,10 @@ const createWindow = () => { }, 0) win.on('close', e => { - hide() - e.preventDefault() + if (showTray) { + hide() + e.preventDefault() + } }) win.on('closed', () => { @@ -176,116 +178,118 @@ if (!gotTheLock) { 'open-in-browser': () => opn(getUrl()) }) - const contextMenu = Menu.buildFromTemplate([ - { - type: 'normal', - label: '打开主界面', - accelerator: getAccelerator('show-main-window'), - click: () => { - showWindow() - } - }, - { - type: 'normal', - label: '浏览器中打开', - accelerator: getAccelerator('open-in-browser'), - click: () => { - opn(getUrl()) - } - }, - { - type: 'normal', - label: '打开主目录', - click: () => { - opn(USER_DIR) - } - }, - { type: 'separator' }, - { - type: 'submenu', - label: '开发', - submenu: [ - { - type: 'radio', - checked: !isDev, - label: `正式端口(${backendPort})`, - click: () => { - isDev = false - reload() - } - }, - { - type: 'radio', - checked: isDev, - label: `开发端口(${devFrontendPort})`, - click: () => { - isDev = true - reload() - } - }, - { type: 'separator' }, - { - type: 'normal', - label: '重载页面', - click: () => { - reload() - } - }, - { - type: 'normal', - label: '主窗口开发工具', - click: () => { - win && win.webContents.openDevTools() - } - }, - { type: 'separator' }, - { - type: 'normal', - label: '强制重新启动', - click: () => { - app.relaunch() - app.exit(1) - } - }, - { - type: 'normal', - label: '强制退出', - click: () => { - app.exit(1) - } - }, - ] - }, - { - type: 'normal', - label: 'GitHub', - click: () => { - opn('https://github.com/purocean/yn') - } - }, - { - type: 'normal', - label: `版本 ${app.getVersion()}`, - click: () => { - updater.checkForUpdates() - } - }, - { type: 'separator' }, - { - type: 'normal', - label: '退出', - click: () => { - setTimeout(() => { - quit() - }, 200) - } - }, - ]) + if (showTray) { + const contextMenu = Menu.buildFromTemplate([ + { + type: 'normal', + label: '打开主界面', + accelerator: getAccelerator('show-main-window'), + click: () => { + showWindow() + } + }, + { + type: 'normal', + label: '浏览器中打开', + accelerator: getAccelerator('open-in-browser'), + click: () => { + opn(getUrl()) + } + }, + { + type: 'normal', + label: '打开主目录', + click: () => { + opn(USER_DIR) + } + }, + { type: 'separator' }, + { + type: 'submenu', + label: '开发', + submenu: [ + { + type: 'radio', + checked: !isDev, + label: `正式端口(${backendPort})`, + click: () => { + isDev = false + reload() + } + }, + { + type: 'radio', + checked: isDev, + label: `开发端口(${devFrontendPort})`, + click: () => { + isDev = true + reload() + } + }, + { type: 'separator' }, + { + type: 'normal', + label: '重载页面', + click: () => { + reload() + } + }, + { + type: 'normal', + label: '主窗口开发工具', + click: () => { + win && win.webContents.openDevTools() + } + }, + { type: 'separator' }, + { + type: 'normal', + label: '强制重新启动', + click: () => { + app.relaunch() + app.exit(1) + } + }, + { + type: 'normal', + label: '强制退出', + click: () => { + app.exit(1) + } + }, + ] + }, + { + type: 'normal', + label: 'GitHub', + click: () => { + opn('https://github.com/purocean/yn') + } + }, + { + type: 'normal', + label: `版本 ${app.getVersion()}`, + click: () => { + updater.checkForUpdates() + } + }, + { type: 'separator' }, + { + type: 'normal', + label: '退出', + click: () => { + setTimeout(() => { + quit() + }, 200) + } + }, + ]) - tray = new Tray(path.join(__dirname, './assets/icon.png')) - tray.setToolTip('Yank Note 一款面向程序员的 Markdown 编辑器') - tray.on('click', showWindow) - tray.setContextMenu(contextMenu) + tray = new Tray(path.join(__dirname, './assets/icon.png')) + tray.setToolTip('Yank Note 一款面向程序员的 Markdown 编辑器') + tray.on('click', showWindow) + tray.setContextMenu(contextMenu) + } updater.init(() => { // 立即升级,退出程序 diff --git a/src/server/constant.ts b/src/server/constant.ts index c6a8edaf..1b0c4020 100644 --- a/src/server/constant.ts +++ b/src/server/constant.ts @@ -1,11 +1,12 @@ import * as path from 'path' import * as os from 'os' +import * as yargs from 'yargs' import { isWsl, toWslPath, getWinHomePath } from './wsl' const homedir = isWsl ? toWslPath(getWinHomePath()) : os.homedir() export const HOME_DIR = homedir -export const USER_DIR = path.join(homedir, 'yank-note') +export const USER_DIR = path.resolve((yargs.argv['data-dir'] as any) || path.join(homedir, 'yank-note')) export const TRASH_DIR = path.join(USER_DIR, 'trash') export const MAIN_REPO_DIR = path.join(USER_DIR, 'main') export const CONFIG_FILE = path.join(USER_DIR, 'config.json') diff --git a/src/server/file.ts b/src/server/file.ts index 5ac8ee77..8ca45f4b 100644 --- a/src/server/file.ts +++ b/src/server/file.ts @@ -3,11 +3,13 @@ import * as xfs from 'fs-extra' import * as path from 'path' import * as crypto from 'crypto' import * as NaturalOrderby from 'natural-orderby' +import * as yargs from 'yargs' import * as wsl from './wsl' import mark, { MarkedFile } from './mark' import repository from './repository' const opn = require('opn') +const readonly = !!(yargs.argv['readonly']) const isWsl = wsl.isWsl const ignorePath = /node_modules/ @@ -117,6 +119,8 @@ const read = (repo: string, p: string) => { } const write = (repo: string, p: string, content: any) => { + if (readonly) throw new Error('只读模式') + p = resolvePath(p, repo) mkdirPSync(path.dirname(p)) @@ -127,6 +131,8 @@ const write = (repo: string, p: string, content: any) => { } const rm = (repo: string, p: string) => { + if (readonly) throw new Error('只读模式') + if (resolvePath(p) !== resolvePath('', repo)) { const newPath = path.join(repository.getTrashPath(repo), p.replace(/\.\./g, '')) + '.' + (new Date).getTime() @@ -141,6 +147,8 @@ const rm = (repo: string, p: string) => { } const mv = (repo: string, oldPath: string, newPath: string) => { + if (readonly) throw new Error('只读模式') + oldPath = resolvePath(oldPath, repo) newPath = resolvePath(newPath, repo) @@ -169,6 +177,7 @@ const checkHash = (repo: string, p: string, oldHash: string) => { } const upload = (repo: string, file: any, path: string) => { + if (readonly) throw new Error('只读模式') write(repo, path, fs.readFileSync(file.path)) } diff --git a/src/server/repository.ts b/src/server/repository.ts index db6f0b64..1df1f1c0 100644 --- a/src/server/repository.ts +++ b/src/server/repository.ts @@ -24,7 +24,7 @@ const getPath = (name: string) => { return /^[a-zA-Z]:/.test(p) ? toWslPath(p) : path.join(MAIN_REPO_DIR, p) } - return path.isAbsolute(p) ? p : path.join(MAIN_REPO_DIR, p) + return path.isAbsolute(p) ? p : path.resolve(p) } const getTrashPath = (name: string) => { From 24ed21bbddf09211cab9ff6166ef5a6dc206ac21 Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 27 Apr 2020 17:13:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++-- package.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c782613f..9b0588ed 100644 --- a/README.md +++ b/README.md @@ -142,12 +142,15 @@ yarn run start ## 更新日志 [最新发布](https://github.com/purocean/yn/releases) -### [v2.3.1](https://github.com/purocean/yn/releases/tag/v2.3.1) 2020-04-27 -1. 增加配置监听端口命令行参数 `--port=8080` +### [v2.3.2](https://github.com/purocean/yn/releases/tag/v2.3.2) 2020-04-27 +1. 调整启动命令行参数
展开查看更多版本记录 +### [v2.3.1](https://github.com/purocean/yn/releases/tag/v2.3.1) 2020-04-27 +1. 增加配置监听端口命令行参数 `--port=8080` + ### [v2.3.0](https://github.com/purocean/yn/releases/tag/v2.3.0) 2020-04-27 1. 增加启动命令行参数 diff --git a/package.json b/package.json index 45ffee96..7bf6e1bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yank.note.yang", - "version": "2.3.1", + "version": "2.3.2", "description": "Yank Note 一款面向程序员的 Markdown 笔记应用", "main": "dist/app.js", "license": "Apache-2.0",