Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions openless-all/app/crates/openless-core/src/shared_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ pub struct UserPreferences {
/// 手动检查按钮显式指定 channel,与此 pref 解耦。
#[serde(default)]
pub update_channel: UpdateChannel,
/// 是否由用户明确选择过更新渠道。旧版默认会把 Stable 写入配置,单看
/// `update_channel` 无法区分默认值与主动切换;历史 Beta 则必然来自用户 opt-in。
#[serde(default)]
pub update_channel_explicit: bool,
/// 历史记录保留天数。0 = 不按时间清理(仅受 200 条上限)。默认 7 天。
/// 写入新条目时执行清理,避免后台轮询。
#[serde(default = "default_history_retention_days")]
Expand Down Expand Up @@ -887,6 +891,8 @@ struct UserPreferencesWire {
sherpa_onnx_keep_loaded_secs: u32,
#[serde(default)]
update_channel: UpdateChannel,
#[serde(default)]
update_channel_explicit: Option<bool>,
#[serde(default = "default_history_retention_days")]
history_retention_days: u32,
#[serde(default = "default_polish_context_window_minutes")]
Expand Down Expand Up @@ -1054,6 +1060,8 @@ impl Default for UserPreferencesWire {
sherpa_onnx_language_hint: prefs.sherpa_onnx_language_hint,
sherpa_onnx_keep_loaded_secs: prefs.sherpa_onnx_keep_loaded_secs,
update_channel: prefs.update_channel,
// None 保留旧配置缺少标记的信息;反序列化时只有历史 Beta 视为显式选择。
update_channel_explicit: None,
history_retention_days: prefs.history_retention_days,
polish_context_window_minutes: prefs.polish_context_window_minutes,
start_minimized: prefs.start_minimized,
Expand Down Expand Up @@ -1121,6 +1129,9 @@ impl<'de> Deserialize<'de> for UserPreferences {
};
let (local_asr_active_model, local_whisper_active_model) =
migrate_local_asr_models(wire.local_asr_active_model, wire.local_whisper_active_model);
let update_channel_explicit = wire
.update_channel_explicit
.unwrap_or(matches!(wire.update_channel, UpdateChannel::Beta));

Ok(Self {
hotkey: wire.hotkey,
Expand Down Expand Up @@ -1216,6 +1227,7 @@ impl<'de> Deserialize<'de> for UserPreferences {
sherpa_onnx_language_hint: wire.sherpa_onnx_language_hint,
sherpa_onnx_keep_loaded_secs: wire.sherpa_onnx_keep_loaded_secs,
update_channel: wire.update_channel,
update_channel_explicit,
history_retention_days: wire.history_retention_days,
polish_context_window_minutes: wire.polish_context_window_minutes,
start_minimized: wire.start_minimized,
Expand Down Expand Up @@ -1556,6 +1568,7 @@ impl Default for UserPreferences {
sherpa_onnx_language_hint: String::new(),
sherpa_onnx_keep_loaded_secs: default_local_asr_keep_loaded_secs(),
update_channel: UpdateChannel::default(),
update_channel_explicit: false,
history_retention_days: default_history_retention_days(),
polish_context_window_minutes: default_polish_context_window_minutes(),
start_minimized: false,
Expand Down Expand Up @@ -3118,6 +3131,32 @@ mod tests {
assert!(!prefs.streaming_insert_save_clipboard);
}

#[test]
fn update_channel_migration_preserves_only_explicit_legacy_beta_opt_in() {
let legacy_stable: UserPreferences =
serde_json::from_str(r#"{ "updateChannel": "stable" }"#).unwrap();
assert_eq!(legacy_stable.update_channel, UpdateChannel::Stable);
assert!(!legacy_stable.update_channel_explicit);

let legacy_beta: UserPreferences =
serde_json::from_str(r#"{ "updateChannel": "beta" }"#).unwrap();
assert_eq!(legacy_beta.update_channel, UpdateChannel::Beta);
assert!(legacy_beta.update_channel_explicit);

let explicit_stable: UserPreferences = serde_json::from_str(
r#"{
"updateChannel": "stable",
"updateChannelExplicit": true
}"#,
)
.unwrap();
assert!(explicit_stable.update_channel_explicit);

let round_trip: UserPreferences =
serde_json::from_str(&serde_json::to_string(&explicit_stable).unwrap()).unwrap();
assert!(round_trip.update_channel_explicit);
}

#[test]
fn paste_shortcut_round_trips_explicit_values() {
for (raw, expected) in [
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions openless-all/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tauri-plugin-shell = "2.3.5"
tauri-plugin-dialog = "2.7.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
semver = "1"
# OpenRouter ASR 把音频以标准 base64(带 padding)放进 JSON body(issue #582)。
base64 = "0.22"
sha2 = "0.10"
Expand Down
35 changes: 13 additions & 22 deletions openless-all/app/src-tauri/src/android/updater_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@ pub fn map_abi_to_arch(abi: &str) -> &'static str {
}

pub fn version_is_newer(remote: &str, current: &str) -> bool {
fn parts(v: &str) -> Vec<u32> {
v.split(|c| c == '.' || c == '-')
.filter_map(|p| p.parse().ok())
.collect()
}
let remote_parts = parts(remote);
let current_parts = parts(current);
let max = remote_parts.len().max(current_parts.len());
for i in 0..max {
let r = remote_parts.get(i).copied().unwrap_or(0);
let c = current_parts.get(i).copied().unwrap_or(0);
if r > c {
return true;
}
if r < c {
return false;
}
}
false
let (Ok(remote), Ok(current)) = (
semver::Version::parse(remote),
semver::Version::parse(current),
) else {
return false;
};
remote > current
}

pub fn stable_manifest_urls(arch: &str) -> Vec<String> {
Expand Down Expand Up @@ -78,9 +66,12 @@ mod tests {
}

#[test]
fn version_is_newer_handles_beta_suffix() {
assert!(version_is_newer("1.3.8-1", "1.3.8"));
assert!(!version_is_newer("1.3.8", "1.3.8-1"));
fn version_is_newer_uses_semver_prerelease_ordering() {
assert!(version_is_newer("1.3.18", "1.3.18-Beta.7"));
assert!(version_is_newer("1.3.18-Beta.8", "1.3.18-Beta.7"));
assert!(!version_is_newer("1.3.18-Beta.7", "1.3.18-Beta.7"));
assert!(!version_is_newer("1.3.17", "1.3.18-Beta.7"));
assert!(!version_is_newer("not-a-version", "1.3.18-Beta.7"));
}

#[test]
Expand Down
130 changes: 117 additions & 13 deletions openless-all/app/src-tauri/src/commands/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use super::*;

#[tauri::command]
pub fn get_settings(core: CoreState<'_>) -> UserPreferences {
core.get_preferences()
let mut prefs = core.get_preferences();
prefs.update_channel = effective_update_channel(None, &prefs, env!("CARGO_PKG_VERSION"));
prefs
}

#[tauri::command]
Expand Down Expand Up @@ -143,8 +145,10 @@ impl openless_core::SettingsRuntime for TauriSettingsRuntime<'_> {
}
}

pub(crate) fn persist_settings(coord: &Coordinator, prefs: UserPreferences) -> Result<(), String> {
let _host_guard = coord.lock_settings_host();
fn persist_settings_with_host_lock_held(
coord: &Coordinator,
prefs: UserPreferences,
) -> Result<(), String> {
coord
.backend()
.update_settings(
Expand All @@ -163,11 +167,22 @@ pub(crate) fn persist_settings(coord: &Coordinator, prefs: UserPreferences) -> R
.map_err(|error| error.to_string())
}

fn persist_settings_preserving_update_channel(
coord: &Coordinator,
mut prefs: UserPreferences,
) -> Result<(), String> {
let _host_guard = coord.lock_settings_host();
// 在同一把写锁内读取并回填,避免并发渠道切换被旧设置快照覆盖。
preserve_update_channel_preferences(&mut prefs, &coord.backend().get_preferences());
persist_settings_with_host_lock_held(coord, prefs)
}

pub(crate) fn persist_strict_settings(
coord: &Coordinator,
prefs: UserPreferences,
mut prefs: UserPreferences,
) -> Result<(), String> {
let _host_guard = coord.lock_settings_host();
preserve_update_channel_preferences(&mut prefs, &coord.backend().get_preferences());
coord
.backend()
.update_settings(
Expand Down Expand Up @@ -198,7 +213,7 @@ pub async fn set_settings(
// 广播给所有 webview。issue #205:QaPanel 跑在独立 webview,
// 没有 HotkeySettingsContext,必须靠事件感知录音键变化,否则面板可见时
// 用户改键会让浮窗里的 "{recordHotkey}" 文案一直停留在旧值。
persist_settings(&*coord, prefs)?;
persist_settings_preserving_update_channel(&*coord, prefs)?;
let prefs = coord.backend().get_preferences();
// 保存即同步胶囊样式原子:下一次录音的入场帧就携带新样式,不依赖 emit_capsule
// 主线程闭包的 ~30Hz 同步(Windows 主线程拥塞时闭包延迟 → 整场显示旧样式)。
Expand Down Expand Up @@ -257,7 +272,7 @@ pub fn set_settings(coord: CoordinatorState<'_>, mut prefs: UserPreferences) ->
.map_err(|e| e.to_string())?;
sync_style_pack_preferences(&mut prefs, &packs);
prefs.android_overlay_trigger = prefs.android_overlay_trigger.normalized();
persist_settings(&*coord, prefs)?;
persist_settings_preserving_update_channel(&*coord, prefs)?;
let prefs = coord.backend().get_preferences();
// 保存即同步胶囊样式原子(Android 通知胶囊 payload 同源,见 emit_capsule)。
coord.sync_capsule_style_from_preferences();
Expand Down Expand Up @@ -297,6 +312,63 @@ mod tests {
);
assert_eq!(stale_settings_payload.default_mode, PolishMode::Light);
}

#[test]
fn update_channel_defaults_to_build_channel_until_user_selects_one() {
let mut prefs = UserPreferences::default();

assert_eq!(
effective_update_channel(None, &prefs, "2.0.0-Beta.1"),
UpdateChannel::Beta
);
assert_eq!(
effective_update_channel(None, &prefs, "2.0.0"),
UpdateChannel::Stable
);
let legacy_beta = UserPreferences {
update_channel: UpdateChannel::Beta,
update_channel_explicit: true,
..UserPreferences::default()
};
assert_eq!(
effective_update_channel(None, &legacy_beta, "2.0.0"),
UpdateChannel::Beta
);
assert_eq!(
effective_update_channel(Some(UpdateChannel::Stable), &prefs, "2.0.0-Beta.1"),
UpdateChannel::Stable
);

assert!(select_update_channel(&mut prefs, UpdateChannel::Stable));
assert!(prefs.update_channel_explicit);
assert_eq!(
effective_update_channel(None, &prefs, "2.0.0-Beta.1"),
UpdateChannel::Stable
);
assert!(!select_update_channel(&mut prefs, UpdateChannel::Stable));
assert!(select_update_channel(&mut prefs, UpdateChannel::Beta));
assert_eq!(prefs.update_channel, UpdateChannel::Beta);
assert!(prefs.update_channel_explicit);
}

#[test]
fn general_settings_save_preserves_dedicated_update_channel_fields() {
let current = UserPreferences {
update_channel: UpdateChannel::Stable,
update_channel_explicit: true,
..UserPreferences::default()
};
let mut stale_payload = UserPreferences {
update_channel: UpdateChannel::Beta,
update_channel_explicit: false,
..UserPreferences::default()
};

preserve_update_channel_preferences(&mut stale_payload, &current);

assert_eq!(stale_payload.update_channel, UpdateChannel::Stable);
assert!(stale_payload.update_channel_explicit);
}
}

// ─────────────────────────── release channel (Beta opt-in) ───────────────────────────
Expand All @@ -312,22 +384,52 @@ mod tests {
// (Beta tag 的 manifest 文件名带 `-beta` 后缀,跟 Stable manifest 在 GitHub
// Release assets 里物理分离)。

fn effective_update_channel(
requested: Option<UpdateChannel>,
prefs: &UserPreferences,
app_version: &str,
) -> UpdateChannel {
requested.unwrap_or_else(|| {
if prefs.update_channel_explicit {
prefs.update_channel
} else if app_version.contains('-') {
UpdateChannel::Beta
} else {
UpdateChannel::Stable
}
})
}

fn select_update_channel(prefs: &mut UserPreferences, channel: UpdateChannel) -> bool {
let changed = prefs.update_channel != channel || !prefs.update_channel_explicit;
prefs.update_channel = channel;
prefs.update_channel_explicit = true;
changed
}

fn preserve_update_channel_preferences(incoming: &mut UserPreferences, current: &UserPreferences) {
incoming.update_channel = current.update_channel;
incoming.update_channel_explicit = current.update_channel_explicit;
}

#[tauri::command]
pub fn get_update_channel(core: CoreState<'_>) -> UpdateChannel {
core.get_preferences().update_channel
let prefs = core.get_preferences();
effective_update_channel(None, &prefs, env!("CARGO_PKG_VERSION"))
}

#[tauri::command]
pub fn set_update_channel(
coord: CoordinatorState<'_>,
channel: UpdateChannel,
) -> Result<(), String> {
// 渠道读取和持久化必须同属一个写临界区,避免反向覆盖并发常规设置。
let _host_guard = coord.lock_settings_host();
let mut prefs = coord.backend().get_preferences();
if prefs.update_channel == channel {
if !select_update_channel(&mut prefs, channel) {
return Ok(());
}
prefs.update_channel = channel;
persist_settings(&*coord, prefs)?;
persist_settings_with_host_lock_held(&*coord, prefs)?;
Ok(())
}

Expand Down Expand Up @@ -465,7 +567,7 @@ pub struct AppUpdateMetadata {

/// 决定 manifest 来源后走 plugin-updater 的标准 check 流程。
/// 渠道:显式传入 `channel` 时用它(关于页固定查 Stable、高级页 Beta 区查 Beta);
/// 不传则回落到 `prefs.update_channel`(后台 AutoUpdateGate 自动检查走这条)
/// 不传则使用用户明确选择的渠道;尚未选择时跟随当前构建类型
/// 返回 None = 当前是最新;Some(metadata) = 有新版可装。
#[tauri::command]
#[cfg(not(mobile))]
Expand All @@ -477,7 +579,8 @@ pub async fn app_check_update_with_channel<R: tauri::Runtime>(
) -> Result<Option<AppUpdateMetadata>, String> {
use tauri_plugin_updater::UpdaterExt;

let channel = channel.unwrap_or_else(|| coord.backend().get_preferences().update_channel);
let prefs = coord.backend().get_preferences();
let channel = effective_update_channel(channel, &prefs, env!("CARGO_PKG_VERSION"));
let mut builder = webview.updater_builder();
if let Some(ms) = timeout_ms {
builder = builder.timeout(std::time::Duration::from_millis(ms));
Expand Down Expand Up @@ -541,7 +644,8 @@ pub async fn app_check_update_with_channel(
) -> Result<Option<AppUpdateMetadata>, String> {
#[cfg(target_os = "android")]
{
let channel = channel.unwrap_or_else(|| coord.backend().get_preferences().update_channel);
let prefs = coord.backend().get_preferences();
let channel = effective_update_channel(channel, &prefs, env!("CARGO_PKG_VERSION"));
return crate::android::updater::check_update(channel).await;
}
#[cfg(not(target_os = "android"))]
Expand Down
Loading
Loading