feat: 小银 Markdown 编辑器 v2.6.1 源码

纯本地 Windows Markdown 编辑器(Electron + Tauri 双栈):

- 实时预览、多标签 / 多窗口两种打开方式
- 查找高亮、大纲、侧栏面板
- 右键复制全文 / 打开目录、常用快捷键
- 不联网、不登录、不收集任何数据

仓库化时做的处理:
- 路径脱敏:README 与 tools/mklink.js 里写死的 C:\Users\<用户名> 改为 %USERPROFILE% /
  process.env.USERPROFILE,换机器即可用(原文件含个人目录名)
- 补 .gitignore(node_modules / dist / src-tauri/target / Tauri 自动生成的 gen/schemas)
- 补 MIT LICENSE(与 package.json 的 license 字段一致)
This commit is contained in:
Jidekin committed 2026-11-19 19:09:45 +08:00
commit 66bad58593
37 files changed
+11319

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('node:path');
const fs = require('node:fs');
const os = require('node:os');
const theme = process.env.SHOT_THEME || 'light';
const out = process.env.SHOT_OUT || path.join(__dirname, '..', 'shot.png');
app.whenReady().then(async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'shotdir-'));
const mk = (n, c) => fs.writeFileSync(path.join(tmp, n), c, 'utf8');
mk('产品需求说明.md', '# 产品需求说明\n\n## 目标\n\n做一个**纯本地**的 Markdown 编辑器。\n\n- 实时预览\n- 右键复制全文\n- 拖进来就打开\n\n> 不联网,不登录。\n');
mk('API 设计.md', '# API\n');
mk('更新日志.md', '# 更新日志\n');
mk('readme.txt', 'txt\n');
fs.mkdirSync(path.join(tmp, '草稿'));
fs.writeFileSync(path.join(tmp, '草稿', '想法.md'), '# 想法\n', 'utf8');
const list = () => fs.readdirSync(tmp, { withFileTypes: true })
.filter(d => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name)))
.map(d => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() }))
.sort((a, b) => (Number(b.isDir) - Number(a.isDir)) || a.name.localeCompare(b.name, 'zh-Hans-CN'));
ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' }));
ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: list() }));
ipcMain.handle('dir:open', async () => ({ ok: false }));
ipcMain.handle('clip:read', () => ''); ipcMain.handle('clip:write', () => true);
ipcMain.handle('file:reveal', () => ({ ok: true })); ipcMain.handle('ui:message', () => 0);
ipcMain.handle('shell:openExternal', () => true);
ipcMain.on('app:setDirty', () => {}); ipcMain.on('win:setTitle', () => {}); ipcMain.on('save:finished', () => {});
const win = new BrowserWindow({ width: 1380, height: 880, show: true, backgroundColor: '#fff',
webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false } });
await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html'));
await win.webContents.executeJavaScript(`localStorage.setItem('md-editor-theme', ${JSON.stringify(theme)}); document.documentElement.dataset.theme = ${JSON.stringify(theme)};`);
win.webContents.send('cmd', 'dir-opened', { ok: true, path: tmp, name: path.basename(tmp), entries: list() });
await new Promise(r => setTimeout(r, 500));
win.webContents.send('cmd', 'file-opened', { ok: true, path: path.join(tmp, '产品需求说明.md'), name: '产品需求说明.md', text: fs.readFileSync(path.join(tmp, '产品需求说明.md'), 'utf8'), eol: '\n' });
await new Promise(r => setTimeout(r, 1400));
const img = await win.webContents.capturePage();
fs.writeFileSync(out, img.toPNG());
console.log('saved', out);
fs.rmSync(tmp, { recursive: true, force: true });
app.exit(0);
});