C.W.K.
Stream
Lesson 05 of 07 · published

트레이, 메뉴, 알림

~13 min · tauri, tray, menu, notification

Level 0웹 관광객
0 XP0/56 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete
"이게 웹뷰로 굴러가는 앱을 진짜 데스크톱에 속한 것처럼 느끼게 하는 손길이야."

시스템 트레이: 메뉴바에 살기

트레이 아이콘(macOS 메뉴바 항목, Windows/Linux 시스템 트레이)은 앱이 백그라운드에 조용히 살면서 한 클릭 거리에 머물게 해. Rust에서 TrayIconBuilder로 만들고, 메뉴를 붙이고, 클릭을 처리해 — 창 보이기/숨기기, 빠른 동작, 종료. 유틸리티랑 항상 쓸 수 있는 도우미한텐, 트레이가 '네가 여는 앱'이랑 '그냥 거기 있는 앱'의 차이야.

메뉴: 네이티브 메뉴바랑 컨텍스트 메뉴

Tauri 메뉴 API(Menu, Submenu, MenuItem, 빌더 변형)는 진짜 네이티브 메뉴를 구성해 — macOS 화면 상단 앱 메뉴바, 컨텍스트 메뉴, 트레이 드롭다운. 메뉴 항목이 Rust에서 처리하는 이벤트를 내. 네이티브 메뉴가 맞게 느껴지는 건 그게 OS의 메뉴 이지 메뉴인 척하는 HTML이 아니라서야.

알림: 사용자 어깨 두드리기

notification 플러그인이 진짜 OS 알림을 보내. 브라우저 API처럼 permission 게이트야: isPermissionGranted 확인, 필요하면 requestPermission 호출, 그다음 sendNotification. 진짜 알릴 가치 있는 일에 써(긴 작업 끝남, 메시지 도착) — 수다 말고. OS 알림 센터는 공유 부동산이야. 시끄러운 앱은 음소거당해.

Code

메뉴 달린 트레이 아이콘 (Rust)·rust
use tauri::tray::TrayIconBuilder;
use tauri::menu::{Menu, MenuItem};

// setup()에서: 작은 메뉴 달린 트레이 아이콘.
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let show = MenuItem::with_id(app, "show", "Show Window", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show, &quit])?;

TrayIconBuilder::new()
    .icon(app.default_window_icon().unwrap().clone())
    .menu(&menu)
    .on_menu_event(|app, event| match event.id.as_ref() {
        "quit" => app.exit(0),
        "show" => { if let Some(w) = app.get_webview_window("main") { let _ = w.show(); } }
        _ => {}
    })
    .build(app)?;
permission 게이트 OS 알림 (프론트엔드)·tsx
import {
  isPermissionGranted, requestPermission, sendNotification,
} from "@tauri-apps/plugin-notification";

let granted = await isPermissionGranted();
if (!granted) granted = (await requestPermission()) === "granted";
if (granted) {
  sendNotification({ title: "Export complete", body: "Your file is ready." });
}

External links

Exercise

두 항목 메뉴('Show Window'랑 'Quit') 달린 시스템 트레이 아이콘을 더해. Show는 메인 창을 앞으로, Quit은 앱을 종료하게 해. 보너스: (가짜) 긴 작업이 끝나면 OS 알림을 보내, permission 확인 뒤에 게이트해서. 데스크톱 앱을 감싼 웹 페이지랑 가르는 네이티브 손길을 더한 거야.
Hint
setup()에서 TrayIconBuilder, on_menu_event를 id로 처리. 알림: isPermissionGranted → requestPermission → sendNotification. notification capability permission 기억해(세 표면 규칙).

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.