Skip to content

Commit bf22d84

Browse files
wilcorreaCopilot
andauthored
feat: internacionalizar menu nativo macOS (#30)
* feat: internacionalizar menu nativo macOS Replica o padrão já estabelecido pelo tray menu: - Extrai lógica de construção do menu para rebuild_macos_menu() - Adiciona command update_menu_labels (macOS only) - Adiciona seção 'menu' em pt-BR.json e en.json - Estende tray-sync.ts com updateMenuLabels() - Chama updateMenuLabels no init e na troca de idioma Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * style: alterar cor da fase 'done' para purple e exibir ID da sessão - Troca bg-emerald-500 por bg-purple-500 no indicador de fase done - Adiciona botão com prefixo do ID da sessão no cabeçalho Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: use pt-BR defaults for initial macOS menu labels Initialize rebuild_macos_menu with Portuguese (pt-BR) strings so the native menu matches the default locale before the frontend sync runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: register update_menu_labels on all platforms as no-op on non-macOS Remove the #[cfg(target_os = "macos")] guard from the command definition and its invoke_handler registration so the frontend can safely call update_menu_labels on any platform. On non-macOS the command returns Ok(()) immediately, preventing silent invoke failures on Linux and Windows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f692d80 commit bf22d84

8 files changed

Lines changed: 124 additions & 9 deletions

File tree

apps/tauri/src-tauri/src/lib.rs

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,41 @@ fn dismiss_cli_prompt(app: tauri::AppHandle) {
236236
}
237237
}
238238

