Skip to content

Commit

Permalink
feat: show warning when installing handheld on desktop (#85)
Browse files Browse the repository at this point in the history
* feat: show warning when installing handheld on desktop

for handheld edition, use `chwd` to check if the device is a known
handheld device or not. If it is not a known handheld device, show a
warning that the user is trying to install the handheld edition on
unsupported hardware

Signed-off-by: SoulHarsh007 <[email protected]>

* fix: use `/etc/edition-tag` instead of `/etc/version-tag`

Signed-off-by: SoulHarsh007 <[email protected]>

* chore: improve RU translation

Signed-off-by: SoulHarsh007 <[email protected]>

* chore: cleanup and use helper functions from `chwd`

Signed-off-by: SoulHarsh007 <[email protected]>

* chore: bump deps and make clippy happy

Signed-off-by: SoulHarsh007 <[email protected]>

---------

Signed-off-by: SoulHarsh007 <[email protected]>
  • Loading branch information
SoulHarsh007 authored Oct 27, 2024
1 parent 2731294 commit 2f25c12
Show file tree
Hide file tree
Showing 14 changed files with 593 additions and 146 deletions.
689 changes: 548 additions & 141 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde_json = "1"
reqwest = { version = "0.12", features = ["blocking"] }
unic-langid = "0.9"
phf = { version = "0.11", features = ["macros"], default-features = false }
chwd = { git = "https://github.com/CachyOS/chwd", rev = "d7e7e65c5c2c0ffe0434adad9a0016617d1f8bb7", version = "1.10.0" }

[build-dependencies]
anyhow = "1"
Expand Down
1 change: 1 addition & 0 deletions i18n/by/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ calamares-install-type = тып усталёўкі Calamares
# Main Page (body)
offline-error = Не ўдаецца запусціць анлайн-усталёўку! Няма падлучэння да Інтэрнэту
unsupported-hw-warning = Вы спрабуеце ўсталяваць на абсталяванне, якое не падтрымліваецца бягучым ISO, ваша ўстаноўка не будзе мець права на падтрымку
tweaksbrowser-label = Праграммы/Налады
appbrowser-label = Устанавіць Праграммы
launch-start-label = Запуск пры старту
Expand Down
1 change: 1 addition & 0 deletions i18n/cs/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ calamares-install-type = Typ Instalace Calamares
# Hlavní stránka (tělo)
offline-error = Nedá se spustit online instalace! Žádné internetové připojení
unsupported-hw-warning = Pokoušíte se instalovat na hardware, který není podporován aktuální verzí ISO, vaše instalace nebude mít nárok na podporu
tweaksbrowser-label = Aplikacie/Vylepšení
appbrowser-label = Instalovat Aplikace
launch-start-label = Spustit při startu
Expand Down
1 change: 1 addition & 0 deletions i18n/de/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ section-project = PROJEKT
# Main Page (body)
offline-error = Die Online-Installation kann nicht gestartet werden! Keine Internetverbindung
unsupported-hw-warning = Sie versuchen, die Installation auf einer Hardware durchzuführen, die von der aktuellen ISO nicht unterstützt wird, und können daher keinen Support in Anspruch nehmen
tweaksbrowser-label = Apps/Tweaks
appbrowser-label = Apps installieren
launch-start-label = Beim Systemstart ausführen
Expand Down
1 change: 1 addition & 0 deletions i18n/en/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ calamares-install-type = Calamares install type
# Main Page (body)
offline-error = Unable to start online installation! No internet connection
unsupported-hw-warning = You are attempting to install on hardware not supported by the current ISO, your installation will not be eligible for support
tweaksbrowser-label = Apps/Tweaks
appbrowser-label = Install Apps
launch-start-label = Launch at start
Expand Down
1 change: 1 addition & 0 deletions i18n/it/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ section-project = PROGETTO
# Main Page (body)
offline-error = Impossibile avviare l'installazione online! Connessione a internet assente
unsupported-hw-warning = Si sta tentando di effettuare l'installazione su un hardware non supportato dall'ISO corrente; l'installazione non potrà beneficiare dell'assistenza
tweaksbrowser-label = Applicazioni/Personalizzazioni
appbrowser-label = Installa Applicazioni
launch-start-label = Lancia all'avvio
Expand Down
1 change: 1 addition & 0 deletions i18n/nl/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ calamares-install-type = Calamares-installatietype
# Main Page (body)
offline-error = De installatie kan niet worden gestart: er is geen internetverbinding
unsupported-hw-warning = U probeert te installeren op hardware die niet wordt ondersteund door de huidige ISO, uw installatie komt niet in aanmerking voor ondersteuning
tweaksbrowser-label = Programma's/Aanpassingen
appbrowser-label = Programma's installeren
launch-start-label = Tonen na opstarten
Expand Down
1 change: 1 addition & 0 deletions i18n/pl/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ section-project = PROJEKT
# Main Page (body)
offline-error = Instalacja online niemożliwa! Brak połączenia internetowego
unsupported-hw-warning = Próba instalacji na sprzęcie nieobsługiwanym przez aktualne ISO spowoduje, że instalacja nie będzie objęta pomocą techniczną
tweaksbrowser-label = Programy/Usprawnienia
appbrowser-label = Instalator Programów
launch-start-label = Uruchamiaj przy starcie
Expand Down
1 change: 1 addition & 0 deletions i18n/ru/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ calamares-install-type = Calamares тип установки
# Main Page (body)
offline-error = Не удается запустить онлайн-установку! Нет подключения к Интернету
unsupported-hw-warning = Вы пытаетесь установить систему на оборудовании, не поддерживаемом текущим ISO. Ваша установка не будет иметь поддержки
tweaksbrowser-label = Приложения/Настройки
appbrowser-label = Установить ПO
launch-start-label = Автозапуск
Expand Down
1 change: 1 addition & 0 deletions i18n/sk/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ calamares-install-type = Typ inštalácie Calamares
# Hlavná stránka (telo)
offline-error = Nedá sa spustiť online inštalácia! Žiadne internetové pripojenie
unsupported-hw-warning = Pokúšate sa nainštalovať na hardvér, ktorý nie je podporovaný aktuálnou verziou ISO, vaša inštalácia nebude mať nárok na podporu
tweaksbrowser-label = Aplikácie/Vylepšenia
appbrowser-label = Inštalovať aplikácie
launch-start-label = Spustiť pri štarte
Expand Down
1 change: 1 addition & 0 deletions i18n/tr/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ calamares-install-type = Calamares kurulum tipi
# Main Page (body)
offline-error = Çevrimiçi kurulum başlatılamadı! Bir internet bağlantısı bulunmuyor.
unsupported-hw-warning = Mevcut ISO tarafından desteklenmeyen bir donanıma kurulum yapmaya çalışıyorsunuz, kurulumunuz destek için uygun olmayacaktır
tweaksbrowser-label = Uygulamalar/İyileştirmeler
appbrowser-label = Uygulama kur
launch-start-label = Başlangıçta aç
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ section-project = 项目
# Main Page (body)
offline-error = 无法启动在线安装!无网络连接
unsupported-hw-warning = 如果您试图在当前 ISO 不支持的硬件上进行安装,您的安装将无法获得支持
tweaksbrowser-label = 应用/调整
appbrowser-label = 安装应用
launch-start-label = 启动时运行
Expand Down
38 changes: 33 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ static G_SAVE_JSON: Lazy<Mutex<serde_json::Value>> = Lazy::new(|| {
});
static mut G_HELLO_WINDOW: Option<Arc<HelloWindow>> = None;

fn version_compat_check(message: String) {
let version_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());

if version_tag == "handheld" {
let profiles_path =
format!("{}/handhelds/profiles.toml", chwd::consts::CHWD_PCI_CONFIG_DIR);

let handheld_profiles =
chwd::profile::parse_profiles(&profiles_path).expect("Failed to parse profiles");
let handheld_profile_names: Vec<_> =
handheld_profiles.iter().map(|profile| &profile.name).collect();

let available_profiles = chwd::profile::get_available_profiles(false);

if available_profiles.iter().any(|profile| handheld_profile_names.contains(&&profile.name))
{
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
show_simple_dialog(
window_ref,
gtk::MessageType::Warning,
&fl!("unsupported-hw-warning"),
message.clone(),
);
}
}
}

fn quick_message(message: String) {
// Spawn child process in separate thread.
std::thread::spawn(move || {
Expand Down Expand Up @@ -482,21 +509,22 @@ fn on_languages_changed(param: &[glib::Value]) -> Option<glib::Value> {

fn on_action_clicked(param: &[glib::Value]) -> Option<glib::Value> {
let widget = param[0].get::<gtk::Widget>().unwrap();
return match widget.widget_name().as_str() {
match widget.widget_name().as_str() {
"install" => {
version_compat_check(fl!("calamares-install-type"));
quick_message(fl!("calamares-install-type"));
None
},
}
"autostart" => {
let action = widget.downcast::<gtk::Switch>().unwrap();
set_autostart(action.is_active());
None
},
}
_ => {
show_about_dialog();
None
},
};
}
}
}

fn on_btn_clicked(param: &[glib::Value]) -> Option<glib::Value> {
Expand Down

0 comments on commit 2f25c12

Please sign in to comment.