Compare commits

..

8 Commits

10 changed files with 241 additions and 60 deletions

25
main.js
View File

@@ -123,9 +123,30 @@ async function start() {
if (release) {
const hasUpdate = release.version !== localVersion || (release.sha256 && release.sha256 !== localSha);
if (isFirstRun || hasUpdate) {
debugLog("Update required or first run. Installing remote build...");
if (isFirstRun) {
debugLog("First run. Installing remote build...");
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 {
debugLog("Already on the latest version.");
}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "vyla-home",
"version": "1.0.0",
"version": "1.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "vyla-home",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "vyla-home",
"version": "1.0.0",
"version": "1.0.3",
"description": "Vyla Home Desktop App Launcher",
"main": "main.js",
"scripts": {
@@ -54,4 +54,4 @@
"installerHeaderIcon": "build/icon.ico"
}
}
}
}

View File

@@ -12,9 +12,32 @@ if (!TOKEN) {
process.exit(1);
}
function getPackageVersion() {
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
return pkg.version || '1.0.0';
function incrementVersion() {
const pkgPath = path.join(__dirname, 'package.json');
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) {
@@ -55,55 +78,64 @@ function uploadFileToGitLabPackage(filePath, packageName, version, fileName) {
}
function createGitLabRelease(tag, releaseLinks) {
return new Promise((resolve, reject) => {
let currentRef = 'main';
try {
currentRef = execSync('git rev-parse HEAD').toString().trim();
} catch (e) { }
const sendRequest = (method, path) => {
return new Promise((resolve, reject) => {
let currentRef = 'main';
try {
currentRef = execSync('git rev-parse HEAD').toString().trim();
} catch (e) { }
const postData = JSON.stringify({
name: `Vyla Home Release ${tag}`,
tag_name: tag,
ref: currentRef,
description: `Automated local release ${tag}`,
assets: {
links: releaseLinks
}
});
const req = https.request({
hostname: 'gitlab.com',
port: 443,
path: `/api/v4/projects/${PROJECT_ID}/releases`,
method: 'POST',
headers: {
'PRIVATE-TOKEN': TOKEN,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
}, (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
if (res.statusCode === 201 || res.statusCode === 200) {
resolve(JSON.parse(body));
} else {
reject(new Error(`Failed to create release (HTTP ${res.statusCode}): ${body}`));
const postData = JSON.stringify({
name: `Vyla Home Release ${tag}`,
tag_name: tag,
ref: currentRef,
description: `Automated local release ${tag}`,
assets: {
links: releaseLinks
}
});
});
req.on('error', reject);
req.write(postData);
req.end();
});
const req = https.request({
hostname: 'gitlab.com',
port: 443,
path: path,
method: method,
headers: {
'PRIVATE-TOKEN': TOKEN,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
}, (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
if (res.statusCode === 200 || res.statusCode === 201) {
resolve(JSON.parse(body));
} else if (res.statusCode === 409 && method === 'POST') {
console.log(`Release ${tag} already exists, updating assets...`);
sendRequest('PUT', `/api/v4/projects/${PROJECT_ID}/releases/${encodeURIComponent(tag)}`)
.then(resolve)
.catch(reject);
} else {
reject(new Error(`Failed to publish release (HTTP ${res.statusCode}): ${body}`));
}
});
});
req.on('error', reject);
req.write(postData);
req.end();
});
};
return sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`);
}
async function main() {
const isFullBuild = process.argv.includes('--installer');
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}) ===`);

View File

@@ -59,11 +59,13 @@ class ServiceManager {
this.logToFile(name, `--- Starting ${name} in ${serviceDir} ---`);
const child = spawn('node', [scriptPath], {
const nodeExecutable = process.env.NODE_EXE || 'node';
const child = spawn(nodeExecutable, [scriptPath], {
cwd: serviceDir,
env,
stdio: ['ignore', 'pipe', 'pipe'],
shell: process.platform === 'win32'
shell: false
});
this.processes[name] = {

2
src-tauri/Cargo.lock generated
View File

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

View File

@@ -1,6 +1,6 @@
[package]
name = "vyla-home"
version = "1.0.0"
version = "1.0.3"
description = "Vyla Home Desktop App Launcher"
edition = "2021"
@@ -9,8 +9,8 @@ tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-shell = "2"
tauri-plugin-process = "2"
tauri-plugin-opener = "2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-process = "2"
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

View File

@@ -23,7 +23,6 @@ struct BackendMessage {
data: serde_json::Value,
}
// Helper to remove the \\?\ prefix that Node.js chokes on
fn clean_path(path: &std::path::Path) -> String {
let s = path.to_string_lossy().to_string();
if s.starts_with("\\\\?\\") {
@@ -33,6 +32,72 @@ fn clean_path(path: &std::path::Path) -> String {
}
}
fn find_node_binary(app: &tauri::App) -> Option<String> {
if let Ok(resource_dir) = app.path().resource_dir() {
let candidates = [
resource_dir.join("node.exe"),
resource_dir.join("bin").join("node.exe"),
resource_dir.join("_up_").join("node.exe"),
];
for candidate in candidates {
if candidate.exists() {
return Some(clean_path(&candidate));
}
}
}
if let Ok(path_var) = std::env::var("PATH") {
for p in std::env::split_paths(&path_var) {
let candidate = p.join("node.exe");
if candidate.exists() {
return Some(clean_path(&candidate));
}
#[cfg(not(windows))]
{
let candidate_unix = p.join("node");
if candidate_unix.exists() {
return Some(clean_path(&candidate_unix));
}
}
}
}
#[cfg(windows)]
{
let default_paths = [
r"C:\Program Files\nodejs\node.exe",
r"C:\Program Files (x86)\nodejs\node.exe",
];
for path in default_paths {
let candidate = std::path::Path::new(path);
if candidate.exists() {
return Some(clean_path(candidate));
}
}
if let Ok(local_app_data) = std::env::var("LOCALAPPDATA") {
let candidate = std::path::PathBuf::from(local_app_data)
.join("Programs")
.join("nodejs")
.join("node.exe");
if candidate.exists() {
return Some(clean_path(&candidate));
}
}
if let Ok(app_data) = std::env::var("APPDATA") {
let candidate = std::path::PathBuf::from(app_data)
.join("npm")
.join("node.exe");
if candidate.exists() {
return Some(clean_path(&candidate));
}
}
}
None
}
fn resolve_script_and_root(app: &tauri::App) -> (String, String) {
if let Ok(resource_dir) = app.path().resource_dir() {
debug_log(&format!("Resource dir found: {:?}", resource_dir));
@@ -117,13 +182,28 @@ fn main() {
debug_log("Webview created");
let (main_js, root_dir) = resolve_script_and_root(app);
let node_bin = match find_node_binary(app) {
Some(bin) => bin,
None => {
debug_log("Node.js runtime not found anywhere");
let _ = window.emit(
"error",
serde_json::json!({
"message": "Node.js runtime not found on this system. Please install Node.js (https://nodejs.org) and restart Vyla Home."
}),
);
return Ok(());
}
};
debug_log(&format!("Using Node binary: {}", node_bin));
debug_log(&format!("Spawning node with script: {}", main_js));
let mut cmd = Command::new("node");
let mut cmd = Command::new(&node_bin);
cmd.arg(&main_js)
.current_dir(&root_dir)
.env("APPDATA_PATH", &app_data_str)
.env("NODE_EXE", &node_bin)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
@@ -172,6 +252,12 @@ fn main() {
}
Err(e) => {
debug_log(&format!("FAILED to spawn Node: {}", e));
let _ = window.emit(
"error",
serde_json::json!({
"message": format!("Failed to launch backend runtime: {}", e)
}),
);
}
}

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/schema.json",
"productName": "Vyla Home",
"version": "1.0.0",
"version": "1.0.3",
"identifier": "com.vyla.home",
"build": {
"frontendDist": "../ui"
@@ -22,6 +22,11 @@
"icons/icon.icns",
"icons/icon.ico"
],
"windows": {
"webviewInstallMode": {
"type": "downloadBootstrapper"
}
},
"resources": [
"../main.js",
"../service-manager.js",
@@ -33,4 +38,4 @@
"../node_modules/**/*"
]
}
}
}

View File

@@ -633,6 +633,21 @@
</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 class="container">
<svg class="icon icon-error" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -653,6 +668,7 @@
<script>
const viewLoader = document.getElementById('view-loader');
const viewError = document.getElementById('view-error');
const viewUpdate = document.getElementById('view-update');
const statusMsg = document.getElementById('status-msg');
const errorMsg = document.getElementById('error-msg');
@@ -666,6 +682,13 @@
}
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) => {
if (e.payload && 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() {
fetch('http://localhost:4890')
.then(res => {