Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Windows: no console window with the app, and the Start Menu shortcut gets its icon (#57)

Brandon Thomasfdfdc879d7f2
diff --git a/.github/workflows/packaging-lint.yml b/.github/workflows/packaging-lint.yml
index 50e4b013b..29817c7eb 100644
--- a/.github/workflows/packaging-lint.yml
+++ b/.github/workflows/packaging-lint.yml
@@ -47,6 +47,10 @@ jobs:
- name: XML, desktop entry, AppStream, Flatpak manifest
run: |
xmllint --noout packaging/windows/printcraft.wxs packaging/macos/*.plist* packaging/linux/*.xml*
+ # Windows Installer needs Icon ids ending in .ico or .exe, or shortcuts show a blank icon (#57).
+ if grep -oE '<Icon Id="[^"]*"' packaging/windows/printcraft.wxs | grep -vE '\.(ico|exe)"$'; then
+ echo "::error file=packaging/windows/printcraft.wxs::Icon Id must end in .ico or .exe"; exit 1
+ fi
desktop-file-validate packaging/linux/ai.storyteller.printcraft.desktop
sed -e 's/@VERSION@/0.0.0/' -e 's/@DATE@/2026-01-01/' packaging/linux/ai.storyteller.printcraft.metainfo.xml.in >"$RUNNER_TEMP/ai.storyteller.printcraft.metainfo.xml"
appstreamcli validate --no-net --explain "$RUNNER_TEMP/ai.storyteller.printcraft.metainfo.xml"
diff --git a/apps/printcraft/src/main.rs b/apps/printcraft/src/main.rs
index 887fe13ed..390b3c0a4 100644
--- a/apps/printcraft/src/main.rs
+++ b/apps/printcraft/src/main.rs
@@ -11,6 +11,10 @@
//! loopback port and writes `{"port", "token", "pid"}` to `<file>` (owner-only permissions).
//! Agents then drive it with `printcraft-cli ui --control <file> <method> …`.
+// Release builds on Windows are GUI-subsystem programs, so launching the app doesn't open a console
+// window next to it (#57). `--version` and diagnostics then go nowhere when started from a terminal
+// (std ignores the missing console handles, so nothing fails); debug builds keep the console.
+#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
use printcraft_ui_egui::PrintCraftApp;
diff --git a/packaging/windows/package.ps1 b/packaging/windows/package.ps1
index a5d773300..71b23c72c 100644
--- a/packaging/windows/package.ps1
+++ b/packaging/windows/package.ps1
@@ -65,6 +65,19 @@ if (-not $SkipBuild) {
}
$Bin = Join-Path $TargetDir "$Target\release"
+
+# The PE optional header's Subsystem field: 2 = Windows GUI, 3 = console. The app must be GUI (no
+# console window opens with it, #57); the CLI must stay console so its output reaches the terminal.
+function Get-PeSubsystem([string] $Path) {
+ $bytes = [System.IO.File]::ReadAllBytes($Path)
+ $pe = [BitConverter]::ToInt32($bytes, 0x3C)
+ return [BitConverter]::ToUInt16($bytes, $pe + 0x5C)
+}
+foreach ($check in @(@('printcraft.exe', 2), @('printcraft-cli.exe', 3))) {
+ $subsystem = Get-PeSubsystem (Join-Path $Bin $check[0])
+ if ($subsystem -ne $check[1]) { throw "$($check[0]) has PE subsystem $subsystem, expected $($check[1])" }
+ Write-Output "ok $($check[0]): PE subsystem $subsystem"
+}
$Stage = Join-Path $TargetDir "windows-package\$Arch"
Remove-Item -Recurse -Force $Stage -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force -Path $Stage | Out-Null
diff --git a/packaging/windows/printcraft.wxs b/packaging/windows/printcraft.wxs
index e212af11b..4c21d81a6 100644
--- a/packaging/windows/printcraft.wxs
+++ b/packaging/windows/printcraft.wxs
@@ -17,15 +17,17 @@
Scope="perMachine"
Compressed="yes"
Language="1033">
- <SummaryInformation Description="PrintCraft image editor" Manufacturer="Learning Machines LLC" />
+ <SummaryInformation Description="PrintCraft PDF workbench" Manufacturer="Learning Machines LLC" />
<!-- Same-version upgrades let successive pre-releases of one X.Y.Z replace each other
(MSI versions are numeric, so 1.2.3-rc.1 and 1.2.3-rc.2 are both 1.2.3). -->
<MajorUpgrade AllowSameVersionUpgrades="yes"
DowngradeErrorMessage="A newer version of PrintCraft is already installed." />
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
- <Icon Id="PrintcraftIcon" SourceFile="$(var.IconPath)" />
- <Property Id="ARPPRODUCTICON" Value="PrintcraftIcon" />
+ <!-- Windows Installer requires an Icon id ending in .ico or .exe, or advertised shortcuts and
+ Add/Remove Programs show a blank icon (#57). -->
+ <Icon Id="PrintcraftIcon.ico" SourceFile="$(var.IconPath)" />
+ <Property Id="ARPPRODUCTICON" Value="PrintcraftIcon.ico" />
<Property Id="ARPURLINFOABOUT" Value="https://getartcraft.com/apps/printcraft" />
<Property Id="ARPURLUPDATEINFO" Value="https://getartcraft.com/apps/printcraft" />
<Property Id="ARPHELPLINK" Value="https://discord.gg/artcraft" />
@@ -45,8 +47,8 @@
<Component Id="PrintcraftApp" Guid="E724C1C6-091F-4E21-A685-80D089FDBE21">
<File Id="PrintcraftExe" Source="$(var.BinDir)\printcraft.exe" KeyPath="yes">
<Shortcut Id="StartMenuShortcut" Directory="ProgramMenuFolder" Name="PrintCraft"
- Description="PrintCraft image editor" WorkingDirectory="INSTALLFOLDER" Advertise="yes"
- Icon="PrintcraftIcon" IconIndex="0" />
+ Description="PrintCraft PDF workbench" WorkingDirectory="INSTALLFOLDER" Advertise="yes"
+ Icon="PrintcraftIcon.ico" IconIndex="0" />
</File>
<RegistryValue Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\App Paths\printcraft.exe" Value="[#PrintcraftExe]" Type="string" />