Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wix): add inline fragments support #32

Merged
merged 1 commit into from
Sep 30, 2023
Merged
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
273 changes: 147 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions crates/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,16 @@
"type": "string"
}
},
"fragments": {
"description": "List of WiX fragments as strings. This is similar to `config.wix.fragments_paths` but is a string so you can define it inline in your config.\n\n```text <?xml version=\"1.0\" encoding=\"utf-8\"?> <Wix xmlns=\"http://schemas.microsoft.com/wix/2006/wi\"> <Fragment> <CustomAction Id=\"OpenNotepad\" Directory=\"INSTALLDIR\" Execute=\"immediate\" ExeCommand=\"cmd.exe /c notepad.exe\" Return=\"check\" /> <InstallExecuteSequence> <Custom Action=\"OpenNotepad\" After=\"InstallInitialize\" /> </InstallExecuteSequence> </Fragment> </Wix> ```",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"componentGroupRefs": {
"description": "The ComponentGroup element ids you want to reference from the fragments.",
"type": [
Expand All @@ -714,6 +724,16 @@
"type": "string"
}
},
"customActionRefs": {
"description": "The CustomAction element ids you want to reference from the fragments.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"featureGroupRefs": {
"description": "The FeatureGroup element ids you want to reference from the fragments.",
"type": [
Expand Down
18 changes: 18 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,30 @@ pub struct WixConfig {
/// A list of paths to .wxs files with WiX fragments to use.
#[serde(alias = "fragment-paths", alias = "fragment_paths")]
pub fragment_paths: Option<Vec<PathBuf>>,
/// List of WiX fragments as strings. This is similar to `config.wix.fragments_paths` but
/// is a string so you can define it inline in your config.
///
/// ```text
/// <?xml version="1.0" encoding="utf-8"?>
/// <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
/// <Fragment>
/// <CustomAction Id="OpenNotepad" Directory="INSTALLDIR" Execute="immediate" ExeCommand="cmd.exe /c notepad.exe" Return="check" />
/// <InstallExecuteSequence>
/// <Custom Action="OpenNotepad" After="InstallInitialize" />
/// </InstallExecuteSequence>
/// </Fragment>
/// </Wix>
/// ```
pub fragments: Option<Vec<String>>,
/// The ComponentGroup element ids you want to reference from the fragments.
#[serde(alias = "component-group-refs", alias = "component_group_refs")]
pub component_group_refs: Option<Vec<String>>,
/// The Component element ids you want to reference from the fragments.
#[serde(alias = "component-refs", alias = "component_refs")]
pub component_refs: Option<Vec<String>>,
/// The CustomAction element ids you want to reference from the fragments.
#[serde(alias = "custom-action-refs", alias = "custom_action_refs")]
pub custom_action_refs: Option<Vec<String>>,
/// The FeatureGroup element ids you want to reference from the fragments.
#[serde(alias = "feature-group-refs", alias = "feature_group_refs")]
pub feature_group_refs: Option<Vec<String>>,
Expand Down
20 changes: 20 additions & 0 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,16 @@
"type": "string"
}
},
"fragments": {
"description": "List of WiX fragments as strings. This is similar to `config.wix.fragments_paths` but is a string so you can define it inline in your config.\n\n```text <?xml version=\"1.0\" encoding=\"utf-8\"?> <Wix xmlns=\"http://schemas.microsoft.com/wix/2006/wi\"> <Fragment> <CustomAction Id=\"OpenNotepad\" Directory=\"INSTALLDIR\" Execute=\"immediate\" ExeCommand=\"cmd.exe /c notepad.exe\" Return=\"check\" /> <InstallExecuteSequence> <Custom Action=\"OpenNotepad\" After=\"InstallInitialize\" /> </InstallExecuteSequence> </Fragment> </Wix> ```",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"componentGroupRefs": {
"description": "The ComponentGroup element ids you want to reference from the fragments.",
"type": [
Expand All @@ -714,6 +724,16 @@
"type": "string"
}
},
"customActionRefs": {
"description": "The CustomAction element ids you want to reference from the fragments.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"featureGroupRefs": {
"description": "The FeatureGroup element ids you want to reference from the fragments.",
"type": [
Expand Down
1 change: 1 addition & 0 deletions crates/packager/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub fn run() {
.with_target(debug)
.with_line_number(tracing)
.with_file(tracing)
.with_max_level(level)
.init();
}

Expand Down
4 changes: 4 additions & 0 deletions crates/packager/src/package/wix/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
{{/each~}}
</Feature>

{{#each custom_action_refs as |id| ~}}
<CustomActionRef Id="{{ id }}"/>
{{/each~}}

{{#if install_webview}}
<!-- WebView2 -->
<Property Id="WVRTINSTALLED">
Expand Down
30 changes: 22 additions & 8 deletions crates/packager/src/package/wix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
codesign,
config::{Config, ConfigExt, ConfigExtInternal},
shell::CommandExt,
util::{self, display_path, download_and_verify, extract_zip, HashAlgorithm},
util::{self, download_and_verify, extract_zip, HashAlgorithm},
};

pub const WIX_URL: &str =
Expand Down Expand Up @@ -355,7 +355,7 @@ fn run_candle(
wxs_file_path.to_string_lossy().to_string(),
format!(
"-dSourceDir={}",
display_path(config.binary_path(main_binary))
util::display_path(config.binary_path(main_binary))
),
];

Expand Down Expand Up @@ -399,7 +399,7 @@ fn run_light(
) -> crate::Result<()> {
let light_exe = wix_path.join("light.exe");

let mut args: Vec<String> = vec!["-o".to_string(), display_path(output_path)];
let mut args: Vec<String> = vec!["-o".to_string(), util::display_path(output_path)];

args.extend(arguments);

Expand Down Expand Up @@ -463,8 +463,6 @@ fn build_wix_app_installer(ctx: &Context, wix_path: &Path) -> crate::Result<Vec<

let mut data = BTreeMap::new();

// TODO: webview2 logic

let app_version = convert_version(&config.version)?;

data.insert("product_name", to_json(&config.product_name));
Expand Down Expand Up @@ -543,14 +541,27 @@ fn build_wix_app_installer(ctx: &Context, wix_path: &Path) -> crate::Result<Vec<
handlebars.register_escape_fn(handlebars::no_escape);
let mut custom_template_path = None;
if let Some(wix) = config.wix() {
data.insert("custom_action_refs", to_json(&wix.custom_action_refs));
data.insert("component_group_refs", to_json(&wix.component_group_refs));
data.insert("component_refs", to_json(&wix.component_refs));
data.insert("feature_group_refs", to_json(&wix.feature_group_refs));
data.insert("feature_refs", to_json(&wix.feature_refs));
data.insert("merge_refs", to_json(&wix.merge_refs));
fragment_paths = wix.fragment_paths.clone().unwrap_or_default();
custom_template_path = wix.template.clone();

fragment_paths = wix.fragment_paths.clone().unwrap_or_default();
if let Some(ref inline_fragments) = wix.fragments {
tracing::debug!(
"Writing inline fragments to {}",
util::display_path(&intermediates_path)
);
for (idx, fragment) in inline_fragments.iter().enumerate() {
let path = intermediates_path.join(format!("inline_fragment{idx}.wxs"));
std::fs::write(&path, fragment)?;
fragment_paths.push(path);
}
}

if let Some(banner_path) = &wix.banner_path {
data.insert("banner_path", to_json(dunce::canonicalize(banner_path)?));
}
Expand Down Expand Up @@ -696,7 +707,7 @@ fn build_wix_app_installer(ctx: &Context, wix_path: &Path) -> crate::Result<Vec<
}
),
"-loc".into(),
display_path(&locale_path),
util::display_path(&locale_path),
"*.wixobj".into(),
];
let msi_output_path = intermediates_path.join("output.msi");
Expand All @@ -710,7 +721,10 @@ fn build_wix_app_installer(ctx: &Context, wix_path: &Path) -> crate::Result<Vec<
.ok_or_else(|| crate::Error::ParentDirNotFound(msi_path.clone()))?,
)?;

tracing::info!("Running light.exe to produce {}", display_path(&msi_path));
tracing::info!(
"Running light.exe to produce {}",
util::display_path(&msi_path)
);

run_light(
config,
Expand Down
62 changes: 62 additions & 0 deletions examples/wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,65 @@ product-name = "WRY example"
identifier = "com.wry.example"
resources = ["Cargo.toml", "src", "32x32.png"]
icons = ["32x32.png"]

[package.metadata.packager.deb]
depends = ["libgtk-3-0", "libwebkit2gtk-4.1-0"]

[package.metadata.packager.appimage]
libs = [
"WebKitNetworkProcess",
"WebKitWebProcess",
"libwebkit2gtkinjectedbundle.so",
]

[package.metadata.packager.appimage.linuxdeploy-plugins]
"gtk" = "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"

[package.metadata.packager.nsis]
appdata-paths = ["$LOCALAPPDATA/$IDENTIFIER"]
preinstall-section = """
; Setup messages
; English
LangString webview2AbortError ${LANG_ENGLISH} "Failed to install WebView2! The app can't run without it. Try restarting the installer."
LangString webview2DownloadError ${LANG_ENGLISH} "Error: Downloading WebView2 Failed - $0"
LangString webview2DownloadSuccess ${LANG_ENGLISH} "WebView2 bootstrapper downloaded successfully"
LangString webview2Downloading ${LANG_ENGLISH} "Downloading WebView2 bootstrapper..."
LangString webview2InstallError ${LANG_ENGLISH} "Error: Installing WebView2 failed with exit code $1"
LangString webview2InstallSuccess ${LANG_ENGLISH} "WebView2 installed successfully"

Section PreInstall
; Check if Webview2 is already installed and skip this section
${If} ${RunningX64}
ReadRegStr $4 HKLM "SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${Else}
ReadRegStr $4 HKLM "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${EndIf}
ReadRegStr $5 HKCU "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"

StrCmp $4 "" 0 webview2_done
StrCmp $5 "" 0 webview2_done

Delete "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
DetailPrint "$(webview2Downloading)"
nsis_tauri_utils::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
Pop $0
${If} $0 == 0
DetailPrint "$(webview2DownloadSuccess)"
${Else}
DetailPrint "$(webview2DownloadError)"
Abort "$(webview2AbortError)"
${EndIf}
StrCpy $6 "$TEMP\\MicrosoftEdgeWebview2Setup.exe"

DetailPrint "$(installingWebview2)"
; $6 holds the path to the webview2 installer
ExecWait "$6 /install" $1
${If} $1 == 0
DetailPrint "$(webview2InstallSuccess)"
${Else}
DetailPrint "$(webview2InstallError)"
Abort "$(webview2AbortError)"
${EndIf}
webview2_done:
SectionEnd
"""
Loading