diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d92d7b2..22e5665 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,6 +23,9 @@ jobs: uses: eifinger/setup-rye@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup rye config - required for tests + run: | + rye config --set default.author="Firstname Lastname " - name: Sync Rye run: | rye pin ${{ matrix.python-version }} diff --git a/src/box/config.py b/src/box/config.py index 56f7e2f..2e04a8a 100644 --- a/src/box/config.py +++ b/src/box/config.py @@ -30,6 +30,11 @@ def app_entry_type(self): """Return the entry type of the project for PyApp.""" return self._pyproject["tool"]["box"]["entry_type"] + @property + def author(self) -> str: + """Return the (first) author of the project.""" + return self._project["authors"][0]["name"] + @property def builder(self) -> str: """Return the builder of the project.""" diff --git a/src/box/installer.py b/src/box/installer.py index 4e1d467..6e85dfc 100644 --- a/src/box/installer.py +++ b/src/box/installer.py @@ -141,7 +141,14 @@ def windows_gui(self): nsis_script_name = Path("make_installer.nsi") with open(nsis_script_name, "w") as f: f.write( - nsis_gui_script(name_pkg, installer_name, self._release_file, icon) + nsis_gui_script( + name_pkg, + installer_name, + self._config.author, + self._config.version, + self._release_file, + icon, + ) ) # make the installer diff --git a/src/box/installer_utils/windows_hlp.py b/src/box/installer_utils/windows_hlp.py index f553f85..7940074 100644 --- a/src/box/installer_utils/windows_hlp.py +++ b/src/box/installer_utils/windows_hlp.py @@ -4,12 +4,19 @@ def nsis_gui_script( - project_name: str, installer_name: str, binary_path: Path, icon_path: Path + project_name: str, + installer_name: str, + author: str, + version: str, + binary_path: Path, + icon_path: Path, ): """Create NSIS script for GUI installer. :param project_name: Name of the project :param installer_name: Name of the installer to be produced by NSIS + :param author: Author of the project + :param version: Version of the project :param binary_path: Path to the binary to be installed :param icon_path: Path to the icon file to be used in the installer """ @@ -19,6 +26,8 @@ def nsis_gui_script( ;Include Modern UI !include "MUI2.nsh" + !define MUI_ICON "{icon_path.absolute()}" + !define MUI_UNICON "{icon_path.absolute()}" ;-------------------------------- ;General @@ -86,26 +95,33 @@ def nsis_gui_script( ;Create uninstaller WriteUninstaller "$INSTDIR\Uninstall-{project_name}.exe" + ; Add uninstaller key information for add/remove software entry + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayName" "{project_name}" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "UninstallString" "$INSTDIR\Uninstall-{project_name}.exe" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "Publisher" "{author}" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayIcon" "$INSTDIR\Uninstall-{project_name}.exe" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayVersion" "{version}" + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application - ;Create shortcuts - if icon file is empty, leave that part away - CreateDirectory "$SMPROGRAMS\$StartMenuFolder" - CreateShortcut "$SMPROGRAMS\$StartMenuFolder\{project_name}.lnk" "$INSTDIR\{binary_path.name}" "" "{str(icon_path.absolute())}" - CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall-{project_name}.lnk" "$INSTDIR\Uninstall-{project_name}.exe" + ;Create shortcuts - if icon file is empty, leave that part away + CreateDirectory "$SMPROGRAMS\$StartMenuFolder" + CreateShortcut "$SMPROGRAMS\$StartMenuFolder\{project_name}.lnk" "$INSTDIR\{binary_path.name}" "" "{str(icon_path.absolute())}" + CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall-{project_name}.lnk" "$INSTDIR\Uninstall-{project_name}.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd - -;-------------------------------- ;Descriptions - ;Language strings + + +;-------------------------------- ;Language strings LangString DESC_SecInst ${{LANG_ENGLISH}} "Selection." ;Assign language strings to sections !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN - !insertmacro MUI_DESCRIPTION_TEXT ${{SecInst}} $(DESC_SecInst) + !insertmacro MUI_DESCRIPTION_TEXT ${{SecInst}} $(DESC_SecInst) !insertmacro MUI_FUNCTION_DESCRIPTION_END ;-------------------------------- @@ -113,7 +129,6 @@ def nsis_gui_script( Section "Uninstall" - ; Delete {project_name} folder Delete "$INSTDIR\{binary_path.name}" Delete "$INSTDIR\Uninstall-{project_name}.exe" @@ -131,7 +146,8 @@ def nsis_gui_script( RMDir "$SMPROGRAMS\$StartMenuFolder" ; Delete registry key - DeleteRegKey /ifempty HKCU "Software\{project_name}" + DeleteRegKey HKCU "Software\{project_name}" + DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" SectionEnd """