Skip to content

Commit

Permalink
Merge pull request #394 from gaphor/mac-startup-binary
Browse files Browse the repository at this point in the history
Mac startup binary
  • Loading branch information
amolenaar committed Aug 12, 2020
2 parents b5b7795 + fb7e307 commit fde76a5
Show file tree
Hide file tree
Showing 9 changed files with 1,403 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
- name: Install macOS Dependencies
run: |
brew list
brew install gobject-introspection gtk+3 adwaita-icon-theme create-dmg
brew install gobject-introspection gtk+3 adwaita-icon-theme gtk-mac-integration create-dmg
- name: Install Poetry
uses: dschep/install-poetry-action@v1.3
with:
Expand Down
3 changes: 2 additions & 1 deletion gaphor/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def quit(self):
event_manager.handle(SessionShutdownRequested(self))
if self.active_session == session:
logger.info("Window not closed, abort quit operation")
return
return False
self.shutdown()
return True

def all(self, base: Type[T]) -> Iterator[Tuple[str, T]]:
return (
Expand Down
4 changes: 4 additions & 0 deletions gaphor/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
gi.require_version("Gtk", "3.0") # noqa: isort:skip
gi.require_version("Gdk", "3.0") # noqa: isort:skip
from gi.repository import GLib, Gdk, Gio, Gtk # noqa: isort:skip
from gaphor.ui.macosshim import macos_init

# fmt: on


Expand Down Expand Up @@ -101,6 +103,8 @@ def app_startup(gtk_app):
try:
application = Application()
apply_application_actions(application, gtk_app)
if macos_init:
macos_init(application, gtk_app)
except Exception:
gtk_app.quit()
raise
Expand Down
28 changes: 28 additions & 0 deletions gaphor/ui/macosshim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
try:
import gi

gi.require_version("GtkosxApplication", "1.0")
except ValueError:
macos_init = None
else:
from gi.repository import Gio, GtkosxApplication

macos_app = GtkosxApplication.Application.get()

def open_file(macos_app, path, gtk_app):
if path == __file__:
return False

gtk_app.open([Gio.File.new_for_path(path)], "")

return True

def block_termination(macos_app, application):
quit = application.quit()
return not quit

def macos_init(application, gtk_app):
macos_app.connect("NSApplicationOpenFile", open_file, gtk_app)
macos_app.connect(
"NSApplicationBlockTermination", block_termination, application
)
49 changes: 38 additions & 11 deletions macos-dmg/Info.plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
Expand All @@ -23,14 +23,31 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleDisplayName</key>
<!-- shown in menu bar during running -->
<string>Gaphor</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2001-2019 Gaphor Developers, Apache 2 License.</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>PyMainFileNames</key>
<array>
<string>__boot__</string>
</array>
<key>PyResourcePackages</key>
<array>
<string>@executable_path/../../Frameworks/Python.framework/Versions/3.7/lib/python3.7</string>
<string>@executable_path/../../Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload</string>
<string>@executable_path/../lib/python3.7/site-packages</string>
</array>
<key>PyRuntimeLocations</key>
<array>
<string>@executable_path/../Frameworks/Python.framework/Versions/3.7/Python</string>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
Expand All @@ -46,20 +63,18 @@
</array>
<key>CFBundleTypeName</key>
<string>Gaphor Model</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>GAPHOR</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>org.gaphor.model</string>
</array>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
<string>public.content</string>
<string>gaphor.model</string>
</array>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
Expand All @@ -79,14 +94,26 @@
<string>https://gaphor.org/</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>GAPHOR</string>
<key>public.filename-extension</key>
<array>
<string>gaphor</string>
</array>
<key>public.mime-type</key>
<string>application/x-gaphor</string>
<array>
<string>application/x-gaphor</string>
</array>
</dict>
</dict>
</array>
<key>NSDesktopFolderUsageDescription</key>
<string>Gaphor needs your permission to access the Desktop folder.</string>
<key>NSDocumentsFolderUsageDescription</key>
<string>Gaphor needs your permission to access the Documents folder.</string>
<key>NSDownloadsFolderUsageDescription</key>
<string>Gaphor needs your permission to access the Downloads folder.</string>
<key>NSNetworkVolumesUsageDescription</key>
<string>Gaphor needs your permission to access network folders.</string>
</dict>
</plist>
40 changes: 40 additions & 0 deletions macos-dmg/__boot__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import pathlib
import sys

PYVER = "3.7"

resources = os.environ["RESOURCEPATH"]
cache = pathlib.Path.home() / ".cache" / "gaphor"

print(f"App contents folder is {resources}, cache is {cache}")


while sys.path[0] == resources:
del sys.path[0]


os.environ["DYLD_LIBRARY_PATH"] = f"{resources}/lib"
os.environ["FONTCONFIG_SYSROOT"] = f"{resources}"
os.environ["GTK_DATA_PREFIX"] = f"{resources}"
os.environ["GI_TYPELIB_PATH"] = f"{resources}/lib/girepository-1.0"

os.environ["GTK_EXE_PREFIX"] = f"{resources}"
os.environ["GTK_PATH"] = f"{resources}"
os.environ["XDG_DATA_HOME"] = f"{resources}/share"
os.environ["XDG_DATA_DIRS"] = f"{resources}/share"
os.environ["FONTCONFIG_FILE"] = f"{resources}/etc/fonts/fonts.conf"
os.environ["GI_TYPELIB_PATH"] = f"{resources}/lib/girepository-1.0"

os.environ["GDK_PIXBUF_MODULEDIR"] = f"{resources}/lib/gdk-pixbuf-2.0/2.10.0/loaders"
os.environ["GDK_PIXBUF_MODULE_FILE"] = f"{cache}/gdk-pixbuf-2.0-loaders.cache"

os.environ["GTK_IM_MODULE_FILE"] = f"{cache}/immodules.cache"

os.system(f'"{resources}/bin/gdk-pixbuf-query-loaders" --update-cache')
os.system(f'"{resources}/bin/gtk-query-immodules-3.0" --update-cache')


from gaphor.ui import main # noqa: E402

main(sys.argv)
41 changes: 0 additions & 41 deletions macos-dmg/gaphor

This file was deleted.

0 comments on commit fde76a5

Please sign in to comment.