{await confirm("Are you sure?")||O.preventDefault()}),qe.onFileDropEvent(O=>{D(`File drop: ${JSON.stringify(O.payload)}`)});const l=navigator.userAgent.toLowerCase(),o=l.includes("android")||l.includes("iphone"),u=[{label:"Welcome",component:No,icon:"i-ph-hand-waving"},{label:"Communication",component:Jo,icon:"i-codicon-radio-tower"},!o&&{label:"CLI",component:Bo,icon:"i-codicon-terminal"},!o&&{label:"Dialog",component:ar,icon:"i-codicon-multiple-windows"},{label:"File system",component:fr,icon:"i-codicon-files"},{label:"HTTP",component:kr,icon:"i-ph-globe-hemisphere-west"},!o&&{label:"Notifications",component:Ar,icon:"i-codicon-bell-dot"},!o&&{label:"App",component:ta,icon:"i-codicon-hubot"},!o&&{label:"Window",component:Er,icon:"i-codicon-window"},!o&&{label:"Shortcuts",component:Rr,icon:"i-codicon-record-keys"},{label:"Shell",component:Fr,icon:"i-codicon-terminal-bash"},!o&&{label:"Updater",component:Gr,icon:"i-codicon-cloud-download"},!o&&{label:"Clipboard",component:Kr,icon:"i-codicon-clippy"},{label:"WebRTC",component:$r,icon:"i-ph-broadcast"}];let d=u[0];function c(O){n(1,d=O)}let f;ft(async()=>{const O=Bt();n(2,f=await O.isMaximized()),Kt("tauri://resize",async()=>{n(2,f=await O.isMaximized())})});function g(){Bt().minimize()}async function k(){const O=Bt();await O.isMaximized()?O.unmaximize():O.maximize()}let _=!1;async function y(){_||(_=await Xs("Are you sure that you want to close this window?",{title:"Tauri API"}),_&&Bt().close())}let v;ft(()=>{n(3,v=localStorage&&localStorage.getItem("theme")=="dark"),ys(v)});function b(){n(3,v=!v),ys(v)}let A=Ts([]);ks(e,A,O=>n(6,i=O));function D(O){A.update(X=>[{html:`[${new Date().toLocaleTimeString()}]: `+(typeof O=="string"?O:JSON.stringify(O,null,1))+"
"},...X])}function H(O){A.update(X=>[{html:`[${new Date().toLocaleTimeString()}]: `+O+"
"},...X])}function W(){A.update(()=>[])}let j,E,M;function T(O){M=O.clientY;const X=window.getComputedStyle(j);E=parseInt(X.height,10);const ne=ae=>{const ye=ae.clientY-M,de=E-ye;n(4,j.style.height=`${de{document.removeEventListener("mouseup",ce),document.removeEventListener("mousemove",ne)};document.addEventListener("mouseup",ce),document.addEventListener("mousemove",ne)}let P;ft(async()=>{n(5,P=await Fs()==="win32")});let C=!1,F,U,J=!1,x=0,me=0;const te=(O,X,ne)=>Math.min(Math.max(X,O),ne);ft(()=>{n(18,F=document.querySelector("#sidebar")),U=document.querySelector("#sidebarToggle"),document.addEventListener("click",O=>{U.contains(O.target)?n(0,C=!C):C&&!F.contains(O.target)&&n(0,C=!1)}),document.addEventListener("touchstart",O=>{if(U.contains(O.target))return;const X=O.touches[0].clientX;(0{if(J){const X=O.touches[0].clientX;me=X;const ne=(X-x)/10;F.style.setProperty("--translate-x",`-${te(0,C?0-ne:18.75-ne,18.75)}rem`)}}),document.addEventListener("touchend",()=>{if(J){const O=(me-x)/10;n(0,C=C?O>-(18.75/2):O>18.75/2)}J=!1})});const ie=()=>Fi("https://tauri.app/"),Y=O=>{c(O),n(0,C=!1)};function he(O){$n[O?"unshift":"push"](()=>{j=O,n(4,j)})}return e.$$.update=()=>{if(e.$$.dirty[0]&1){const O=document.querySelector("#sidebar");O&&fa(O,C)}},[C,d,f,v,j,P,i,u,c,g,k,y,b,A,D,H,W,T,F,ie,Y,he]}class ma extends ve{constructor(t){super(),ge(this,t,pa,da,pe,{},null,[-1,-1])}}new ma({target:document.querySelector("#app")});
+ `,b=h(),L=r("br"),D=h(),H=r("div"),W=h(),j=r("br"),E=h(),M=r("div");for(let N=0;N',_e=h(),$=r("div");for(let N=0;N{Xt(V,1)}),si()}Te?(Y=new Te(lt(N)),xn(Y.$$.fragment),Ae(Y.$$.fragment,1),Jt(Y,ie,null)):Y=null}if(se[0]&64){fe=N[6];let V;for(V=0;V{await confirm("Are you sure?")||O.preventDefault()}),qe.onFileDropEvent(O=>{D(`File drop: ${JSON.stringify(O.payload)}`)});const l=navigator.userAgent.toLowerCase(),o=l.includes("android")||l.includes("iphone"),u=[{label:"Welcome",component:No,icon:"i-ph-hand-waving"},{label:"Communication",component:Jo,icon:"i-codicon-radio-tower"},!o&&{label:"CLI",component:Bo,icon:"i-codicon-terminal"},!o&&{label:"Dialog",component:ar,icon:"i-codicon-multiple-windows"},{label:"File system",component:fr,icon:"i-codicon-files"},{label:"HTTP",component:kr,icon:"i-ph-globe-hemisphere-west"},!o&&{label:"Notifications",component:Lr,icon:"i-codicon-bell-dot"},!o&&{label:"App",component:ta,icon:"i-codicon-hubot"},!o&&{label:"Window",component:Er,icon:"i-codicon-window"},!o&&{label:"Shortcuts",component:Rr,icon:"i-codicon-record-keys"},{label:"Shell",component:Fr,icon:"i-codicon-terminal-bash"},!o&&{label:"Updater",component:Gr,icon:"i-codicon-cloud-download"},!o&&{label:"Clipboard",component:Kr,icon:"i-codicon-clippy"},{label:"WebRTC",component:$r,icon:"i-ph-broadcast"}];let d=u[0];function c(O){n(1,d=O)}let f;ft(async()=>{const O=Bt();n(2,f=await O.isMaximized()),Kt("tauri://resize",async()=>{n(2,f=await O.isMaximized())})});function g(){Bt().minimize()}async function k(){const O=Bt();await O.isMaximized()?O.unmaximize():O.maximize()}let _=!1;async function y(){_||(_=await Xs("Are you sure that you want to close this window?",{title:"Tauri API"}),_&&Bt().close())}let v;ft(()=>{n(3,v=localStorage&&localStorage.getItem("theme")=="dark"),ys(v)});function b(){n(3,v=!v),ys(v)}let L=Ts([]);ks(e,L,O=>n(6,i=O));function D(O){L.update(X=>[{html:`[${new Date().toLocaleTimeString()}]: `+(typeof O=="string"?O:JSON.stringify(O,null,1))+"
"},...X])}function H(O){L.update(X=>[{html:`[${new Date().toLocaleTimeString()}]: `+O+"
"},...X])}function W(){L.update(()=>[])}let j,E,M;function T(O){M=O.clientY;const X=window.getComputedStyle(j);E=parseInt(X.height,10);const ne=ae=>{const ye=ae.clientY-M,de=E-ye;n(4,j.style.height=`${de{document.removeEventListener("mouseup",ce),document.removeEventListener("mousemove",ne)};document.addEventListener("mouseup",ce),document.addEventListener("mousemove",ne)}let P;ft(async()=>{n(5,P=await Fs()==="win32")});let C=!1,F,U,J=!1,x=0,me=0;const te=(O,X,ne)=>Math.min(Math.max(X,O),ne);ft(()=>{n(18,F=document.querySelector("#sidebar")),U=document.querySelector("#sidebarToggle"),document.addEventListener("click",O=>{U.contains(O.target)?n(0,C=!C):C&&!F.contains(O.target)&&n(0,C=!1)}),document.addEventListener("touchstart",O=>{if(U.contains(O.target))return;const X=O.touches[0].clientX;(0{if(J){const X=O.touches[0].clientX;me=X;const ne=(X-x)/10;F.style.setProperty("--translate-x",`-${te(0,C?0-ne:18.75-ne,18.75)}rem`)}}),document.addEventListener("touchend",()=>{if(J){const O=(me-x)/10;n(0,C=C?O>-(18.75/2):O>18.75/2)}J=!1})});const ie=()=>Fi("https://tauri.app/"),Y=O=>{c(O),n(0,C=!1)};function he(O){$n[O?"unshift":"push"](()=>{j=O,n(4,j)})}return e.$$.update=()=>{if(e.$$.dirty[0]&1){const O=document.querySelector("#sidebar");O&&fa(O,C)}},[C,d,f,v,j,P,i,u,c,g,k,y,b,L,D,H,W,T,F,ie,Y,he]}class ma extends ve{constructor(t){super(),ge(this,t,pa,da,pe,{},null,[-1,-1])}}new ma({target:document.querySelector("#app")});
diff --git a/examples/api/src-tauri/src/desktop.rs b/examples/api/src-tauri/src/desktop.rs
index adbfce9a1b38..2244c1d1bade 100644
--- a/examples/api/src-tauri/src/desktop.rs
+++ b/examples/api/src-tauri/src/desktop.rs
@@ -1,7 +1,11 @@
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{
- api::dialog::ask, CustomMenuItem, GlobalShortcutManager, Manager, RunEvent, SystemTray,
- SystemTrayEvent, SystemTrayMenu, WindowBuilder, WindowEvent, WindowUrl,
+ api::{
+ dialog::{ask, MessageDialogBuilder, MessageDialogButtons},
+ shell,
+ },
+ CustomMenuItem, GlobalShortcutManager, Manager, RunEvent, SystemTray, SystemTrayEvent,
+ SystemTrayMenu, WindowBuilder, WindowEvent, WindowUrl,
};
pub fn main() {
@@ -71,6 +75,7 @@ fn create_tray(app: &tauri::App) -> tauri::Result<()> {
tray_menu1 = tray_menu1
.add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
+ .add_item(CustomMenuItem::new("about", "About"))
.add_item(CustomMenuItem::new("exit_app", "Quit"))
.add_item(CustomMenuItem::new("destroy", "Destroy"));
@@ -78,6 +83,7 @@ fn create_tray(app: &tauri::App) -> tauri::Result<()> {
.add_item(CustomMenuItem::new("toggle", "Toggle"))
.add_item(CustomMenuItem::new("new", "New window"))
.add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
+ .add_item(CustomMenuItem::new("about", "About"))
.add_item(CustomMenuItem::new("exit_app", "Quit"))
.add_item(CustomMenuItem::new("destroy", "Destroy"));
let is_menu1 = AtomicBool::new(true);
@@ -161,6 +167,20 @@ fn create_tray(app: &tauri::App) -> tauri::Result<()> {
.unwrap();
is_menu1.store(!flag, Ordering::Relaxed);
}
+ "about" => {
+ let window = handle.get_window("main").unwrap();
+ MessageDialogBuilder::new("About app", "Tauri demo app")
+ .parent(&window)
+ .buttons(MessageDialogButtons::OkCancelCustom(
+ "Homepage".into(),
+ "know it".into(),
+ ))
+ .show(move |ok| {
+ if ok {
+ shell::open(&window.shell_scope(), "https://tauri.app/", None).unwrap();
+ }
+ });
+ }
_ => {}
}
}
diff --git a/tooling/api/src/dialog.ts b/tooling/api/src/dialog.ts
index bc22c63ebac1..168990e4be6a 100644
--- a/tooling/api/src/dialog.ts
+++ b/tooling/api/src/dialog.ts
@@ -97,6 +97,19 @@ interface MessageDialogOptions {
title?: string
/** The type of the dialog. Defaults to `info`. */
type?: 'info' | 'warning' | 'error'
+ /** The label of the confirm button. */
+ okLabel?: string
+}
+
+interface ConfirmDialogOptions {
+ /** The title of the dialog. Defaults to the app name. */
+ title?: string
+ /** The type of the dialog. Defaults to `info`. */
+ type?: 'info' | 'warning' | 'error'
+ /** The label of the confirm button. */
+ okLabel?: string
+ /** The label of the cancel button. */
+ cancelLabel?: string
}
/**
@@ -233,7 +246,8 @@ async function message(
cmd: 'messageDialog',
message: message.toString(),
title: opts?.title?.toString(),
- type: opts?.type
+ type: opts?.type,
+ buttonLabel: opts?.okLabel?.toString()
}
})
}
@@ -256,7 +270,7 @@ async function message(
*/
async function ask(
message: string,
- options?: string | MessageDialogOptions
+ options?: string | ConfirmDialogOptions
): Promise {
const opts = typeof options === 'string' ? { title: options } : options
return invokeTauriCommand({
@@ -265,7 +279,11 @@ async function ask(
cmd: 'askDialog',
message: message.toString(),
title: opts?.title?.toString(),
- type: opts?.type
+ type: opts?.type,
+ buttonLabels: [
+ opts?.okLabel?.toString() ?? 'Yes',
+ opts?.cancelLabel?.toString() ?? 'No'
+ ]
}
})
}
@@ -288,7 +306,7 @@ async function ask(
*/
async function confirm(
message: string,
- options?: string | MessageDialogOptions
+ options?: string | ConfirmDialogOptions
): Promise {
const opts = typeof options === 'string' ? { title: options } : options
return invokeTauriCommand({
@@ -297,7 +315,11 @@ async function confirm(
cmd: 'confirmDialog',
message: message.toString(),
title: opts?.title?.toString(),
- type: opts?.type
+ type: opts?.type,
+ buttonLabels: [
+ opts?.okLabel?.toString() ?? 'Ok',
+ opts?.cancelLabel?.toString() ?? 'Cancel'
+ ]
}
})
}
@@ -306,7 +328,8 @@ export type {
DialogFilter,
OpenDialogOptions,
SaveDialogOptions,
- MessageDialogOptions
+ MessageDialogOptions,
+ ConfirmDialogOptions
}
export { open, save, message, ask, confirm }