Skip to content

Commit

Permalink
feat(Windows): nsis (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Dec 18, 2024
1 parent 1531d5b commit d9038ff
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
data/screenshots/*.png filter=lfs diff=lfs merge=lfs -text
build-aux/*.bmp filter=lfs diff=lfs merge=lfs -text
17 changes: 16 additions & 1 deletion .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ on:
push:
branches: [main]
pull_request:
workflow_dispatch:
inputs:
release:
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -16,13 +20,24 @@ jobs:
shell: msys2 {0}
steps:
- uses: actions/checkout@v3
with:
lfs: 'true'
- uses: msys2/setup-msys2@v2
with:
msystem: mingw64
update: true
install: git make zip wget mingw-w64-x86_64-meson mingw-w64-x86_64-gcc mingw-w64-x86_64-vala mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libxml2 mingw-w64-x86_64-gtksourceview5 mingw-w64-x86_64-webp-pixbuf-loader mingw-w64-x86_64-libadwaita mingw-w64-x86_64-libgee mingw-w64-x86_64-json-glib mingw-w64-x86_64-libsecret mingw-w64-x86_64-desktop-file-utils mingw-w64-x86_64-imagemagick mingw-w64-x86_64-icu mingw-w64-x86_64-libspelling mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base mingw-w64-x86_64-gst-plugins-good
install: git make zip wget unzip mingw-w64-x86_64-meson mingw-w64-x86_64-gcc mingw-w64-x86_64-vala mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libxml2 mingw-w64-x86_64-gtksourceview5 mingw-w64-x86_64-webp-pixbuf-loader mingw-w64-x86_64-libadwaita mingw-w64-x86_64-libgee mingw-w64-x86_64-json-glib mingw-w64-x86_64-libsecret mingw-w64-x86_64-desktop-file-utils mingw-w64-x86_64-imagemagick mingw-w64-x86_64-icu mingw-w64-x86_64-libspelling mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-nsis
- run: make windows release=1
if: ${{ inputs.release }}
- run: make windows
if: ${{ !inputs.release }}
- uses: actions/upload-artifact@v4
with:
name: tuba_windows_portable
path: tuba_windows_portable/
- run: make windows_nsis
- uses: actions/upload-artifact@v4
with:
name: Tuba Setup.exe
path: nsis/Tuba Setup.exe
- run: sha256sum nsis/Tuba\ Setup.exe
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ builddir
*.exe
/tuba_windows_portable/
tuba_windows_portable.zip
/nsis/
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ __windows_set_icon:
ifeq (,$(wildcard ./rcedit-x64.exe))
wget https://github.com/electron/rcedit/releases/download/v1.1.1/rcedit-x64.exe
endif
rsvg-convert ./data/icons/color-nightly.svg -o ./builddir/color-nightly.png -h 256 -w 256
magick -density "256x256" -background transparent ./builddir/color-nightly.png -define icon:auto-resize -colors 256 ./builddir/dev.geopjr.Tuba.ico
rsvg-convert ./data/icons/color$(if $(release),,-nightly).svg -o ./builddir/color$(if $(release),,-nightly).png -h 256 -w 256
magick -density "256x256" -background transparent ./builddir/color$(if $(release),,-nightly).png -define icon:auto-resize -colors 256 ./builddir/dev.geopjr.Tuba.ico
./rcedit-x64.exe $(PREFIX)/bin/dev.geopjr.Tuba.exe --set-icon ./builddir/dev.geopjr.Tuba.ico

__windows_copy_deps:
Expand All @@ -54,7 +54,7 @@ __windows_copy_deps:
cp -r /mingw64/lib/gstreamer-1.0 $(PREFIX)/lib/gstreamer-1.0

cp -f /mingw64/share/gtksourceview-5/styles/Adwaita.xml /mingw64/share/gtksourceview-5/styles/Adwaita-dark.xml ${PREFIX}/share/gtksourceview-5/styles/
cp -f /mingw64/share/gtksourceview-5/language-specs/xml.lang /mingw64/share/gtksourceview-5/language-specs/markdown.lang /mingw64/share/gtksourceview-5/language-specs/html.lang ${PREFIX}/share/gtksourceview-5/language-specs/
cp -f /mingw64/share/gtksourceview-5/language-specs/dtd.lang /mingw64/share/gtksourceview-5/language-specs/def.lang /mingw64/share/gtksourceview-5/language-specs/rust.lang /mingw64/share/gtksourceview-5/language-specs/language2.rng /mingw64/share/gtksourceview-5/language-specs/json.lang /mingw64/share/gtksourceview-5/language-specs/xml.lang /mingw64/share/gtksourceview-5/language-specs/markdown.lang /mingw64/share/gtksourceview-5/language-specs/html.lang ${PREFIX}/share/gtksourceview-5/language-specs/

ldd $(PREFIX)/lib/gio/*/*.dll | grep '\/mingw.*\.dll' -o | xargs -I{} cp "{}" $(PREFIX)/bin
ldd $(PREFIX)/lib/gstreamer-1.0/*.dll | grep '\/mingw.*\.dll' -o | xargs -I{} cp "{}" $(PREFIX)/bin
Expand All @@ -80,3 +80,16 @@ __windows_cleanup:

__windows_package:
zip -r9q tuba_windows_portable.zip tuba_windows_portable/

windows_nsis:
rm -rf nsis
mkdir nsis
cp ./build-aux/dev.geopjr.Tuba-side.bmp nsis/
cp ./builddir/dev.geopjr.Tuba.ico nsis/
cp ./builddir/dev.geopjr.Tuba.nsi nsis/
mv tuba_windows_portable/ nsis/
magick ./builddir/color$(if $(release),,-nightly).png -modulate 100,100,70 nsis/dev.geopjr.Tuba-uninstall.png
magick -density "256x256" -background transparent nsis/dev.geopjr.Tuba-uninstall.png -define icon:auto-resize -colors 256 nsis/dev.geopjr.Tuba-uninstall.ico
rsvg-convert ./data/icons/color$(if $(release),,-nightly).svg -o nsis/dev.geopjr.Tuba-header.png -h 57 -w 57
magick nsis/dev.geopjr.Tuba-header.png -background white -alpha remove -alpha off -type truecolor -define bmp:format=bmp3 nsis/dev.geopjr.Tuba-header.bmp
cd nsis && makensis dev.geopjr.Tuba.nsi
3 changes: 3 additions & 0 deletions build-aux/dev.geopjr.Tuba-side.bmp
Git LFS file not shown
144 changes: 144 additions & 0 deletions build-aux/dev.geopjr.Tuba.nsi.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
;----------
; Includes

!include "MUI2.nsh"
!include "logiclib.nsh"
!include "FileFunc.nsh"

;----------
; Custom defines

!define NAME "@NAME@"
!define EXEC_NAME "@EXEC_NAME@"
!define APPFILE "${EXEC_NAME}.exe"
!define VERSION "@VERSION@"
!define SLUG "${NAME} v${VERSION}"
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"

;----------
; General

Name "${Name}"
BrandingText "${SLUG}"
OutFile "${NAME} Setup.exe"
InstallDir "$PROGRAMFILES\${NAME}"
InstallDirRegKey HKCU "Software\${NAME}" ""
RequestExecutionLevel admin

;----------
; UI

!define MUI_ICON "${EXEC_NAME}.ico"
!define MUI_UNICON "${EXEC_NAME}-uninstall.ico"
!define MUI_ABORTWARNING
!define MUI_WELCOMEPAGE_TITLE "${SLUG} Setup"
!define MUI_WELCOMEFINISHPAGE_BITMAP "${EXEC_NAME}-side.bmp"
!define MUI_HEADERIMAGE_BITMAP "${EXEC_NAME}-header.bmp"
!define MUI_HEADERIMAGE "${EXEC_NAME}.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH

;----------
; Pages

; Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\bin\${APPFILE}"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_LINK "Visit ${NAME}'s Website"
!define MUI_FINISHPAGE_LINK_LOCATION "https://tuba.geopjr.dev/"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;----------
; Language

!insertmacro MUI_LANGUAGE "English"

;----------
; Section - Install App

Section "-hidden app"
SectionIn RO
SetOutPath "$INSTDIR\bin"
File /a /r "tuba_windows_portable\bin\"
SetOutPath "$INSTDIR\lib"
File /a /r "tuba_windows_portable\lib\"
SetOutPath "$INSTDIR\share"
File /a /r "tuba_windows_portable\share\"
SetOutPath "$INSTDIR\"
File "${EXEC_NAME}.ico"
WriteRegStr HKCU "Software\${NAME}" "" $INSTDIR

WriteRegStr HKLM "${UNINSTALL_KEY}" "DisplayName" "${NAME}"
WriteRegStr HKLM "${UNINSTALL_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR"
WriteRegStr HKLM "${UNINSTALL_KEY}" "Publisher" "GeopJr"
WriteRegStr HKLM "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\${EXEC_NAME}.ico"
WriteRegStr HKLM "${UNINSTALL_KEY}" "URLInfoAbout" "https://tuba.geopjr.dev/"
WriteRegStr HKLM "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}"
WriteRegDWORD HKLM "${UNINSTALL_KEY}" "NoModify" 1
WriteRegDWORD HKLM "${UNINSTALL_KEY}" "NoRepair" 1

${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "${UNINSTALL_KEY}" "EstimatedSize" "$0"

WriteUninstaller "$INSTDIR\uninstall.exe"
SectionEnd

;----------
; Section - Shortcut

Section "Desktop Shortcut" DeskShort
CreateShortCut "$DESKTOP\${NAME}.lnk" "$INSTDIR\bin\${APPFILE}"
CreateShortCut "$SMPrograms\${NAME}.lnk" "$INSTDIR\bin\${APPFILE}"
SectionEnd

;----------
; Remove empty parent directories

Function un.RMDirUP
!define RMDirUP '!insertmacro RMDirUPCall'

!macro RMDirUPCall _PATH
push '${_PATH}'
Call un.RMDirUP
!macroend

; $0 - current folder
ClearErrors

Exch $0
; DetailPrint "ASDF - $0\.."
RMDir "$0\.."

IfErrors Skip
${RMDirUP} "$0\.."
Skip:
Pop $0
FunctionEnd

;----------
; Section - Uninstaller

Section "Uninstall"
; Delete Shortcut
Delete "$DESKTOP\${NAME}.lnk"
Delete "$SMPrograms\${NAME}.lnk"

; Delete Uninstall
Delete "$INSTDIR\uninstall.exe"

; Delete Folder
RMDir /r "$INSTDIR"
${RMDirUP} "$INSTDIR"

DeleteRegKey /ifempty HKCU "Software\${NAME}"
DeleteRegKey HKLM "${UNINSTALL_KEY}"
SectionEnd
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ endif

if host_machine.system() == 'windows'
add_project_arguments(['--define=WINDOWS'], language: 'vala')
add_project_arguments('-mwindows', language: 'c')
elif host_machine.system() == 'darwin'
add_project_arguments(['--define=DARWIN'], language: 'vala')
endif
Expand Down Expand Up @@ -143,6 +142,7 @@ executable(
sources,
dependencies: final_deps,
install: true,
win_subsystem: 'windows'
)

subdir('tests')
Expand All @@ -163,3 +163,11 @@ if not distro
meson.add_install_script('build-aux/meson_post_install.py')
endif
endif

if host_machine.system() == 'windows'
configure_file(
input : 'build-aux/dev.geopjr.Tuba.nsi.in',
output : 'dev.geopjr.Tuba.nsi',
configuration : config
)
endif

0 comments on commit d9038ff

Please sign in to comment.