Skip to content
20 changes: 17 additions & 3 deletions packages/desktop-shell/bootstrap/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const logs = document.querySelector('#logs');
const update = document.querySelector('#update');
const version = document.querySelector('#version');

let currentWorkspace = '';
let runtimeStatus;
let updateVersion;

function setWorkspace(path) {
Expand All @@ -21,6 +23,7 @@ function setWorkspace(path) {
}

function setStatus(kind, heading, message, failure = '') {
document.body.dataset.state = kind;
title.textContent = heading;
detail.textContent = message;
pulse.className = `pulse ${kind === 'starting' ? '' : kind}`;
Expand All @@ -29,18 +32,20 @@ function setStatus(kind, heading, message, failure = '') {
retry.hidden = kind !== 'error';
choose.hidden = kind === 'starting';
choose.disabled = kind === 'starting';
setWorkspace();
}

async function chooseWorkspace() {
if (!invoke) return;
runtimeStatus = 'starting';
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
setStatus(
'starting',
'Opening workspace',
'Starting the bundled Qwen Code runtime…',
);
try {
const path = await invoke('choose_workspace');
if (path) setWorkspace(path);
if (path) currentWorkspace = path;
else
setStatus('idle', 'Choose another workspace', 'No folder was selected.');
} catch (failure) {
Expand All @@ -55,6 +60,7 @@ async function chooseWorkspace() {

async function retryRuntime() {
if (!invoke) return;
runtimeStatus = 'starting';
setStatus(
'starting',
'Restarting Qwen Code',
Expand Down Expand Up @@ -123,20 +129,23 @@ async function initialize() {

await Promise.all([
listen('runtime-starting', ({ payload }) => {
setWorkspace(payload);
runtimeStatus = 'starting';
currentWorkspace = String(payload || '');
setStatus(
'starting',
'Starting Qwen Code',
'Launching the bundled runtime and checking its health…',
);
}),
listen('runtime-failed', ({ payload }) => {
runtimeStatus = 'failed';
setStatus(
'error',
'Qwen Code could not start',
'Review the details, open the log, or choose another workspace.',
String(payload),
);
setWorkspace(currentWorkspace);
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
}),
listen('update-available', ({ payload }) => {
updateVersion = String(payload);
Expand All @@ -147,7 +156,11 @@ async function initialize() {

const state = await invoke('bootstrap_state');
version.textContent = `Desktop ${state.desktopVersion}`;
setWorkspace(state.workspace);
currentWorkspace ||= String(state.workspace || '');
if (runtimeStatus) {
if (runtimeStatus === 'failed') setWorkspace(currentWorkspace);
return;
}
if (state.status === 'starting') {
setStatus(
'starting',
Expand All @@ -167,6 +180,7 @@ async function initialize() {
'Review the details, open the log, or choose another workspace.',
state.error,
);
setWorkspace(currentWorkspace);
} else {
setStatus(
'idle',
Expand Down
45 changes: 43 additions & 2 deletions packages/desktop-shell/bootstrap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,47 @@
700 26px/1 ui-monospace,
monospace;
}
body[data-state='starting'] {
background: #070b12;
}
body[data-state='starting']::before,
body[data-state='starting'] .brand-copy,
body[data-state='starting'] .actions,
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
body[data-state='starting'] footer {
display: none;
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
}
body[data-state='starting'] .shell {
width: auto;
border: 0;
padding: 0;
background: none;
box-shadow: none;
backdrop-filter: none;
}
body[data-state='starting'] .mark {
animation: mark-pulse 1.6s ease-in-out infinite;
}
body[data-state='starting'] .status {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
white-space: nowrap;
}
@keyframes mark-pulse {
50% {
opacity: 0.55;
transform: scale(0.94);
}
}
@media (prefers-reduced-motion: reduce) {
body[data-state='starting'] .mark {
animation: none;
}
}
h1 {
margin: 0;
font-size: 28px;
Expand Down Expand Up @@ -232,12 +273,12 @@
}
</style>
</head>
<body>
<body data-state="starting">
<main>
<section class="shell" aria-live="polite">
<div class="brand">
<div class="mark">Q</div>
<div>
<div class="brand-copy">
<h1>Qwen Code</h1>
<p class="eyebrow">Desktop workspace</p>
</div>
Expand Down
76 changes: 76 additions & 0 deletions packages/desktop-shell/scripts/test-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import vm from 'node:vm';
import { fileURLToPath } from 'node:url';
import { resolveLogRoot, sliceNewLog } from './resolve-log-root.js';

Expand Down Expand Up @@ -39,6 +40,7 @@ const root = fs.mkdtempSync(
);
try {
testBootstrapBridgeConfiguration();
await testBootstrapWorkspaceVisibility();
testLegacyApplicationIdentity();
testElectronBridgeWorkflow();
testDesktopReleaseSigningWorkflow();
Expand All @@ -52,6 +54,80 @@ try {
fs.rmSync(root, { recursive: true, force: true });
}

async function testBootstrapWorkspaceVisibility() {
const elements = {};
const element = (selector) => {
elements[selector] ??= {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
addEventListener(event, listener) {
this.listeners ??= {};
this.listeners[event] = listener;
},
style: {},
};
return elements[selector];
};
const listeners = {};
const body = { dataset: {} };
let resolveBootstrapState;
const tauri = {
core: {
invoke: async (command) => {
if (command === 'bootstrap_state') {
return new Promise((resolve) => {
resolveBootstrapState = resolve;
});
}
assert.equal(command, 'restart_runtime');
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
return new Promise(() => {});
},
},
event: {
listen: async (event, listener) => {
listeners[event] = listener;
},
},
};
vm.runInNewContext(
fs.readFileSync(path.join(packageDir, 'bootstrap', 'bootstrap.js'), 'utf8'),
{
document: { body, querySelector: element },
window: { __TAURI__: tauri },
},
);
await new Promise((resolve) => setImmediate(resolve));

listeners['runtime-starting']({
payload: '/Users/example/Projects/qwen-code',
});
assert.equal(body.dataset.state, 'starting');
assert.equal(element('#workspace').hidden, true);

listeners['runtime-failed']({ payload: 'runtime failed' });
assert.equal(body.dataset.state, 'error');
assert.equal(element('#workspace').hidden, false);
assert.equal(
element('#workspace').textContent,
'/Users/example/Projects/qwen-code',
);

element('#retry').listeners.click();
assert.equal(body.dataset.state, 'starting');
assert.equal(element('#workspace').hidden, true);

resolveBootstrapState({
desktopVersion: '0.2.0',
status: 'starting',
workspace: '/Users/example/Documents',
});
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
await new Promise((resolve) => setImmediate(resolve));
assert.equal(element('#title').textContent, 'Restarting Qwen Code');
assert.equal(
element('#workspace').hidden,
true,
'A stale bootstrap snapshot must not overwrite a newer recovery action.',
);
}

function testLegacyApplicationIdentity() {
const config = JSON.parse(
fs.readFileSync(
Expand Down
39 changes: 32 additions & 7 deletions packages/desktop-shell/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ fn bootstrap_state(
require_bootstrap_origin(&webview)?;
let starting = state.starting.load(Ordering::SeqCst) != 0;
let running = lock(&state.runtime).is_some();
let workspace = bootstrap_workspace(
lock(&state.last_workspace).clone(),
state.settings.workspace(),
);
Ok(BootstrapState {
desktop_version: env!("CARGO_PKG_VERSION").to_string(),
status: if running {
Expand All @@ -316,14 +320,20 @@ fn bootstrap_state(
} else {
"idle"
},
workspace: state
.settings
.workspace()
.map(|path| path.to_string_lossy().into_owned()),
workspace: workspace.map(|path| path.to_string_lossy().into_owned()),
error: lock(&state.last_error).clone(),
})
}

fn bootstrap_workspace(
last_workspace: Option<(PathBuf, bool)>,
persisted_workspace: Option<PathBuf>,
) -> Option<PathBuf> {
last_workspace
.map(|(workspace, _)| workspace)
.or(persisted_workspace)
}

#[tauri::command]
async fn choose_workspace(
webview: WebviewWindow,
Expand Down Expand Up @@ -895,9 +905,9 @@ mod tests {
FULLSCREEN_HIDE_GENERATION, FULLSCREEN_HIDE_PENDING,
};
use super::{
default_workspace_override_dir, default_workspace_path, ensure_workspace_dir,
is_allowed_navigation, is_bootstrap_url, is_safe_external_url, is_same_origin, origin_of,
BOOTSTRAP_URL,
bootstrap_workspace, default_workspace_override_dir, default_workspace_path,
ensure_workspace_dir, is_allowed_navigation, is_bootstrap_url, is_safe_external_url,
is_same_origin, origin_of, BOOTSTRAP_URL,
};
use std::ffi::OsString;
use std::fs;
Expand All @@ -907,6 +917,21 @@ mod tests {
use std::sync::Mutex;
use url::Url;

#[test]
fn bootstrap_prefers_the_workspace_being_started() {
let attempted = PathBuf::from("/tmp/attempted");
let persisted = PathBuf::from("/tmp/persisted");
assert_eq!(
bootstrap_workspace(Some((attempted.clone(), false)), Some(persisted.clone())),
Some(attempted),
);
assert_eq!(
bootstrap_workspace(None, Some(persisted.clone())),
Some(persisted)
);
assert_eq!(bootstrap_workspace(None, None), None);
}

#[cfg(target_os = "macos")]
#[test]
fn fullscreen_hide_lifecycle_state() {
Expand Down
Loading