239+
#[tauri::command]
240+
fn get_cli_suggested_paths() -> Vec<String> {
241+
#[cfg(target_os = "macos")]
242+
{
243+
cli_installer::get_suggested_paths()
244+
}
245+
#[cfg(not(target_os = "macos"))]
246+
{
247+
vec![]
248+
}
249+
}
250+
251+
#[tauri::command]
252+
fn install_cli_to_path(path: String) -> InstallResult {
253+
#[cfg(target_os = "macos")]
254+
{
255+
let dest_dir = std::path::Path::new(&path);
256+
let r = cli_installer::install_to_dir(dest_dir);
257+
InstallResult {
258+
success: r.success,
259+
path: r.path,
260+
error: r.error,
261+
}
262+
}
263+
#[cfg(not(target_os = "macos"))]
264+
{
265+
let _ = path;
266+
InstallResult {
267+
success: false,
268+
path: String::new(),
269+
error: "CLI installer is only supported on macOS".to_string(),
270+
}
271+
}
272+
}
273+
239274
#[tauri::command]
240275
fn load_comments(
241276
markdown_path: String,
@@ -332,6 +367,26 @@ fn show_settings_window(app: tauri::AppHandle) -> Result<(), String> {
332367
Ok(())
333368
}
334369

370+
#[tauri::command]
371+
fn update_menu_labels(
372+
app: tauri::AppHandle,
373+
settings: String,
374+
install_cli: String,
375+
file_menu: String,
376+
open_file: String,
377+
) -> Result<(), String> {
378+
#[cfg(target_os = "macos")]
379+
{
380+
return rebuild_macos_menu(&app, &settings, &install_cli, &file_menu, &open_file)
381+
.map_err(|e| e.to_string());
382+
}
383+
#[cfg(not(target_os = "macos"))]
384+
{
385+
let _ = (app, settings, install_cli, file_menu, open_file);
386+
Ok(())
387+
}
388+
}
389+
335390
#[tauri::command]
336391
fn update_tray_labels(
337392
app: tauri::AppHandle,
@@ -369,15 +424,21 @@ pub fn handle_recording_toggle(handle: &tauri::AppHandle) {
369424
}
370425

371426
#[cfg(target_os = "macos")]
372-
fn setup_macos_menu(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
427+
fn rebuild_macos_menu(
428+
app: &tauri::AppHandle,
429+
settings: &str,
430+
install_cli: &str,
431+
file_menu: &str,
432+
open_file: &str,
433+
) -> Result<(), Box<dyn std::error::Error>> {
373434
use tauri::menu::{MenuBuilder, MenuItemBuilder, SubmenuBuilder};
374435

375-
let settings_item = MenuItemBuilder::with_id("settings", "Settings\u{2026}")
436+
let settings_item = MenuItemBuilder::with_id("settings", settings)
376437
.accelerator("CmdOrCtrl+,")
377438
.build(app)?;
378-
let install_cli_item = MenuItemBuilder::with_id("install-cli", "Install Command Line Tool\u{2026}")
439+
let install_cli_item = MenuItemBuilder::with_id("install-cli", install_cli)
379440
.build(app)?;
380-
let open_file_item = MenuItemBuilder::with_id("open-file", "Open\u{2026}")
441+
let open_file_item = MenuItemBuilder::with_id("open-file", open_file)
381442
.accelerator("CmdOrCtrl+O")
382443
.build(app)?;
383444

@@ -396,7 +457,7 @@ fn setup_macos_menu(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>>
396457
.quit()
397458
.build()?;
398459

399-
let file_submenu = SubmenuBuilder::new(app, "File")
460+
let file_submenu = SubmenuBuilder::new(app, file_menu)
400461
.item(&open_file_item)
401462
.build()?;
402463

@@ -425,6 +486,18 @@ fn setup_macos_menu(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>>
425486
.build()?;
426487

427488
app.set_menu(menu)?;
489+
Ok(())
490+
}
491+
492+
#[cfg(target_os = "macos")]
493+
fn setup_macos_menu(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
494+
rebuild_macos_menu(
495+
app.handle(),
496+
"Configurações\u{2026}",
497+
"Instalar Ferramenta de Linha de Comando\u{2026}",
498+
"Arquivo",
499+
"Abrir\u{2026}",
500+
)?;
428501

429502
let app_handle = app.handle().clone();
430503
app.on_menu_event(move |_app, event| {
@@ -641,6 +714,8 @@ pub fn run() {
641714
check_cli_status,
642715
install_cli,
643716
dismiss_cli_prompt,
717+
get_cli_suggested_paths,
718+
install_cli_to_path,
644719
load_comments,
645720
save_comments,
646721
count_unresolved_comments,
@@ -654,6 +729,7 @@ pub fn run() {
654729
hide_whisper_window,
655730
show_settings_window,
656731
update_tray_labels,
732+
update_menu_labels,
657733
write_clipboard,
658734
whisper::commands::is_currently_recording,
659735
whisper::commands::start_recording,

apps/tauri/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MarkdownViewer } from "@/components/MarkdownViewer";
77
import { DirectoryWorkspace } from "@/components/DirectoryWorkspace";
88
import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts";
99
import { initHomeDir } from "@/lib/format-path";
10-
import { updateTrayLabels } from "@/lib/tray-sync";
10+
import { updateTrayLabels, updateMenuLabels } from "@/lib/tray-sync";
1111
import { ErrorBoundary } from "@/components/ErrorBoundary";
1212
import { TooltipProvider } from "@/components/ui/tooltip";
1313
import { Toaster } from "@/components/ui/sonner";
@@ -206,6 +206,7 @@ function App() {
206206
useEffect(() => {
207207
initHomeDir().catch(console.error);
208208
updateTrayLabels(localStorage.getItem("arandu-language") || "pt-BR");
209+
updateMenuLabels(localStorage.getItem("arandu-language") || "pt-BR");
209210

210211
const showWindow = async () => {
211212
const appWindow = getCurrentWindow();

apps/tauri/src/components/ActiveSessionView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const PHASE_COLORS: Record<PlanPhase, string> = {
4040
planning: "bg-yellow-500",
4141
reviewing: "bg-blue-500",
4242
executing: "bg-green-500",
43-
done: "bg-emerald-500",
43+
done: "bg-purple-500",
4444
};
4545

4646
const PHASE_KEYS: Record<PlanPhase, string> = {
@@ -186,6 +186,13 @@ export function ActiveSessionView({
186186
<div className="h-10 border-b border-border px-3 flex items-center justify-between shrink-0 bg-card">
187187
<div className="flex items-center gap-2 min-w-0">
188188
<span className="text-sm font-semibold truncate mx-2">{session.name}</span>
189+
<button
190+
className="text-xs text-muted-foreground/50 hover:text-muted-foreground font-mono flex-shrink-0 transition-colors"
191+
title={session.id}
192+
onClick={() => navigator.clipboard.writeText(session.id)}
193+
>
194+
#{session.id.slice(0, 8)}
195+
</button>
189196
<DropdownMenu>
190197
<DropdownMenuTrigger asChild>
191198
<button className="flex items-center gap-1.5 px-2 py-0.5 rounded hover:bg-muted transition-colors flex-shrink-0">

apps/tauri/src/components/SessionCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const PHASE_COLORS: Record<PlanPhase, string> = {
2828
planning: "bg-yellow-500",
2929
reviewing: "bg-blue-500",
3030
executing: "bg-green-500",
31-
done: "bg-emerald-500",
31+
done: "bg-purple-500",
3232
};
3333

3434
const PHASE_KEYS: Record<PlanPhase, string> = {

apps/tauri/src/components/settings/GeneralSettings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { useTheme } from "next-themes";
1111
import { useTranslation } from "react-i18next";
1212
import { Monitor, Moon, Sun } from "lucide-react";
13-
import { updateTrayLabels } from "@/lib/tray-sync";
13+
import { updateTrayLabels, updateMenuLabels } from "@/lib/tray-sync";
1414
import { useState } from "react";
1515

1616
const COPILOT_PATH_KEY = "arandu-copilot-path";
@@ -107,6 +107,7 @@ export function GeneralSettings() {
107107
<Select value={i18n.language} onValueChange={(lng) => {
108108
i18n.changeLanguage(lng);
109109
updateTrayLabels(lng);
110+
updateMenuLabels(lng);
110111
}}>
111112
<SelectTrigger className="w-48">
112113
<SelectValue />

apps/tauri/src/lib/tray-sync.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ export function updateTrayLabels(lng: string) {
1717
quit: t.tray.quit,
1818
}).catch(console.error);
1919
}
20+
21+
export function updateMenuLabels(lng: string) {
22+
const t = translations[lng] ?? translations["pt-BR"];
23+
invoke("update_menu_labels", {
24+
settings: t.menu.arandu.settings,
25+
installCli: t.menu.arandu.installCli,
26+
fileMenu: t.menu.file.title,
27+
openFile: t.menu.file.open,
28+
}).catch(console.error);
29+
}

apps/tauri/src/locales/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@
143143
"settings": "Settings\u2026",
144144
"quit": "Quit"
145145
},
146+
"menu": {
147+
"arandu": {
148+
"settings": "Settings\u2026",
149+
"installCli": "Install Command Line Tool\u2026"
150+
},
151+
"file": {
152+
"title": "File",
153+
"open": "Open\u2026"
154+
}
155+
},
146156
"plan": {
147157
"emptyState": "Plan will appear here once the session starts",
148158
"openPlan": "Open Plan",

apps/tauri/src/locales/pt-BR.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@
143143
"settings": "Configurações\u2026",
144144
"quit": "Sair"
145145
},
146+
"menu": {
147+
"arandu": {
148+
"settings": "Configurações\u2026",
149+
"installCli": "Instalar Ferramenta de Linha de Comando\u2026"
150+
},
151+
"file": {
152+
"title": "Arquivo",
153+
"open": "Abrir\u2026"
154+
}
155+
},
146156
"plan": {
147157
"emptyState": "O plano aparecerá aqui quando a sessão iniciar",
148158
"openPlan": "Abrir Plano",

0 commit comments

Comments
 (0)