From bdbebb9e087b5ccb480694415ce84382e8f9af7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fdez?= Date: Wed, 5 Aug 2020 00:17:09 +0200 Subject: [PATCH] standalone osx application bundle --- Makefile | 4 +- base | 2 +- frontend/device/sdl/device.lua | 3 + platform/mac/do_mac_bundle.sh | 46 ++++++++++++- platform/mac/koreader.sh | 30 -------- platform/mac/menu.xml | 122 +++++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 34 deletions(-) delete mode 100755 platform/mac/koreader.sh create mode 100644 platform/mac/menu.xml diff --git a/Makefile b/Makefile index 3ca9a521b..e336bf91c 100644 --- a/Makefile +++ b/Makefile @@ -405,9 +405,11 @@ macosupdate: all $(INSTALL_DIR)/bundle/Contents/MacOS \ $(INSTALL_DIR)/bundle/Contents/Resources - cp $(MACOS_DIR)/koreader.sh $(INSTALL_DIR)/bundle/Contents/MacOS/koreader cp resources/koreader.icns $(INSTALL_DIR)/bundle/Contents/Resources/icon.icns cp -LR $(INSTALL_DIR)/koreader $(INSTALL_DIR)/bundle/Contents + cp -pRv $(MACOS_DIR)/menu.xml $(INSTALL_DIR)/bundle/Contents/MainMenu.xib + ibtool --compile "$(INSTALL_DIR)/bundle/Contents/Resources/Base.lproj/MainMenu.nib" "$(INSTALL_DIR)/bundle/Contents/MainMenu.xib" + rm -rfv "$(INSTALL_DIR)/bundle/Contents/MainMenu.xib" REMARKABLE_PACKAGE:=koreader-remarkable$(KODEDUG_SUFFIX)-$(VERSION).zip REMARKABLE_PACKAGE_OTA:=koreader-remarkable$(KODEDUG_SUFFIX)-$(VERSION).targz diff --git a/base b/base index 041e30d6c..d2a0a1bff 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 041e30d6c23d76911cb74a2a7fb2661b0bac9a12 +Subproject commit d2a0a1bffba885f39cfe40d4f6c6fa18b6d06aeb diff --git a/frontend/device/sdl/device.lua b/frontend/device/sdl/device.lua index 89e4c1ba0..99b12e522 100644 --- a/frontend/device/sdl/device.lua +++ b/frontend/device/sdl/device.lua @@ -5,6 +5,7 @@ local logger = require("logger") local function yes() return true end local function no() return false end +local function notOSX() return jit.os ~= "OSX" end local function isUrl(s) return type(s) == "string" and s:match("*?://") @@ -101,6 +102,8 @@ local AppImage = Device:new{ local Desktop = Device:new{ model = SDL.getPlatform(), isDesktop = yes, + canRestart = notOSX, + hasExitOptions = notOSX, } local Emulator = Device:new{ diff --git a/platform/mac/do_mac_bundle.sh b/platform/mac/do_mac_bundle.sh index f540713e6..d18c8991a 100755 --- a/platform/mac/do_mac_bundle.sh +++ b/platform/mac/do_mac_bundle.sh @@ -1,5 +1,20 @@ #!/bin/bash # Script to generate mac application bundles for KOReader +# +# We don't use XCode at all. Just commandline tools. +# +# menu.xml contains the main menu of a typical OSX program. +# each time some user facing string in menu.xml changed we can +# generate a new translation template with: +# +# cp menu.xml menu.xib +# ibtool --generate-strings-file mac.strings menu.xib +# rm -rf menu.xib +# +# the generated "mac.strings" is in xliff format (binary, not plain text) +# and can be translated using an xliff editor or an online service that support +# IOS string format, like weblate. + COPYRIGHT="Copyright © $(date +"%Y") KOReader" command_exists() { @@ -95,10 +110,14 @@ cat <"${APP_PATH}/Contents/Info.plist" NSPrincipalClass NSApplication + NSMainNibFile + MainMenu LSMultipleInstancesProhibited LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} + SDL_FILESYSTEM_BASE_DIR_TYPE + bundle END @@ -135,18 +154,41 @@ install_name_tool -change ${BREW}/webp/lib/libwebp.7.dylib libs/libwebp.7.dylib # prepare bundle for distribution ln -s /usr/bin/tar tar -mv COPYING ../COPYING.txt +mv COPYING README.md ../Resources/ +mv koreader ../MacOS/koreader rm -rf cache clipboard history ota \ l10n/.git l10n/.tx l10n/templates l10n/LICENSE l10n/Makefile l10n/README.md \ plugins/SSH.koplugin plugins/hello.koplugin plugins/timesync.koplugin \ plugins/autofrontlight.koplugin resources/fonts resources/icons/src \ resources/kobo-touch-probe.png resources/koreader.icns rocks/bin \ - rocks/lib/luarocks screenshots spec tools README.md + rocks/lib/luarocks screenshots spec tools + +# adjust reader.lua a bit. + +sed '1d' reader.lua >tempfile +sed -i.backup 's/.\/reader.lua/koreader/' tempfile +sed -i.backup 's/the last viewed document will be opened"/" .. os.getenv("HOME") .. " will be opened"/' tempfile +mv tempfile reader.lua +rm -f tempfile* +chmod -x reader.lua popd || exit 1 +# bundle translations, if any +for path in l10n/*; do + lang=$(echo "${path}" | sed s'/l10n\///') + if [ "${lang}" != "templates" ]; then + translation_file="l10n/${lang}/mac.strings" + if [ -f "${translation_file}" ]; then + mkdir -p "${APP_PATH}/Contents/Resources/${lang}.lproj" + cp -pv "${translation_file}" "${APP_PATH}/Contents/Resources/${lang}.lproj/MainMenu.strings" + fi + fi +done + # package as DMG if create-dmg is available # reduces size from 80MB to 40MB mv "${APP_PATH}" "${APP_BUNDLE}.app" + if command_exists "create-dmg"; then # create KOReader-$VERSION.dmg with KOReader.app inside create-dmg "${APP_BUNDLE}.app" --overwrite diff --git a/platform/mac/koreader.sh b/platform/mac/koreader.sh deleted file mode 100755 index 236ee556d..000000000 --- a/platform/mac/koreader.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -export LC_ALL="en_US.UTF-8" - -export KO_MULTIUSER=1 -USER_STORAGE="${HOME}/.config/koreader" -[ ! -d "${USER_STORAGE}" ] && mkdir -p "${USER_STORAGE}" - -# working directory of koreader -KOREADER_DIR="${0%/*}/../koreader" - -# arguments -if [ -z "${1}" ]; then - ARGS=${HOME} -else - ARGS=${*} -fi - -# we're always starting from our working directory -cd "${KOREADER_DIR}" || exit -RETURN_VALUE=85 -while [ ${RETURN_VALUE} -eq 85 ]; do - ./reader.lua "${ARGS}" - RETURN_VALUE=$? - ARGS=${HOME} -done - -# remove the flag to avoid emulator confusion -export -n KO_MULTIUSER - -exit ${RETURN_VALUE} diff --git a/platform/mac/menu.xml b/platform/mac/menu.xml new file mode 100644 index 000000000..af75bf53e --- /dev/null +++ b/platform/mac/menu.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +