From 500530a3367332aaf798cfd51a4bfe66d439381f Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 30 Aug 2022 14:00:58 -0300 Subject: [PATCH] dmg: version, and set icon - Add the version number into the .dmg filename - Set the lokinet icon on the .dmg. This is done via a swift program because all the Apple CLI tools to do this are deprecated. --- CMakeLists.txt | 2 +- cmake/macos.cmake | 8 +++++--- contrib/mac.sh | 2 +- contrib/macos/seticon.swift | 26 ++++++++++++++++++++++++++ contrib/macos/sign.sh.in | 2 +- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 contrib/macos/seticon.swift diff --git a/CMakeLists.txt b/CMakeLists.txt index d987714a1..ad3ef1e01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ project(lokinet if(APPLE) # Apple build number: must be incremented to submit a new build for the same lokinet version, # should be reset to 0 when the lokinet version increments. - set(LOKINET_APPLE_BUILD 3) + set(LOKINET_APPLE_BUILD 4) endif() set(RELEASE_MOTTO "Our Lord And Savior" CACHE STRING "Release motto") diff --git a/cmake/macos.cmake b/cmake/macos.cmake index 9ecffb4a7..2f15a02fc 100644 --- a/cmake/macos.cmake +++ b/cmake/macos.cmake @@ -73,7 +73,7 @@ message(STATUS "Using ${CODESIGN_EXT_PROFILE} extension provisioning profile") -set(lokinet_installer "${PROJECT_BINARY_DIR}/Lokinet Installer") +set(lokinet_installer "${PROJECT_BINARY_DIR}/Lokinet ${PROJECT_VERSION}") set(lokinet_app "${lokinet_installer}/Lokinet.app") @@ -128,10 +128,11 @@ add_custom_command(OUTPUT "${mac_icon}" add_custom_target(icon DEPENDS "${mac_icon}") if(BUILD_PACKAGE) + add_executable(seticon "${PROJECT_SOURCE_DIR}/contrib/macos/seticon.swift") add_custom_command(OUTPUT "${lokinet_installer}.dmg" - DEPENDS notarize + DEPENDS notarize seticon COMMAND create-dmg - --volname "Lokinet Installer" + --volname "Lokinet ${PROJECT_VERSION}" --volicon lokinet.icns #--background ... FIXME --text-size 16 @@ -144,6 +145,7 @@ if(BUILD_PACKAGE) --no-internet-enable "${lokinet_installer}.dmg" "${lokinet_installer}" + COMMAND ./seticon lokinet.icns "${lokinet_installer}.dmg" ) add_custom_target(package DEPENDS "${lokinet_installer}.dmg") endif() diff --git a/contrib/mac.sh b/contrib/mac.sh index 6ddb89f04..70bf4d090 100755 --- a/contrib/mac.sh +++ b/contrib/mac.sh @@ -35,5 +35,5 @@ ninja -j1 package cd .. echo -e "Build complete, your app is here:\n" -ls -lad $(pwd)/build-mac/Lokinet\ Installer* +ls -lad $(pwd)/build-mac/Lokinet\ * echo "" diff --git a/contrib/macos/seticon.swift b/contrib/macos/seticon.swift new file mode 100644 index 000000000..b73c26ec9 --- /dev/null +++ b/contrib/macos/seticon.swift @@ -0,0 +1,26 @@ +import Foundation +import AppKit + +// Apple deprecated their command line tools to set images on things and replaced them with a +// barely-documented swift function. Yay! + +// Usage: ./seticon /path/to/my.icns /path/to/some.dmg + +let args = CommandLine.arguments + +if args.count != 3 { + print("Error: usage: ./seticon /path/to/my.icns /path/to/some.dmg") + exit(1) +} + +var icns = args[1] +var dmg = args[2] + +var img = NSImage(byReferencingFile: icns)! + +if NSWorkspace.shared.setIcon(img, forFile: dmg) { + print("Set \(dmg) icon to \(icns) [\(img.size)]") +} else { + print("Setting icon failed, don't know why") + exit(2) +} diff --git a/contrib/macos/sign.sh.in b/contrib/macos/sign.sh.in index ae0cff037..8765e51b7 100755 --- a/contrib/macos/sign.sh.in +++ b/contrib/macos/sign.sh.in @@ -26,7 +26,7 @@ gui_entitlements="@PROJECT_SOURCE_DIR@/gui/node_modules/app-builder-lib/template ext_entitlements="@PROJECT_SOURCE_DIR@/contrib/macos/lokinet-extension.@LOKINET_ENTITLEMENTS_TYPE@.entitlements.plist" app_entitlements="@PROJECT_SOURCE_DIR@/contrib/macos/lokinet.@LOKINET_ENTITLEMENTS_TYPE@.entitlements.plist" -SIGN_TARGET="@PROJECT_BINARY_DIR@/Lokinet Installer/Lokinet.app" +SIGN_TARGET="@PROJECT_BINARY_DIR@/Lokinet @PROJECT_VERSION@/Lokinet.app" for ext in systemextension appex; do netext="$SIGN_TARGET/@lokinet_ext_dir@/org.lokinet.network-extension.$ext"