From ccb0c3d5ee20d7a4750662f02b1160b61586f1b8 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Tue, 1 Jan 2019 13:56:22 +0100 Subject: [PATCH] Mac app package --- mac-setup/build-app.sh | 15 +++++++++++++-- src/control/XournalMain.cpp | 22 ++++++++++++++++++---- src/util/Stacktrace.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/mac-setup/build-app.sh b/mac-setup/build-app.sh index 12c35a72..79e6ac6c 100755 --- a/mac-setup/build-app.sh +++ b/mac-setup/build-app.sh @@ -11,7 +11,11 @@ cd "${0%/*}" # delete old app, if there echo "clean old app" -rm -rf ./Xournal++.app +if [[ $1 == u ]]; then + echo "update app!" +else + rm -rf ./Xournal++.app +fi echo "prepare macdylibbundler" if [ ! -d "macdylibbundler" ]; then @@ -28,11 +32,18 @@ cd .. echo "prepare package" mkdir -p Xournal++.app/Contents/MacOS +mkdir -p Xournal++.app/Contents/Resources cp ../build/src/xournalpp ./Xournal++.app/Contents/MacOS/xournalpp -./macdylibbundler/dylibbundler -od -b -x ./Xournal++.app/Contents/MacOS/xournalpp -d ./Xournal++.app/Contents/libs/ + +if [[ $1 == u ]]; then + echo "update app!" +else + ./macdylibbundler/dylibbundler -od -b -x ./Xournal++.app/Contents/MacOS/xournalpp -d ./Xournal++.app/Contents/libs/ +fi cp icon/xournalpp.icns ./Xournal++.app/Contents/Resources/xournalpp.icns cp Info.plist ./Xournal++.app/Contents/Info.plist +cp -rvp ../ui ./Xournal++.app/Contents/Resources/ echo "finished" diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index 9273846e..bd420f6b 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -52,11 +52,11 @@ void XournalMain::initLocalisation() bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); textdomain(GETTEXT_PACKAGE); - + #ifdef WIN32 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); #endif - + #endif //ENABLE_NLS // Not working on Windows! Working on Linux, but not sure if it's needed @@ -93,7 +93,7 @@ void XournalMain::checkForErrorlog() } g_dir_close(home); - + if (errorList.empty()) { return; @@ -265,7 +265,7 @@ int XournalMain::run(int argc, char* argv[]) } // Checks for input method compatibility - + const char* imModule = g_getenv("GTK_IM_MODULE"); if (imModule != NULL && strcmp(imModule, "xim") == 0) { @@ -437,6 +437,19 @@ void XournalMain::initResourcePath(GladeSearchpath* gladePath) // ----------------------------------------------------------------------- +#ifdef __APPLE__ + Path p = Stacktrace::getExePath(); + p /= "../Resources/ui/about.glade"; + + if (p.exists()) + { + gladePath->addSearchDirectory(p.getParentPath().str()); + return; + } + + string msg = FS(_F("Missing the needed UI file! .app corrupted?\nPath: {1}") % p.str()); + XojMsgBox::showErrorToUser(NULL, msg); +#else // Check at the target installation directory Path absolute = PACKAGE_DATA_DIR; absolute /= PROJECT_PACKAGE; @@ -450,6 +463,7 @@ void XournalMain::initResourcePath(GladeSearchpath* gladePath) string msg = FS(_F("Missing the needed UI file, could not find them at any location.\nNot relative\nNot in the Working Path\nNot in {1}") % PACKAGE_DATA_DIR); XojMsgBox::showErrorToUser(NULL, msg); +#endif exit(12); } diff --git a/src/util/Stacktrace.cpp b/src/util/Stacktrace.cpp index 4be33267..df7d9d0c 100644 --- a/src/util/Stacktrace.cpp +++ b/src/util/Stacktrace.cpp @@ -8,6 +8,13 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + +#include + + #include using std::endl; @@ -36,12 +43,35 @@ void Stacktrace::printStracktrace(std::ostream& stream) } #else +#ifdef __APPLE__ + +std::string Stacktrace::getExePath() +{ + char c; + uint32_t size = 0; + _NSGetExecutablePath(&c, &size); + + char* path = new char[size + 1]; + if (_NSGetExecutablePath(path, &size) == 0) + { + Path p(path); + delete[] path; + return p.getParentPath().str(); + } + + g_error("Could not executable path!"); + + delete[] path; + return ""; +} +#else std::string Stacktrace::getExePath() { char result[PATH_MAX]; ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); return std::string(result, (count > 0) ? count : 0); } +#endif void Stacktrace::printStracktrace(std::ostream& stream) {