Skip to content
Open
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
16 changes: 16 additions & 0 deletions settings-ui/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
"Pasta Downloads do sistema": "System Downloads folder",
"Escolher pasta…": "Choose folder…",
"Restaurar Downloads": "Reset to Downloads",
"Som do aviso": "Alert sound",
"Som padrão do Windows": "Windows' default sound",
"Escolher som…": "Choose sound…",
"Esse arquivo de som não pode ser usado.": "That sound file cannot be used.",
"Tamanho da interface": "Interface size",
"Tema": "Theme",
"O WhatsApp segue esta opção quando o tema dele está em \"Padrão do sistema\".": "WhatsApp follows this when its own theme is set to \"System default\".",
Expand Down Expand Up @@ -482,6 +486,10 @@
"Pasta Downloads do sistema": "Carpeta Descargas del sistema",
"Escolher pasta…": "Elegir carpeta…",
"Restaurar Downloads": "Restaurar Descargas",
"Som do aviso": "Sonido del aviso",
"Som padrão do Windows": "Sonido predeterminado de Windows",
"Escolher som…": "Elegir sonido…",
"Esse arquivo de som não pode ser usado.": "Ese archivo de sonido no se puede usar.",
"Tamanho da interface": "Tamaño de la interfaz",
"Barra de título": "Barra de título",
"Gerenciadores de janelas lado a lado, como o Hyprland, não usam barra de título.": "Los gestores de ventanas en mosaico, como Hyprland, no usan barra de título.",
Expand Down Expand Up @@ -791,6 +799,10 @@
"Pasta Downloads do sistema": "مجلد التنزيلات في النظام",
"Escolher pasta…": "اختر مجلدًا…",
"Restaurar Downloads": "العودة إلى التنزيلات",
"Som do aviso": "صوت التنبيه",
"Som padrão do Windows": "صوت Windows الافتراضي",
"Escolher som…": "اختر صوتًا…",
"Esse arquivo de som não pode ser usado.": "لا يمكن استخدام ملف الصوت هذا.",
"Tamanho da interface": "حجم الواجهة",
"Tema": "السمة",
"O WhatsApp segue esta opção quando o tema dele está em \"Padrão do sistema\".": "يتبع WhatsApp هذا الإعداد عندما تكون سمته على «افتراضي النظام».",
Expand Down Expand Up @@ -1097,6 +1109,10 @@
"Pasta Downloads do sistema": "Folder Unduhan sistem",
"Escolher pasta…": "Pilih folder…",
"Restaurar Downloads": "Kembalikan ke Unduhan",
"Som do aviso": "Suara pemberitahuan",
"Som padrão do Windows": "Suara bawaan Windows",
"Escolher som…": "Pilih suara…",
"Esse arquivo de som não pode ser usado.": "File suara itu tidak dapat digunakan.",
"Tamanho da interface": "Ukuran antarmuka",
"Tema": "Tema",
"O WhatsApp segue esta opção quando o tema dele está em \"Padrão do sistema\".": "WhatsApp mengikuti ini saat temanya diatur ke \"Default sistem\".",
Expand Down
8 changes: 8 additions & 0 deletions settings-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ <h2 class="group-title">Contas</h2>
</section>
<section class="group" id="sec-notificacoes"><h2 class="group-title">Notificações</h2><div class="boxed-list">
<label class="row"><span class="row-text"><span class="row-title">Receber notificações</span><span class="row-subtitle">Ativa os avisos de mensagens do whatRust.</span></span><input type="checkbox" class="switch" id="notifications"></label><label class="row"><span class="row-text"><span class="row-title">Som de notificação</span><span class="row-subtitle">Silencia os avisos sonoros de mensagens do WhatsApp. O toque de chamadas continua.</span></span><input type="checkbox" class="switch" id="notification_sound"></label>
<div class="row" id="notification_sound_file_row" hidden>
<span class="row-text"><span class="row-title">Som do aviso</span>
<span class="row-subtitle" id="notification_sound_file_subtitle">Som padrão do Windows</span></span>
<div class="hotkey-row">
<button type="button" id="choose_notification_sound" class="secondary">Escolher som…</button>
<button type="button" id="reset_notification_sound" class="secondary">Restaurar padrão</button>
</div>
</div>
<label class="row">
<span class="row-text">
<span class="row-title">Silenciar som interno do WhatsApp Web</span>
Expand Down
37 changes: 37 additions & 0 deletions settings-ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ function showDownloadDir() {
document.getElementById("reset_download_dir").disabled = !downloadDir;
}

