4 Commits
v1.2.3 ... test

Author SHA1 Message Date
Igor Pecovnik
009a36fac3 Generate simple website with download autodetection
Todo: styling
2026-01-03 23:35:31 +01:00
Ricardo Pardini
9cf8ca299b gha: build: linux: rework caching for consistency
- `actions/setup-node` doesn't allow for setting cache keys
  - even in recent versions... (bumped to v6)
  - so move npm caching to `actions/cache`:
    - disable `setup-node` caching via `package-manager-cache: false`
    - add new step for `actions/cache` "npm dependencies"
      - cache key includes the runner image, the container distro (if any), and hash of `package-lock.json`
- for `Swatinem/rust-cache`
  - use a cache key that includes the runner image, the container distro (if any), and TAURI_CLI_VERSION
  - add a TODO ref Cargo.lock missing/.gitignored, as it would be hashed too automatically had it existed
- for `actions/cache` based "cargo bin tauri-cli" caching
  - use a cache key that includes the runner image, the container distro (if any), and TAURI_CLI_VERSION
  - also TODO ref Cargo.lock, which was spelled out, but doesn't exist
  - also TODO as it seems to me this is already covered by the `Swatinem/rust-cache` cache

Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
2026-01-03 13:39:37 +01:00
Ricardo Pardini
0431b243bb gha: build: set a specific TAURI_CLI_VERSION (2.9.6)
- so we can hash it into the cache keys (done in later commit) for consistency

Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
2026-01-03 13:39:37 +01:00
Ricardo Pardini
4a3aa68051 gha: build: linux: rework into matrix; use bookworm for .deb builds
- this should reduce the glibc dep version requirement of .deb's, allowing them to run on old but still supported systems
  - See https://v2.tauri.app/distribute/debian/#limitations
    - "you must build your Tauri application using the oldest base system you intend to support"
    - Debian oldstable (Bookworm) will be supported until late 2028, so fair to support it
    - also, there's no downsides; imager itself runs great either way, and .deb install pulls updated deps on newer distros
- fold linux-x64 and linux-amd64 into a single matrix job (1st level)
- 2nd matrix level is per-type:
  - `deb` is now built using an oldtable container
  - `appimage` is built without container, directly on runner, as before
     - seems like appimage/`linuxdeploy` doesn't wanna be run in a container
     - also, the AppImage does seem to contain libs, so we don't wanna ship old ones

Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
2026-01-03 13:39:37 +01:00
3 changed files with 526 additions and 135 deletions

View File

