From e99987793a9d3f01fcf744f31400dd9f1c4568ee Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Fri, 8 May 2026 01:41:54 +0800 Subject: [PATCH] fix: install from tagged release URL, version consistency check on startup --- paperforge/plugin/main.js | 36 ++++++++++++++++++++++++++---------- paperforge/setup_wizard.py | 5 +++-- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/paperforge/plugin/main.js b/paperforge/plugin/main.js index 7a474563..b29d7233 100644 --- a/paperforge/plugin/main.js +++ b/paperforge/plugin/main.js @@ -2164,9 +2164,10 @@ class PaperForgeSetupModal extends Modal { if (!hasPaperforge) { this._log(t('install_bootstrapping')); + const ver = this.plugin.manifest.version || '1.4.17rc2'; await runPython([ '-m', 'pip', 'install', '--upgrade', - 'git+https://github.com/LLLin000/PaperForge.git', + `git+https://github.com/LLLin000/PaperForge.git@${ver}`, ]); } @@ -2366,15 +2367,30 @@ module.exports = class PaperForgePlugin extends Plugin { _autoUpdate() { const vp = this.app.vault.adapter.basePath; const pythonExe = resolvePythonExecutable(vp); - const spawn = require('node:child_process').spawn; - const child = spawn(pythonExe, ['-m', 'pip', 'install', '--upgrade', 'git+https://github.com/LLLin000/PaperForge.git'], { cwd: vp, timeout: 120000 }); - let stdout = ''; - child.stdout.on('data', (data) => { stdout += data.toString('utf-8'); }); - child.on('close', (code) => { - if (code !== 0) return; - const result = stdout.trim().replace(/\n\s*\n/g, '\n'); - if (result.includes('already satisfied') || result.includes('already up-to-date')) return; - new Notice('[OK] PaperForge CLI updated', 5000); + const ver = this.manifest.version || '1.4.17rc2'; + const url = `git+https://github.com/LLLin000/PaperForge.git@${ver}`; + + // Check if installed package version matches plugin version + const { execFile } = require('node:child_process'); + execFile(pythonExe, ['-c', 'import paperforge; print(paperforge.__version__)'], { cwd: vp, timeout: 10000 }, (err, stdout) => { + if (err) { + // Not installed — install now + const spawn = require('node:child_process').spawn; + const child = spawn(pythonExe, ['-m', 'pip', 'install', '--upgrade', url], { cwd: vp, timeout: 120000 }); + child.on('close', (code) => { + if (code === 0) new Notice('[OK] PaperForge CLI installed', 5000); + }); + return; + } + const pyVer = stdout.trim(); + if (pyVer !== ver) { + // Mismatch — upgrade + const spawn = require('node:child_process').spawn; + const child = spawn(pythonExe, ['-m', 'pip', 'install', '--upgrade', url], { cwd: vp, timeout: 120000 }); + child.on('close', (code) => { + if (code === 0) new Notice(`[OK] PaperForge ${pyVer} -> ${ver}`, 5000); + }); + } }); } diff --git a/paperforge/setup_wizard.py b/paperforge/setup_wizard.py index 80f41ef4..8ee70ef8 100644 --- a/paperforge/setup_wizard.py +++ b/paperforge/setup_wizard.py @@ -1004,11 +1004,12 @@ def headless_setup( except ImportError: current_ver = 'not installed' # If repo_root is the source repository (has pyproject.toml), install from it. - # Otherwise (site-packages copy) install from GitHub. + # Otherwise (site-packages copy) install from GitHub tagged release. if (repo_root / "pyproject.toml").exists(): install_target = [str(repo_root)] else: - install_target = [f"git+https://github.com/LLLin000/PaperForge.git"] + from paperforge import __version__ as _pv + install_target = [f"git+https://github.com/LLLin000/PaperForge.git@{_pv}"] result = subprocess.run( [sys.executable, "-m", "pip", "install", "--upgrade"] + install_target, capture_output=True, text=True, timeout=120,