// The chosen notification sound file (null = Windows' own sound). Windows only.
let notificationSoundFile = null;

function showNotificationSound() {
const sub = document.getElementById("notification_sound_file_subtitle");
// The file's name: the whole path is in the tooltip.
sub.textContent = notificationSoundFile ? notificationSoundFile.split(/[\\/]/).pop() : "Som padrão do Windows";
sub.title = notificationSoundFile || "";
document.getElementById("reset_notification_sound").disabled = !notificationSoundFile;
}

async function chooseNotificationSound() {
try {
const file = await invoke("pick_notification_sound");
if (!file) return;
const previous = notificationSoundFile;
notificationSoundFile = file;
showNotificationSound();
if (!(await save())) {
notificationSoundFile = previous;
showNotificationSound();
}
} catch (e) { flash(String(e)); }
}

async function resetNotificationSound() {
notificationSoundFile = null;
showNotificationSound();
await save();
}

function showIcon(custom) {
document.getElementById("icon_subtitle").textContent = custom ? "Personalizado" : "Padrão";
document.getElementById("reset_icon").disabled = !custom;
Expand Down Expand Up @@ -191,6 +222,9 @@ async function load() {
syncMenuBarIconRow();
downloadDir = s.download_dir || null;
showDownloadDir();
document.getElementById("notification_sound_file_row").hidden = s.platform !== "windows";
notificationSoundFile = s.notification_sound_file || null;
showNotificationSound();
showIcon(!!s.custom_icon);
loadProxy(s);
}
Expand Down Expand Up @@ -250,6 +284,7 @@ async function save() {
s.rendering = document.getElementById("rendering").value || "auto";
s.language = document.getElementById("language").value;
s.download_dir = downloadDir;
s.notification_sound_file = notificationSoundFile;
s.sleep_idle_hours = parseInt(document.getElementById("sleep_idle_hours").value, 10) || 0;
s.quiet_start = document.getElementById("quiet_start").value || "22:00";
s.quiet_end = document.getElementById("quiet_end").value || "08:00";
Expand Down Expand Up @@ -482,6 +517,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("record_blur_hotkey").addEventListener("click", () => toggleRecording("blur_hotkey", "record_blur_hotkey"));
document.getElementById("choose_download_dir").addEventListener("click", chooseDownloadDir);
document.getElementById("reset_download_dir").addEventListener("click", resetDownloadDir);
document.getElementById("choose_notification_sound").addEventListener("click", chooseNotificationSound);
document.getElementById("reset_notification_sound").addEventListener("click", resetNotificationSound);
document.getElementById("choose_icon").addEventListener("click", chooseIcon);
document.getElementById("reset_icon").addEventListener("click", resetIcon);
// Zoom saves on change rather than on Save: picking a size you cannot see the
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ windows = { version = "0.62", features = [
"Win32_Globalization", # GetUserDefaultLocaleName: default UI language
"Win32_UI_Input_KeyboardAndMouse", # GetKeyState: Ctrl+Shift+P privacy panel (issue #80)
"Win32_Graphics_Dwm", # DwmSetWindowAttribute: per-account window border colour (accent.rs)
"Media_Core", # MediaSource: a notification sound of the user's own (sound.rs)
"Media_Playback", # MediaPlayer, same
] }
windows-core = "0.62"
# Since windows-rs 0.61 IAsyncOperation lives in the windows-future crate
Expand Down
1 change: 1 addition & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn main() {
"import_backup",
"open_settings",
"pick_download_dir",
"pick_notification_sound",
"choose_app_icon",
"reset_app_icon",
"set_account_photo",
Expand Down
1 change: 1 addition & 0 deletions src-tauri/capabilities/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"allow-get-settings",
"allow-set-settings",
"allow-pick-download-dir",
"allow-pick-notification-sound",
"allow-choose-app-icon",
"allow-reset-app-icon",
"allow-set-account-photo",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/permissions/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ commands.allow = ["notify", "notification_icon", "set_unread", "dlog", "switcher
identifier = "allow-settings-commands"
description = "Manage settings and accounts from the bundled settings window."
commands.allow = [
"get_settings", "set_settings", "open_settings", "pick_download_dir", "choose_app_icon",
"get_settings", "set_settings", "open_settings", "pick_download_dir", "pick_notification_sound", "choose_app_icon",
"reset_app_icon", "set_account_photo", "remove_account_photo", "open_contributor", "list_accounts",
"add_account", "remove_account", "rename_account", "open_account", "set_default_account",
"get_lock_status", "set_app_lock_password", "change_app_lock_password",
Expand Down
46 changes: 46 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ pub fn set_settings(
crate::downloads::validate_dir(std::path::Path::new(dir))?;
}
}
if settings.notification_sound_file != stored.notification_sound_file {
if let Some(file) = &settings.notification_sound_file {
if !crate::sound::usable(std::path::Path::new(file)) {
return Err(tr("Esse arquivo de som não pode ser usado.").into());
}
}
}
// The icon is only switched through choose_app_icon / reset_app_icon.
settings.custom_icon = stored.custom_icon;
crate::proxy::validate(&mut settings)?;
Expand Down Expand Up @@ -330,6 +337,7 @@ fn merge_backup(
// Machine-specific: keep this computer's icon and download folder.
settings.custom_icon = stored.custom_icon;
settings.download_dir = stored.download_dir.clone();
settings.notification_sound_file = stored.notification_sound_file.clone();
let mut list = backup.accounts;
list.sort_by_key(|a| a.order);
let mut order: Vec<String> = Vec::new();
Expand Down Expand Up @@ -511,6 +519,44 @@ pub async fn pick_download_dir(
Ok(Some(path.to_string_lossy().into_owned()))
}

/// Ask for a notification sound file (Windows). Returns the chosen path, or
/// `None` if cancelled, and plays it once so the choice can be heard. The UI
/// saves it with the other settings.
#[tauri::command]
pub async fn pick_notification_sound(
window: tauri::Webview,
app: tauri::AppHandle,
) -> Result<Option<String>, String> {
if is_remote(&window) {
return Err("forbidden".into());
}
lock::require_unlocked(&app)?;
use tauri_plugin_dialog::DialogExt;
let mut dialog = app
.dialog()
.file()
.set_title(tr("Som do aviso"))
.add_filter(tr("Áudio"), crate::sound::EXTENSIONS);
let stored = crate::settings::load(&app).notification_sound_file;
if let Some(dir) = stored
.as_deref()
.and_then(|f| std::path::Path::new(f).parent())
.filter(|d| d.is_dir())
{
dialog = dialog.set_directory(dir);
}
let Some(picked) = dialog.set_parent(&window.window()).blocking_pick_file() else {
return Ok(None);
};
let path = picked.into_path().map_err(|e| e.to_string())?;
if !crate::sound::usable(&path) {
return Err(tr("Esse arquivo de som não pode ser usado.").into());
}
let path = path.to_string_lossy().into_owned();
crate::sound::play(&path);
Ok(Some(path))
}

/// Pick a PNG, validate it, keep a copy and use it as the app icon.
/// `false` means the picker was cancelled.
#[tauri::command]
Expand Down
12 changes: 12 additions & 0 deletions src-tauri/src/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ static EN_TABLE: &[(&str, &str)] = &[
("Todos os arquivos", "All files"),
("Salvar arquivo", "Save file"),
("Pasta de downloads", "Download folder"),
("Som do aviso", "Alert sound"),
("Áudio", "Audio"),
("Esse arquivo de som não pode ser usado.", "That sound file cannot be used."),
("Salvar backup do whatRust", "Save whatRust backup"),
("Restaurar backup do whatRust", "Restore whatRust backup"),
("Este arquivo não é um backup do whatRust.", "This file is not a whatRust backup."),
Expand Down Expand Up @@ -376,6 +379,9 @@ static ES_TABLE: &[(&str, &str)] = &[
("Todos os arquivos", "Todos los archivos"),
("Salvar arquivo", "Guardar archivo"),
("Pasta de downloads", "Carpeta de descargas"),
("Som do aviso", "Sonido del aviso"),
("Áudio", "Audio"),
("Esse arquivo de som não pode ser usado.", "Ese archivo de sonido no se puede usar."),
("Salvar backup do whatRust", "Guardar copia de seguridad de whatRust"),
("Restaurar backup do whatRust", "Restaurar copia de seguridad de whatRust"),
("Este arquivo não é um backup do whatRust.", "Este archivo no es una copia de seguridad de whatRust."),
Expand Down Expand Up @@ -518,6 +524,9 @@ static AR_TABLE: &[(&str, &str)] = &[
("Todos os arquivos", "كل الملفات"),
("Salvar arquivo", "حفظ الملف"),
("Pasta de downloads", "مجلد التنزيلات"),
("Som do aviso", "صوت التنبيه"),
("Áudio", "صوت"),
("Esse arquivo de som não pode ser usado.", "لا يمكن استخدام ملف الصوت هذا."),
("Salvar backup do whatRust", "حفظ نسخة whatRust الاحتياطية"),
("Restaurar backup do whatRust", "استعادة نسخة whatRust الاحتياطية"),
("Este arquivo não é um backup do whatRust.", "هذا الملف ليس نسخة احتياطية من whatRust."),
Expand Down Expand Up @@ -660,6 +669,9 @@ static ID_TABLE: &[(&str, &str)] = &[
("Todos os arquivos", "Semua berkas"),
("Salvar arquivo", "Simpan berkas"),
("Pasta de downloads", "Folder unduhan"),
("Som do aviso", "Suara pemberitahuan"),
("Áudio", "Audio"),
("Esse arquivo de som não pode ser usado.", "File suara itu tidak dapat digunakan."),
("Salvar backup do whatRust", "Simpan cadangan whatRust"),
("Restaurar backup do whatRust", "Pulihkan cadangan whatRust"),
("Este arquivo não é um backup do whatRust.", "Berkas ini bukan cadangan whatRust."),
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/ipc_acl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const SETTINGS_COMMANDS: &[&str] = &[
"get_settings",
"set_settings",
"pick_download_dir",
"pick_notification_sound",
"choose_app_icon",
"reset_app_icon",
"set_account_photo",
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod sessions;
mod settings;
#[cfg(all(windows, debug_assertions))]
mod smoke;
mod sound;
mod theme;
mod tray;
mod ui_health;
Expand Down Expand Up @@ -242,6 +243,7 @@ pub fn run() {
commands::set_settings,
commands::open_settings,
commands::pick_download_dir,
commands::pick_notification_sound,
commands::choose_app_icon,
commands::set_account_photo,
commands::remove_account_photo,
Expand Down
8 changes: 7 additions & 1 deletion src-tauri/src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,10 @@ fn windows_toast(
ToastNotificationManager,
},
};
let silent = !crate::settings::load(app).notification_sound;
let settings = crate::settings::load(app);
// A sound file of the user's own is played by whatRust, over a silent toast.
let custom_sound = crate::sound::custom(&settings);
let silent = !settings.notification_sound || custom_sound.is_some();
let app = app.clone();
let title = title.to_string();
let body = body.to_string();
Expand Down Expand Up @@ -872,6 +875,9 @@ fn windows_toast(
0x800704C7u32 as i32,
)));
}
if let Some(file) = &custom_sound {
crate::sound::play(file);
}
Ok(toast)
})();
if let Ok(toast) = &send {
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct Settings {
/// Play WhatsApp's own message alert tones and give the native toasts a
/// sound. Off silences both; calls still ring. On by default.
pub notification_sound: bool,
/// Windows: a sound file (WAV, MP3, M4A, WMA…) played instead of Windows'
/// own toast sound. `None` keeps Windows' sound. Toasts of an unpackaged
/// app cannot point at a file, so the toast goes silent and whatRust plays
/// the file itself (see `sound`). A file that has gone away falls back to
/// Windows' sound.
pub notification_sound_file: Option<String>,
pub notify_when_focused: bool,
pub notify_active_chat: bool,
pub respect_muted: bool,
Expand Down Expand Up @@ -114,6 +120,7 @@ impl Default for Settings {
blur_hotkey: "CmdOrCtrl+Shift+B".to_string(),
notifications: true,
notification_sound: true,
notification_sound_file: None,
notify_when_focused: true,
notify_active_chat: true,
respect_muted: true,
Expand Down Expand Up @@ -296,6 +303,9 @@ impl Settings {
self.zoom = sanitize_zoom(self.zoom);
self.language = crate::i18n::sanitize_code(&self.language);
self.download_dir = self.download_dir.filter(|d| !d.trim().is_empty());
self.notification_sound_file = self
.notification_sound_file
.filter(|f| !f.trim().is_empty());
self.title_bar = crate::decorations::sanitize(&self.title_bar);
self.theme = crate::theme::sanitize(&self.theme);
self.rendering = sanitize_rendering(&self.rendering);
Expand Down
Loading