diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 0afe41b..403a24b 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -60,40 +60,29 @@ jobs: meson compile -C builddir meson install -C builddir - - name: 🧱 Create .app bundle + - name: ⚙️ Package it with pyinstaller run: | - mkdir -p MyApp.app/Contents/MacOS - cp install/bin/my-gtk-app MyApp.app/Contents/MacOS/ - cp -r install/share MyApp.app/Contents/Resources/ - # Create basic Info.plist - cat > MyApp.app/Contents/Info.plist < - - - - CFBundleNameMyApp - CFBundleIdentifiercom.example.myapp - CFBundleVersion${{ github.ref_name }} - CFBundleExecutablemy-gtk-app - CFBundlePackageTypeAPPL - - - EOF + pyinstaller --name Scriptorium \ + --windowed \ + --add-data "builddir:." \ + install/bin/scriptorium + codesign --deep --force --sign - dist/Scriptorium.app - name: 📀 Create DMG run: | + mkdir -p dist + rm -f dist/Scriptorium.dmg create-dmg \ - --volname "MyApp" \ - --window-pos 200 120 \ - --window-size 800 400 \ - --icon-size 100 \ - --icon "MyApp.app" 200 190 \ + --volname "Scriptorium" \ + --window-size 1000 800 \ + --icon "Scriptorium.app" 200 190 \ --app-drop-link 600 185 \ - dist/ \ - MyApp.app + "dist/Scriptorium.dmg" \ + "dist/" + - name: 📤 Upload DMG artifact uses: actions/upload-artifact@v4 with: - name: MyApp-macos-dmg + name: Scriptorium-macos-dmg path: dist/*.dmg diff --git a/scriptorium/__init__.py b/scriptorium/__init__.py index 0e34ad1..ea83d0f 100644 --- a/scriptorium/__init__.py +++ b/scriptorium/__init__.py @@ -2,6 +2,6 @@ import gi gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") -gi.require_version("WebKit", "6.0") gi.require_version("Tsparql", "3.0") +gi.require_version("WebKit", "6.0") diff --git a/scriptorium/main.py b/scriptorium/main.py index f2b9a3e..44fad84 100644 --- a/scriptorium/main.py +++ b/scriptorium/main.py @@ -18,7 +18,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import sys from scriptorium.widgets.multiline_entry_row import MultiLineEntryRow -from gi.repository import Gio, Adw, WebKit, GLib +from gi.repository import Gio, Adw, GLib from .window import ScrptWindow import logging @@ -54,11 +54,7 @@ def __init__(self): current_value = self.settings.get_string("style-variant") style_variant_action.activate(GLib.Variant('s', current_value)) - # Force loading WebKit, otherwise it is not recognized in Builder - dummy = WebKit.WebView() - del dummy - - # Same for MultiLineEntryRow + # Force loading MultiLineEntryRow, otherwise it is not recognized in Builder dummy = MultiLineEntryRow() del dummy diff --git a/scriptorium/views/editor_formatting.blp b/scriptorium/views/editor_formatting.blp index bc58aee..0d4be48 100644 --- a/scriptorium/views/editor_formatting.blp +++ b/scriptorium/views/editor_formatting.blp @@ -1,6 +1,5 @@ using Gtk 4.0; using Adw 1; -using WebKit 6.0; template $ScrptFormattingPanel: Adw.NavigationPage { title: "Formatting"; @@ -76,19 +75,10 @@ template $ScrptFormattingPanel: Adw.NavigationPage { margin-start: 12; margin-end: 12; - Box { + Box web_view_placeholder { styles [ "card", ] - WebKit.WebView web_view { - zoom-level: 1; - vexpand: true; - hexpand: true; - margin-start: 6; - margin-end: 6; - margin-top: 6; - margin-bottom: 6; - } } } }; diff --git a/scriptorium/views/editor_formatting.py b/scriptorium/views/editor_formatting.py index 6890420..6aad31f 100644 --- a/scriptorium/views/editor_formatting.py +++ b/scriptorium/views/editor_formatting.py @@ -17,10 +17,16 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from gi.repository import Adw, Gtk, Gio, GObject +import logging +from gi.repository import Adw, Gtk, Gio from scriptorium.models import Chapter from scriptorium.globals import BASE -import logging + +try: + from gi.repository import WebKit + HAVE_WEBKIT = True +except ImportError: + HAVE_WEBKIT = False logger = logging.getLogger(__name__) @@ -33,7 +39,7 @@ class ScrptFormattingPanel(Adw.NavigationPage): __icon_name__ = "open-book-symbolic" __description__ = "Preview and modify the formatting" - web_view = Gtk.Template.Child() + web_view_placeholder = Gtk.Template.Child() button_next = Gtk.Template.Child() button_previous = Gtk.Template.Child() chapters_drop_down = Gtk.Template.Child() @@ -42,6 +48,29 @@ def __init__(self, editor, **kwargs): super().__init__(**kwargs) self._editor = editor + # If we have WebKit set the component, otherwise show placeholder + if HAVE_WEBKIT: + logger.info("Webkit is available") + self.web_view = WebKit.WebView() + self.web_view.set_zoom_level(1) + self.web_view.set_margin_start(6) + self.web_view.set_margin_end(6) + self.web_view.set_margin_top(6) + self.web_view.set_margin_bottom(6) + self.web_view.set_vexpand(True) + self.web_view.set_hexpand(True) + self.web_view_placeholder.append(self.web_view) + else: + widget = Adw.StatusPage( + title = "Not available", + icon_name = "process-stop-symbolic", + description = "This feature is not available on your operating system" + ) + widget.set_vexpand(True) + widget.set_hexpand(True) + self.web_view_placeholder.append(widget) + + self.chapters_drop_down.connect( "notify::selected-item", self.on_selected_item @@ -57,6 +86,7 @@ def __init__(self, editor, **kwargs): self._position = 0 + def on_selected_item(self, _drop_down, _selected_item): selected_chapter = _drop_down.get_selected_item() if selected_chapter is None: @@ -77,7 +107,8 @@ def on_selected_item(self, _drop_down, _selected_item): html_content = html_content.replace("{content}", content) # Load the content - self.web_view.load_html(html_content) + if HAVE_WEBKIT: + self.web_view.load_html(html_content) # Find the position of the chapter chapters = self._editor.project.manuscript.chapters