Compare commits

..

3 Commits

7 changed files with 91 additions and 12 deletions

25
main.js
View File

@@ -123,9 +123,30 @@ async function start() {
if (release) { if (release) {
const hasUpdate = release.version !== localVersion || (release.sha256 && release.sha256 !== localSha); const hasUpdate = release.version !== localVersion || (release.sha256 && release.sha256 !== localSha);
if (isFirstRun || hasUpdate) { if (isFirstRun) {
debugLog("Update required or first run. Installing remote build..."); debugLog("First run. Installing remote build...");
await installBuild(release); await installBuild(release);
} else if (hasUpdate) {
debugLog("Update available. Prompting user...");
sendToTauri('update-available', { current: localVersion, latest: release.version });
const tempApp = express();
let userDecision = null;
tempApp.post('/update/yes', (req, res) => { userDecision = true; res.sendStatus(200); });
tempApp.post('/update/no', (req, res) => { userDecision = false; res.sendStatus(200); });
const tempServer = tempApp.listen(4891, '127.0.0.1');
while (userDecision === null) {
await new Promise(r => setTimeout(r, 500));
}
tempServer.close();
if (userDecision) {
debugLog("User accepted update.");
await installBuild(release);
} else {
debugLog("User skipped update.");
}
} else { } else {
debugLog("Already on the latest version."); debugLog("Already on the latest version.");
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "vyla-home", "name": "vyla-home",
"version": "1.0.1", "version": "1.0.2",
"description": "Vyla Home Desktop App Launcher", "description": "Vyla Home Desktop App Launcher",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@@ -12,9 +12,32 @@ if (!TOKEN) {
process.exit(1); process.exit(1);
} }
function getPackageVersion() { function incrementVersion() {
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')); const pkgPath = path.join(__dirname, 'package.json');
return pkg.version || '1.0.0'; const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
let [major, minor, patch] = (pkg.version || '1.0.0').split('.').map(Number);
patch = (patch || 0) + 1;
const newVersion = `${major}.${minor}.${patch}`;
pkg.version = newVersion;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
const tauriPath = path.join(__dirname, 'src-tauri', 'tauri.conf.json');
if (fs.existsSync(tauriPath)) {
const tauriConf = JSON.parse(fs.readFileSync(tauriPath, 'utf8'));
tauriConf.version = newVersion;
fs.writeFileSync(tauriPath, JSON.stringify(tauriConf, null, 4) + '\n', 'utf8');
}
const cargoPath = path.join(__dirname, 'src-tauri', 'Cargo.toml');
if (fs.existsSync(cargoPath)) {
let cargo = fs.readFileSync(cargoPath, 'utf8');
cargo = cargo.replace(/^version\s*=\s*".*"/m, `version = "${newVersion}"`);
fs.writeFileSync(cargoPath, cargo, 'utf8');
}
return newVersion;
} }
function uploadFileToGitLabPackage(filePath, packageName, version, fileName) { function uploadFileToGitLabPackage(filePath, packageName, version, fileName) {
@@ -112,7 +135,7 @@ async function main() {
const isFullBuild = process.argv.includes('--installer'); const isFullBuild = process.argv.includes('--installer');
const customTag = process.argv.find(arg => arg.startsWith('--tag='))?.split('=')[1]; const customTag = process.argv.find(arg => arg.startsWith('--tag='))?.split('=')[1];
const version = customTag || `v${getPackageVersion()}`; const version = customTag || `v${incrementVersion()}`;
console.log(`=== Building Vyla Home Release (${version}) ===`); console.log(`=== Building Vyla Home Release (${version}) ===`);

2
src-tauri/Cargo.lock generated
View File

@@ -4222,7 +4222,7 @@ dependencies = [
[[package]] [[package]]
name = "vyla-home" name = "vyla-home"
version = "1.0.0" version = "1.0.2"
dependencies = [ dependencies = [
"serde", "serde",
"serde_json", "serde_json",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "vyla-home" name = "vyla-home"
version = "1.0.1" version = "1.0.2"
description = "Vyla Home Desktop App Launcher" description = "Vyla Home Desktop App Launcher"
edition = "2021" edition = "2021"

View File

@@ -1,7 +1,7 @@
{ {
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/schema.json", "$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/schema.json",
"productName": "Vyla Home", "productName": "Vyla Home",
"version": "1.0.1", "version": "1.0.2",
"identifier": "com.vyla.home", "identifier": "com.vyla.home",
"build": { "build": {
"frontendDist": "../ui" "frontendDist": "../ui"

View File

@@ -633,6 +633,21 @@
</div> </div>
</div> </div>
<div id="view-update" class="view-state">
<div class="container">
<svg class="icon icon-loader" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
style="color:#0a84ff; animation:none; transform:none;">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3" />
</svg>
<h1>Update Available</h1>
<p id="update-msg">A new version is available.</p>
<div class="buttons">
<button class="secondary" onclick="skipUpdate()">Skip</button>
<button class="primary" onclick="installUpdate()">Install Update</button>
</div>
</div>
</div>
<div id="view-error" class="view-state"> <div id="view-error" class="view-state">
<div class="container"> <div class="container">
<svg class="icon icon-error" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <svg class="icon icon-error" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -653,6 +668,7 @@
<script> <script>
const viewLoader = document.getElementById('view-loader'); const viewLoader = document.getElementById('view-loader');
const viewError = document.getElementById('view-error'); const viewError = document.getElementById('view-error');
const viewUpdate = document.getElementById('view-update');
const statusMsg = document.getElementById('status-msg'); const statusMsg = document.getElementById('status-msg');
const errorMsg = document.getElementById('error-msg'); const errorMsg = document.getElementById('error-msg');
@@ -666,6 +682,13 @@
} }
if (window.__TAURI__ && window.__TAURI__.event) { if (window.__TAURI__ && window.__TAURI__.event) {
window.__TAURI__.event.listen('update-available', (e) => {
if (e.payload) {
document.getElementById('update-msg').textContent = `Version ${e.payload.latest} is available (Current: ${e.payload.current}).`;
showView(viewUpdate);
}
});
window.__TAURI__.event.listen('status', (e) => { window.__TAURI__.event.listen('status', (e) => {
if (e.payload && e.payload.message) { if (e.payload && e.payload.message) {
statusMsg.textContent = e.payload.message; statusMsg.textContent = e.payload.message;
@@ -694,6 +717,18 @@
}); });
} }
function installUpdate() {
fetch('http://127.0.0.1:4891/update/yes', { method: 'POST' }).catch(() => { });
statusMsg.textContent = 'Starting update...';
showView(viewLoader);
}
function skipUpdate() {
fetch('http://127.0.0.1:4891/update/no', { method: 'POST' }).catch(() => { });
statusMsg.textContent = 'Continuing to app...';
showView(viewLoader);
}
function pollBackend() { function pollBackend() {
fetch('http://localhost:4890') fetch('http://localhost:4890')
.then(res => { .then(res => {