@@ -6,12 +6,8 @@ on:
- 'v*'
workflow_dispatch:
inputs:
build_linux_x64:
description: 'Build Linux x64'
type: boolean
default: true
build_linux_arm64:
description: 'Build Linux ARM64'
build_linux:
description: 'Build Linux (x64 + ARM64)'
type: boolean
default: true
build_macos:
@@ -34,7 +30,7 @@ concurrency:
env:
CARGO_TERM_COLOR: always
NODE_VERSION: '20'
TAURI_CLI_VERSION: '^2'
TAURI_CLI_VERSION: '2.9.6'
# Tauri updater signing key (set in GitHub Secrets)
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
@@ -93,11 +89,35 @@ jobs:
omitNameDuringUpdate: true
replacesArtifacts: false
build-linux-x64:
name: build-linux (x86_64-unknown-linux-gnu)
needs: [create-release]
if: ${{ github.event_name == 'push' || inputs.build_linux_x64 }}
runs-on: ubuntu-24.04
build-linux:
name: build-linux ${{ matrix.type.name }} (${{ matrix.arch.name }}/${{ matrix.type.distro_id }})
needs: [ create-release ]
if: ${{ github.event_name == 'push' || inputs.build_linux }} # can't use matrix here; if is evaluated before matrix expansion
strategy:
fail-fast: false # let other jobs try to complete if one fails
matrix:
arch:
- { name: 'amd64', runner: 'ubuntu-24.04' }
- { name: 'arm64', runner: "ubuntu-24.04-arm" }
type:
# deb: build in the oldest still-supported matching container: oldstable (bookworm)
- name: 'deb'
distro_id: "bookworm"
container: { image: 'debian:bookworm' }
bundles: 'deb'
deps: "apt"
artifacts: "src-tauri/target/release/bundle/deb/*.deb"
# appimage: doesn't use a container (instead, runs directly on the runner); requires sudo to install deps
- name: 'appimage'
distro_id: "gharunner"
bundles: 'appimage'
deps: "apt"
deps_gain_root: "sudo"
artifacts: |
src-tauri/target/release/bundle/appimage/*.AppImage
src-tauri/target/release/bundle/appimage/*.AppImage.sig
runs-on: ${{ matrix.arch.runner }}
container: ${{ matrix.type.container }}
permissions:
contents: write
steps:
@@ -125,10 +145,13 @@ jobs:
-e "s/\"version\": \"[0-9.]*\"/\"version\": \"$VERSION\"/" \
src-tauri/tauri.conf.json
- name: Install dependencies
- name: Install dependencies (apt)
if: ${{ matrix.type.deps == 'apt' }}
run: |
sudo apt-get update
sudo apt-get install -y \
${{ matrix.type.deps_gain_root || '' }} apt-get update
${{ matrix.type.deps_gain_root || '' }} apt-get install -y \
build-essential \
curl \
libwebkit2gtk-4.1-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
@@ -139,10 +162,17 @@ jobs:
xdg-utils
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
package-manager-cache: false # setup-node can't add key to cache, so we do it ourselves in below step
# Cache npm, just like setup-node would do it with "cache: npm", but with our own key that includes arch and distro
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ matrix.arch.runner }}-${{ matrix.arch.name }}-${{ matrix.type.distro_id }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
@@ -151,12 +181,16 @@ jobs:
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
# ensure cache separation per host distro; this also ends up caching tauri-cli, so add that to key too.
key: "rust-cache-${{ matrix.arch.runner }}-${{ matrix.arch.name }}-${{ matrix.type.distro_id }}-${{env.TAURI_CLI_VERSION}}"
# @TODO: Cargo.lock is in gitignore, so it's not included here - it would via rust-cache Action magic, no need to specify it.
- name: Cache cargo bin (tauri-cli)
- name: Cache cargo bin (tauri-cli) # @TODO: Swatinem/rust-cache already caches this. maybe just drop this.
uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: cargo-bin-${{ runner.os }}-${{ runner.arch }}-stable-${{ hashFiles('**/Cargo.lock') }}
key: "cargo-bin-${{ matrix.arch.runner }}-${{ matrix.arch.name }}-${{ matrix.type.distro_id }}-stable-${{env.TAURI_CLI_VERSION}}-${{ hashFiles('**/Cargo.lock') }}"
# @TODO: Cargo.lock is in gitignore, so it's not included here, albeit being specified.
- name: Install npm dependencies
run: npm ci
@@ -172,7 +206,7 @@ jobs:
fi
- name: Build Tauri app
run: cargo tauri build --bundles deb,appimage
run: cargo tauri build --bundles "${{ matrix.type.bundles }}"
- name: Upload artifacts to GitHub Release
uses: ncipollo/release-action@v1
@@ -186,106 +220,7 @@ jobs:
omitNameDuringUpdate: true
replacesArtifacts: false
artifacts: |
src-tauri/target/release/bundle/deb/*.deb
src-tauri/target/release/bundle/appimage/*.AppImage
src-tauri/target/release/bundle/appimage/*.AppImage.sig
build-linux-arm64:
name: build-linux (aarch64-unknown-linux-gnu)
needs: [create-release]
if: ${{ github.event_name == 'push' || inputs.build_linux_arm64 }}
runs-on: ubuntu-24.04-arm
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set version from release tag
shell: bash
run: |
set -euo pipefail
TAG='${{ needs.create-release.outputs.release_tag }}'
VERSION="${TAG#v}"
echo "Setting version to $VERSION"
sed -i \
-e "s/\"version\": \"[0-9.]*\"/\"version\": \"$VERSION\"/" \
package.json
sed -i \
-e "s/^version = \".*\"/version = \"$VERSION\"/" \
src-tauri/Cargo.toml
sed -i \
-e "s/\"version\": \"[0-9.]*\"/\"version\": \"$VERSION\"/" \
src-tauri/tauri.conf.json
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
patchelf \
libssl-dev \
libgtk-3-dev \
squashfs-tools \
xdg-utils
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
- name: Cache cargo bin (tauri-cli)
uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: cargo-bin-${{ runner.os }}-${{ runner.arch }}-stable-${{ hashFiles('**/Cargo.lock') }}
- name: Install npm dependencies
run: npm ci
- name: Build frontend
run: npm run build
- name: Install Tauri CLI (if missing)
shell: bash
run: |
if ! command -v cargo-tauri >/dev/null 2>&1; then
cargo install tauri-cli --version "${TAURI_CLI_VERSION}" --locked
fi
- name: Build Tauri app
run: cargo tauri build --bundles deb,appimage
- name: Upload artifacts to GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.create-release.outputs.release_tag }}
name: "Armbian Imager ${{ needs.create-release.outputs.release_tag }}"
draft: true
prerelease: false
allowUpdates: true
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
replacesArtifacts: false
artifacts: |
src-tauri/target/release/bundle/deb/*.deb
src-tauri/target/release/bundle/appimage/*.AppImage
src-tauri/target/release/bundle/appimage/*.AppImage.sig
${{ matrix.type.artifacts }}
build-macos:
name: build-macos (${{ matrix.target }})
@@ -653,8 +588,7 @@ jobs:
name: Generate latest.json for updater
needs:
- create-release
- build-linux-x64
- build-linux-arm64
- build-linux
- build-macos
- build-windows-x64
- build-windows-arm64
@@ -770,8 +704,7 @@ jobs:
name: Publish release (draft -> false) + cleanup
needs:
- create-release
- build-linux-x64
- build-linux-arm64
- build-linux
- build-macos
- build-windows-x64
- build-windows-arm64

44
.github/workflows/pages-test.yml vendored Normal file
View File

@@ -0,0 +1,44 @@
name: Deploy test branch to GitHub Pages
on:
push:
branches: [ test ]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: test
- name: Fetch Latest Release
id: fetch_release
run: |
# Fetch the release JSON from the Armbian repo
curl -s https://api.github.com/repos/armbian/imager/releases/latest > latest.json
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

View File

@@ -1,13 +1,427 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/armbian-icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Armbian Imager</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Armbian Imager - Download</title>
<style>
/* --- CSS Reset & Base Variables --- */
:root {
--primary: #f98d05; /* Armbian Orange */
--primary-hover: #d67d04;
--dark-bg: #1a1a1a;
--card-bg: #ffffff;
--text-main: #333333;
--text-light: #666666;
--border-radius: 8px;
--font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: var(--font-family);
background-color: var(--dark-bg);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* --- Header --- */
header {
padding: 20px 40px;
display: flex;
align-items: center;
justify-content: space-between;
}
.logo { font-weight: 700; font-size: 24px; color: white; text-decoration: none; display: flex; align-items: center; gap: 10px; }
.logo span { color: var(--primary); }
.nav-links a { color: #ccc; text-decoration: none; margin-left: 20px; font-size: 14px; transition: 0.2s; }
.nav-links a:hover { color: white; }
/* --- Hero Section --- */
.hero {
background: linear-gradient(135deg, #2b2b2b 0%, #1a1a1a 100%);
padding: 60px 20px;
text-align: center;
border-bottom: 1px solid #333;
}
.hero h1 { font-size: 3rem; color: white; margin-bottom: 15px; font-weight: 700; }
.hero p { font-size: 1.2rem; color: #aaa; max-width: 600px; margin: 0 auto; }
/* --- Main Download Card --- */
.download-section {
flex: 1;
display: flex;
justify-content: center;
padding: 40px 20px;
}
.card {
background: var(--card-bg);
width: 100%;
max-width: 800px;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
overflow: hidden;
}
/* 1. Auto Download Area */
.auto-download {
padding: 40px;
background: #f9f9f9;
text-align: center;
border-bottom: 1px solid #eee;
}
.auto-label { text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--text-light); margin-bottom: 15px; display: block; }
.main-btn {
display: inline-block;
background-color: var(--primary);
color: white;
text-decoration: none;
padding: 18px 40px;
font-size: 20px;
font-weight: 700;
border-radius: 50px; /* Pill shape */
box-shadow: 0 4px 15px rgba(249, 141, 5, 0.4);
transition: transform 0.2s, background-color 0.2s;
cursor: pointer;
pointer-events: none; /* Disabled until loaded */
opacity: 0.8;
min-width: 300px;
}
.main-btn:hover { background-color: var(--primary-hover); transform: translateY(-2px); }
.main-btn.ready { pointer-events: auto; opacity: 1; }
.main-btn .sub { display: block; font-size: 14px; font-weight: 400; opacity: 0.9; margin-top: 4px; }
.detected-info { margin-top: 15px; font-size: 14px; color: var(--text-light); }
/* 2. Manual Tabs Area */
.manual-download { padding: 30px; min-height: 200px; }
.tabs-header { display: flex; justify-content: center; border-bottom: 2px solid #eee; margin-bottom: 20px; }
.tab-btn {
background: none; border: none; padding: 10px 20px;
font-size: 16px; font-weight: 600; color: var(--text-light);
cursor: pointer; border-bottom: 3px solid transparent; transition: 0.2s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { border-bottom-color: var(--primary); color: var(--text-main); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s; }
.file-list { list-style: none; }
.file-item {
display: flex; justify-content: space-between; align-items: center;
padding: 12px; border-bottom: 1px solid #f0f0f0; transition: 0.2s;
}
.file-item:hover { background-color: #fafafa; }
.file-name { font-weight: 500; color: #333; display: flex; align-items: center; gap: 10px; }
.file-meta { font-size: 13px; color: #888; text-align: right; }
.download-link {
color: var(--primary); text-decoration: none; font-weight: 600; margin-left: 15px;
border: 1px solid var(--primary); padding: 5px 12px; border-radius: 4px;
font-size: 12px;
}
.download-link:hover { background-color: var(--primary); color: white; }
.empty-msg { text-align: center; color: #999; font-style: italic; padding: 20px; }
/* Loading Spinner */
.spinner { border: 3px solid #f3f3f3; border-top: 3px solid var(--primary); border-radius: 50%; width: 20px; height: 20px; animation: spin 1s linear infinite; display: inline-block; margin-bottom: 5px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
/* Footer */
footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
</style>
</head>
<body>
<header>
<a href="#" class="logo">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path><polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline><line x1="12" y1="22.08" x2="12" y2="12"></line></svg>
<span>Armbian</span> Imager
</a>
<nav class="nav-links">
<a href="#">Docs</a>
<a href="#">Source</a>
<a href="#">Community</a>
</nav>
</header>
<div class="hero">
<h1>Flash OS images easily</h1>
<p>The ultimate tool for creating bootable USB drives and SD cards for Armbian.</p>
</div>
<div class="download-section">
<div class="card">
<!-- Automatic Section -->
<div class="auto-download">
<span class="auto-label">Recommended for your system</span>
<br>
<a id="main-btn" href="#" class="main-btn">
<span class="spinner"></span> Detecting...
</a>
<div id="detected-info" class="detected-info"></div>
</div>
<!-- Manual Section -->
<div class="manual-download">
<div class="tabs-header">
<button class="tab-btn active" onclick="switchTab('windows')">Windows</button>
<button class="tab-btn" onclick="switchTab('mac')">macOS</button>
<button class="tab-btn" onclick="switchTab('linux')">Linux</button>
</div>
<div id="tab-windows" class="tab-content active">
<ul class="file-list" id="list-windows"></ul>
</div>
<div id="tab-mac" class="tab-content">
<ul class="file-list" id="list-mac"></ul>
</div>
<div id="tab-linux" class="tab-content">
<ul class="file-list" id="list-linux"></ul>
</div>
</div>
</div>
</div>
<footer>
&copy; 2024 Armbian. Open Source software.
</footer>
<script>
//const REPO_OWNER = "armbian";
//const REPO_NAME = "imager";
//const API_URL = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest`;
// This points to the file generated by the GitHub Action
const API_URL = `./latest.json`;
const mainBtn = document.getElementById('main-btn');
const infoDiv = document.getElementById('detected-info');
// --- 1. INIT ---
window.addEventListener('DOMContentLoaded', async () => {
try {
// Fetch Data
const response = await fetch(API_URL);
if (!response.ok) throw new Error("API Limit Reached");
const release = await response.json();
// Detect Client
const { os, arch } = await getClientInfo();
// Render Auto Button
renderAutoButton(release, os, arch);
// Render Manual Lists (Updated Logic)
renderManualLists(release);
} catch (err) {
console.error(err);
mainBtn.innerHTML = "Manual Download";
mainBtn.href = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/latest`;
mainBtn.classList.add('ready');
infoDiv.innerText = "Could not auto-detect. Please select manually below.";
}
});
// --- 2. RENDER FUNCTIONS ---
function renderAutoButton(release, os, arch) {
const asset = findBestAsset(release.assets, os, arch);
const tagName = release.tag_name;
if (asset) {
mainBtn.href = asset.browser_download_url;
mainBtn.setAttribute('download', asset.name);
const osDisplay = os.charAt(0).toUpperCase() + os.slice(1);
mainBtn.innerHTML = `Download for ${osDisplay}`;
const sub = document.createElement('span');
sub.className = 'sub';
sub.innerText = `${tagName} • ${formatBytes(asset.size)}`;
mainBtn.appendChild(sub);
mainBtn.classList.add('ready');
infoDiv.innerText = `Detected Architecture: ${arch.toUpperCase()}`;
} else {
mainBtn.innerHTML = "Download Latest";
mainBtn.href = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/latest`;
mainBtn.classList.add('ready');
infoDiv.innerText = `We couldn't find a specific file for ${os} (${arch}). Check the tabs below.`;
}
}
function renderManualLists(release) {
const assets = release.assets;
// Helper to add "No files found" message if empty
const checkEmpty = (id) => {
const el = document.getElementById(id);
if(el.children.length === 0) {
el.innerHTML = `<li class="empty-msg">No files found for this OS in this release.</li>`;
}
};
// Clear lists
document.getElementById('list-windows').innerHTML = '';
document.getElementById('list-mac').innerHTML = '';
document.getElementById('list-linux').innerHTML = '';
let processedCount = 0;
assets.forEach(asset => {
const name = asset.name;
const lowerName = name.toLowerCase();
// Filter out non-binary files
if (name.endsWith('.txt') || name.endsWith('.json') || name.endsWith('.sha256') || name.endsWith('.md5')) return;
let targetListId = null;
// --- IMPROVED FILTERING LOGIC ---
// 1. Windows Check
if (lowerName.includes('win') || name.endsWith('.exe')) {
targetListId = 'list-windows';
}
// 2. macOS Check
else if (lowerName.includes('mac') || lowerName.includes('darwin') || name.endsWith('.dmg')) {
targetListId = 'list-mac';
}
// 3. Linux Check (Specific formats)
else if (name.endsWith('.AppImage') || name.endsWith('.deb') || name.endsWith('.rpm')) {
targetListId = 'list-linux';
}
// 4. Ambiguous Files (.zip, .tar, etc.)
else if (name.endsWith('.zip')) {
// For zips, we rely heavily on naming
if (lowerName.includes('win')) targetListId = 'list-windows';
else if (lowerName.includes('mac')) targetListId = 'list-mac';
else if (lowerName.includes('linux') || lowerName.includes('arm64') || lowerName.includes('amd64')) {
// Assuming zips with arch keywords are Linux unless proven otherwise
targetListId = 'list-linux';
}
}
// If we found a target, render it
if (targetListId) {
processedCount++;
const li = document.createElement('li');
li.className = 'file-item';
li.innerHTML = `
<div class="file-name">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#666" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
${name}
</div>
<div class="file-meta">
${formatBytes(asset.size)}
<a href="${asset.browser_download_url}" class="download-link">Download</a>
</div>
`;
document.getElementById(targetListId).appendChild(li);
}
});
console.log(`Processed ${processedCount} assets out of ${assets.length} total.`);
// Final check for empty tabs
checkEmpty('list-windows');
checkEmpty('list-mac');
checkEmpty('list-linux');
}
// --- 3. LOGIC HELPERS ---
function switchTab(os) {
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
event.target.classList.add('active');
document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
document.getElementById(`tab-${os}`).classList.add('active');
}
async function getClientInfo() {
if (navigator.userAgentData && navigator.userAgentData.getHighEntropyValues) {
const uaData = await navigator.userAgentData.getHighEntropyValues(['architecture', 'platform']);
return {
os: normalizeOS(uaData.platform),
arch: normalizeArch(uaData.architecture)
};
}
const ua = navigator.userAgent;
let os = "unknown", arch = "unknown";
if (ua.indexOf("Win") !== -1) os = "windows";
else if (ua.indexOf("Mac") !== -1) os = "mac";
else if (ua.indexOf("Linux") !== -1) os = "linux";
if (ua.indexOf("arm") !== -1 || ua.indexOf("aarch64") !== -1) arch = "arm64";
else if (ua.indexOf("x86_64") !== -1 || ua.indexOf("x64") !== -1) arch = "x64";
else if (os === "mac") arch = "arm64";
else arch = "x64";
return { os, arch };
}
function normalizeOS(platform) {
if (platform === "Windows") return "windows";
if (platform === "macOS") return "mac";
if (platform === "Linux") return "linux";
return platform.toLowerCase();
}
function normalizeArch(arch) {
if (arch === "arm" || arch === "arm64" || arch === "aarch64") return "arm64";
if (arch === "x86" || arch === "x86_64" || arch === "x64") return "x64";
return "unknown";
}
function findBestAsset(assets, os, arch) {
const compatible = assets.filter(a => {
const name = a.name.toLowerCase();
if (os === 'windows') {
if (arch === 'x64') return name.includes('win') && name.includes('x64');
}
if (os === 'mac') {
if (arch === 'arm64') return name.includes('macos') && (name.includes('arm64') || name.includes('aarch64'));
if (arch === 'x64') return name.includes('macos') && name.includes('x64');
}
if (os === 'linux') {
if (name.includes('win') || name.includes('macos') || name.includes('darwin')) return false;
if (arch === 'x64') return name.includes('amd64') || name.includes('x86_64') || name.includes('x64');
if (arch === 'arm64') return name.includes('arm64') || name.includes('aarch64');
}
return false;
});
// Prefer AppImage
compatible.sort((a, b) => {
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();
if (nameA.includes('appimage') && !nameB.includes('appimage')) return -1;
return 0;
});
return compatible[0] || null;
}
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
</script>
</body>
</html>