diff --git a/main.js b/main.js index 0a59852..425fa15 100644 --- a/main.js +++ b/main.js @@ -34,6 +34,7 @@ debugLog("--- Node.js Process Started ---"); let serviceManager; let expressApp; let expressServer; +let updateDecisionHandler = null; debugLog(`AppData Dir: ${APPDATA_DIR}`); @@ -84,12 +85,25 @@ cmdApp.use((req, res, next) => { if (req.method === 'OPTIONS') return res.sendStatus(200); next(); }); +cmdApp.all('/update/:choice', (req, res) => { + const c = String(req.params.choice).toLowerCase(); + if (updateDecisionHandler) { + if (c === 'yes' || c === 'true' || c === 'install') updateDecisionHandler(true); + if (c === 'no' || c === 'false' || c === 'skip') updateDecisionHandler(false); + } + res.sendStatus(200); +}); cmdApp.get('/__tauri_cmd/:cmd', (req, res) => { + const cmd = req.params.cmd; + if (updateDecisionHandler) { + if (cmd === 'update_yes' || cmd === 'update_install') updateDecisionHandler(true); + if (cmd === 'update_no' || cmd === 'update_skip') updateDecisionHandler(false); + } debugLog(`[CMD-SERVER:4892] Command received: ${req.params.cmd} (window: ${req.query.window || 'main'})`); sendToTauri('tauri-cmd', { cmd: req.params.cmd, url: req.query.url, window: req.query.window }); res.sendStatus(200); }); -cmdApp.listen(4892, '127.0.0.1', () => debugLog("[CMD-SERVER] Dedicated command server listening on 127.0.0.1:4892")); +cmdApp.listen(4892, () => debugLog("[CMD-SERVER] Dedicated command server listening on port 4892")); process.stdin.resume(); process.stdin.on('end', () => { @@ -324,22 +338,34 @@ async function start() { const tempApp = express(); let userDecision = null; + updateDecisionHandler = (val) => { userDecision = val; }; + tempApp.use((req, res, next) => { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS'); res.header('Access-Control-Allow-Headers', '*'); - res.header('Connection', 'close'); if (req.method === 'OPTIONS') return res.sendStatus(200); next(); }); tempApp.get('/update/info', (req, res) => { res.json({ available: true, current: localVersion, latest: release.version }); }); - tempApp.post('/update/yes', (req, res) => { userDecision = true; res.sendStatus(200); }); - tempApp.post('/update/no', (req, res) => { userDecision = false; res.sendStatus(200); }); + const handleYes = (req, res) => { userDecision = true; res.sendStatus(200); }; + const handleNo = (req, res) => { userDecision = false; res.sendStatus(200); }; + + tempApp.all('/update/yes', handleYes); + tempApp.all('/update/install', handleYes); + tempApp.all('/update/no', handleNo); + tempApp.all('/update/skip', handleNo); + tempApp.all('/update/:choice', (req, res) => { + const c = String(req.params.choice || '').toLowerCase(); + if (c === 'yes' || c === 'install' || c === 'true') userDecision = true; + if (c === 'no' || c === 'skip' || c === 'false') userDecision = false; + res.sendStatus(200); + }); const tempServer = await new Promise((resolve) => { - const s = tempApp.listen(4891, '127.0.0.1', () => resolve(s)); + const s = tempApp.listen(4891, () => resolve(s)); s.on('error', (err) => { debugLog(`Update server bind error: ${err.message}`); resolve(null); @@ -358,6 +384,7 @@ async function start() { await new Promise(r => setTimeout(r, 25)); } + updateDecisionHandler = null; if (tempServer) { tempServer.close(); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7988659..f46a891 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -195,7 +195,34 @@ fn resolve_script_and_root(app: &tauri::App) -> (String, String) { (clean_path(&candidate), clean_path(&dir)) } -const LINK_HANDLER_SCRIPT: &str = r##" +const LINK_HANDLER_SCRIPT: &str = + r##" + + window.vylaHome = { + sendUpdateChoice: function(choice) { + var action = choice ? 'yes' : 'no'; + [4891, 4892].forEach(function(port) { + ['127.0.0.1', 'localhost'].forEach(function(host) { + fetch('http://' + host + ':' + port + '/update/' + action, { method: 'POST' }).catch(function() {}); + fetch('http://' + host + ':' + port + '/update/' + action, { method: 'GET' }).catch(function() {}); + fetch('http://' + host + ':' + port + '/__tauri_cmd/update_' + action, { method: 'GET' }).catch(function() {}); + }); + }); + } + }; + + document.addEventListener('click', function(e) { + var el = e.target.closest('button, a, .btn'); + if (!el) return; + var text = (el.innerText || el.textContent || '').toLowerCase(); + var id = (el.id || '').toLowerCase(); + if (id.includes('install') || id.includes('update-yes') || text.includes('install update')) { + window.vylaHome.sendUpdateChoice(true); + } else if (id.includes('skip') || id.includes('update-no') || text.includes('skip')) { + window.vylaHome.sendUpdateChoice(false); + } + }, true); + function doInvoke(cmd, args) { if (window.__TAURI__ && window.__TAURI__.core) { return window.__TAURI__.core.invoke(cmd, args || {});