b3709b9766
A string table per language (launcher/lang/<code>.json, English text to its translation) and tr()/trf() in i18n.rs. The window follows the system's language unless Settings > Launcher > Language picks one; a missing string shows in English. This first part translates the top bar, the account switch and the Settings page's account, update and launcher rows; buttons, segments, section titles and page headers translate through their widgets. CLI: settings language system|en|fr|ru. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.1 KiB
Rust
93 lines
3.1 KiB
Rust
//! What the window does while the game runs (`backend::WhilePlaying`): stay, minimise, or hide
|
|
//! (macOS), and come back to the front when the game closes, with how the run ended.
|
|
use super::*;
|
|
use backend::WhilePlaying;
|
|
use gpui::AnyWindowHandle;
|
|
|
|
pub(super) struct Aside {
|
|
/// The launcher's window.
|
|
window: AnyWindowHandle,
|
|
/// What the window did when the game started, to undo when it closes.
|
|
stepped: Option<WhilePlaying>,
|
|
}
|
|
|
|
impl Aside {
|
|
pub(super) fn new(window: AnyWindowHandle) -> Self {
|
|
Aside {
|
|
window,
|
|
stepped: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Launcher {
|
|
/// The game started: get out of its way as the player asked. Read from `settings.json`, so
|
|
/// `horizon-launcher settings while-playing …` counts at once.
|
|
pub(super) fn step_aside(&mut self, cx: &mut Context<Self>) {
|
|
self.settings.while_playing = Settings::load().while_playing;
|
|
let how = self.settings.while_playing.here();
|
|
if how == WhilePlaying::Stay {
|
|
return;
|
|
}
|
|
let window = self.aside.window;
|
|
self.aside.stepped = Some(how);
|
|
cx.defer(move |cx| match how {
|
|
WhilePlaying::Hide => cx.hide(),
|
|
_ => {
|
|
let _ = window.update(cx, |_, window, _| window.minimize_window());
|
|
}
|
|
});
|
|
}
|
|
|
|
/// The game closed: back to the front, where its play time, errors and log are.
|
|
pub(super) fn come_back(&mut self, cx: &mut Context<Self>) {
|
|
if self.aside.stepped.take().is_none() {
|
|
return;
|
|
}
|
|
let window = self.aside.window;
|
|
cx.defer(move |cx| {
|
|
cx.activate(true);
|
|
let _ = window.update(cx, |_, window, _| window.activate_window());
|
|
});
|
|
}
|
|
|
|
/// Settings' row for it.
|
|
pub(super) fn while_playing_row(&self, n: usize, cx: &mut Context<Self>) -> Div {
|
|
let t = self.theme;
|
|
let mut options = vec![
|
|
(WhilePlaying::Stay, "Stay"),
|
|
(WhilePlaying::Minimize, "Minimise"),
|
|
];
|
|
if cfg!(target_os = "macos") {
|
|
options.push((WhilePlaying::Hide, "Hide"));
|
|
}
|
|
let current = self.settings.while_playing.here();
|
|
let picker = segments("while-playing", &options, current, &t, {
|
|
let this = cx.entity().downgrade();
|
|
move |choice, _, cx| {
|
|
let _ = this.update(cx, |this, cx| {
|
|
this.settings.while_playing = choice;
|
|
this.settings.save();
|
|
cx.notify();
|
|
});
|
|
}
|
|
});
|
|
let said = match current {
|
|
WhilePlaying::Stay => "The launcher stays open while you play.",
|
|
WhilePlaying::Minimize => {
|
|
"The launcher goes down when the game starts, and comes back when it closes."
|
|
}
|
|
WhilePlaying::Hide => {
|
|
"The launcher hides when the game starts, and comes back when it closes."
|
|
}
|
|
};
|
|
index_row(
|
|
n,
|
|
tr("While playing"),
|
|
Some(div().child(tr(said)).into_any_element()),
|
|
Some(picker.into_any_element()),
|
|
&t,
|
|
)
|
|
}
|
|
}
|