@@ -16,7 +16,7 @@ use heck::ToKebabCase;
1616use schemars:: JsonSchema ;
1717use serde:: {
1818 de:: { Deserializer , Error as DeError , Visitor } ,
19- Deserialize , Serialize ,
19+ Deserialize , Serialize , Serializer ,
2020} ;
2121use serde_json:: Value as JsonValue ;
2222use serde_with:: skip_serializing_none;
@@ -1872,6 +1872,89 @@ impl<'de> Deserialize<'de> for UpdaterEndpoint {
18721872 }
18731873}
18741874
1875+ /// Install modes for the Windows update.
1876+ #[ derive( Debug , PartialEq , Clone ) ]
1877+ #[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
1878+ #[ cfg_attr( feature = "schema" , schemars( rename_all = "camelCase" ) ) ]
1879+ pub enum WindowsUpdateInstallMode {
1880+ /// Specifies there's a basic UI during the installation process, including a final dialog box at the end.
1881+ BasicUi ,
1882+ /// The quiet mode means there's no user interaction required.
1883+ /// Requires admin privileges if the installer does.
1884+ Quiet ,
1885+ /// Specifies unattended mode, which means the installation only shows a progress bar.
1886+ Passive ,
1887+ }
1888+
1889+ impl WindowsUpdateInstallMode {
1890+ /// Returns the associated `msiexec.exe` arguments.
1891+ pub fn msiexec_args ( & self ) -> & ' static [ & ' static str ] {
1892+ match self {
1893+ Self :: BasicUi => & [ "/qb+" ] ,
1894+ Self :: Quiet => & [ "/quiet" ] ,
1895+ Self :: Passive => & [ "/passive" ] ,
1896+ }
1897+ }
1898+ }
1899+
1900+ impl Display for WindowsUpdateInstallMode {
1901+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1902+ write ! (
1903+ f,
1904+ "{}" ,
1905+ match self {
1906+ Self :: BasicUi => "basicUI" ,
1907+ Self :: Quiet => "quiet" ,
1908+ Self :: Passive => "passive" ,
1909+ }
1910+ )
1911+ }
1912+ }
1913+
1914+ impl Default for WindowsUpdateInstallMode {
1915+ fn default ( ) -> Self {
1916+ Self :: Passive
1917+ }
1918+ }
1919+
1920+ impl Serialize for WindowsUpdateInstallMode {
1921+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
1922+ where
1923+ S : Serializer ,
1924+ {
1925+ serializer. serialize_str ( self . to_string ( ) . as_ref ( ) )
1926+ }
1927+ }
1928+
1929+ impl < ' de > Deserialize < ' de > for WindowsUpdateInstallMode {
1930+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
1931+ where
1932+ D : Deserializer < ' de > ,
1933+ {
1934+ let s = String :: deserialize ( deserializer) ?;
1935+ match s. to_lowercase ( ) . as_str ( ) {
1936+ "basicui" => Ok ( Self :: BasicUi ) ,
1937+ "quiet" => Ok ( Self :: Quiet ) ,
1938+ "passive" => Ok ( Self :: Passive ) ,
1939+ _ => Err ( DeError :: custom ( format ! (
1940+ "unknown update install mode '{}'" ,
1941+ s
1942+ ) ) ) ,
1943+ }
1944+ }
1945+ }
1946+
1947+ /// The updater configuration for Windows.
1948+ #[ skip_serializing_none]
1949+ #[ derive( Debug , Default , PartialEq , Clone , Serialize , Deserialize ) ]
1950+ #[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
1951+ #[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
1952+ pub struct UpdaterWindowsConfig {
1953+ /// The installation mode for the update on Windows. Defaults to `passive`.
1954+ #[ serde( default ) ]
1955+ pub install_mode : WindowsUpdateInstallMode ,
1956+ }
1957+
18751958/// The Updater configuration object.
18761959#[ skip_serializing_none]
18771960#[ derive( Debug , PartialEq , Clone , Serialize ) ]
@@ -1900,6 +1983,9 @@ pub struct UpdaterConfig {
19001983 /// Signature public key.
19011984 #[ serde( default ) ] // use default just so the schema doesn't flag it as required
19021985 pub pubkey : String ,
1986+ /// The Windows configuration for the updater.
1987+ #[ serde( default ) ]
1988+ pub windows : UpdaterWindowsConfig ,
19031989}
19041990
19051991impl < ' de > Deserialize < ' de > for UpdaterConfig {
@@ -1915,6 +2001,8 @@ impl<'de> Deserialize<'de> for UpdaterConfig {
19152001 dialog : bool ,
19162002 endpoints : Option < Vec < UpdaterEndpoint > > ,
19172003 pubkey : Option < String > ,
2004+ #[ serde( default ) ]
2005+ windows : UpdaterWindowsConfig ,
19182006 }
19192007
19202008 let config = InnerUpdaterConfig :: deserialize ( deserializer) ?;
@@ -1930,6 +2018,7 @@ impl<'de> Deserialize<'de> for UpdaterConfig {
19302018 dialog : config. dialog ,
19312019 endpoints : config. endpoints ,
19322020 pubkey : config. pubkey . unwrap_or_default ( ) ,
2021+ windows : config. windows ,
19332022 } )
19342023 }
19352024}
@@ -1941,6 +2030,7 @@ impl Default for UpdaterConfig {
19412030 dialog : default_dialog ( ) ,
19422031 endpoints : None ,
19432032 pubkey : "" . into ( ) ,
2033+ windows : Default :: default ( ) ,
19442034 }
19452035 }
19462036}
@@ -2611,6 +2701,25 @@ mod build {
26112701 }
26122702 }
26132703
2704+ impl ToTokens for WindowsUpdateInstallMode {
2705+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
2706+ let prefix = quote ! { :: tauri:: utils:: config:: WindowsUpdateInstallMode } ;
2707+
2708+ tokens. append_all ( match self {
2709+ Self :: BasicUi => quote ! { #prefix:: BasicUi } ,
2710+ Self :: Quiet => quote ! { #prefix:: Quiet } ,
2711+ Self :: Passive => quote ! { #prefix:: Passive } ,
2712+ } )
2713+ }
2714+ }
2715+
2716+ impl ToTokens for UpdaterWindowsConfig {
2717+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
2718+ let install_mode = & self . install_mode ;
2719+ literal_struct ! ( tokens, UpdaterWindowsConfig , install_mode) ;
2720+ }
2721+ }
2722+
26142723 impl ToTokens for UpdaterConfig {
26152724 fn to_tokens ( & self , tokens : & mut TokenStream ) {
26162725 let active = self . active ;
@@ -2628,8 +2737,17 @@ mod build {
26282737 } )
26292738 . as_ref ( ) ,
26302739 ) ;
2740+ let windows = & self . windows ;
26312741
2632- literal_struct ! ( tokens, UpdaterConfig , active, dialog, pubkey, endpoints) ;
2742+ literal_struct ! (
2743+ tokens,
2744+ UpdaterConfig ,
2745+ active,
2746+ dialog,
2747+ pubkey,
2748+ endpoints,
2749+ windows
2750+ ) ;
26332751 }
26342752 }
26352753
@@ -2948,6 +3066,7 @@ mod test {
29483066 dialog : true ,
29493067 pubkey : "" . into ( ) ,
29503068 endpoints : None ,
3069+ windows : Default :: default ( ) ,
29513070 } ,
29523071 security : SecurityConfig {
29533072 csp : None ,
0 commit comments