From ac9c16661e56ae2457da1a258c918b887fee0ee7 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:10:18 +0100 Subject: [PATCH 01/10] Use WebKit on the fly Activate only when the panel is loaded, so we can eventually build the app without it --- scriptorium/__init__.py | 2 +- scriptorium/main.py | 8 ++--- scriptorium/views/editor_formatting.blp | 12 +------- scriptorium/views/editor_formatting.py | 39 ++++++++++++++++++++++--- 4 files changed, 39 insertions(+), 22 deletions(-) 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 From 403554a612787c61e13133c21d9c31a4745b8ca4 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:17:08 +0100 Subject: [PATCH 02/10] Fix placeholder names in workflow --- .github/workflows/macos-build.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 0afe41b..c474a1d 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -62,19 +62,19 @@ jobs: - name: 🧱 Create .app bundle 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/ + mkdir -p Scriptorium.app/Contents/MacOS + cp install/bin/scriptorium Scriptorium.app/Contents/MacOS/ + cp -r install/share Scriptorium.app/Contents/Resources/ # Create basic Info.plist - cat > MyApp.app/Contents/Info.plist < Scriptorium.app/Contents/Info.plist < - CFBundleNameMyApp - CFBundleIdentifiercom.example.myapp + CFBundleNameScriptorium + CFBundleIdentifierio.github.cgueret.Scriptorium CFBundleVersion${{ github.ref_name }} - CFBundleExecutablemy-gtk-app + CFBundleExecutablescriptorium CFBundlePackageTypeAPPL @@ -83,17 +83,17 @@ jobs: - name: 📀 Create DMG run: | create-dmg \ - --volname "MyApp" \ + --volname "Scriptorium" \ --window-pos 200 120 \ --window-size 800 400 \ --icon-size 100 \ - --icon "MyApp.app" 200 190 \ + --icon "Scriptorium.app" 200 190 \ --app-drop-link 600 185 \ dist/ \ - MyApp.app + Scriptorium.app - name: 📤 Upload DMG artifact uses: actions/upload-artifact@v4 with: - name: MyApp-macos-dmg + name: Scriptorium-macos-dmg path: dist/*.dmg From b9ad6e905ff3cbe8418223e938296fd92534b2a2 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:21:14 +0100 Subject: [PATCH 03/10] Typo in name --- .github/workflows/macos-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index c474a1d..1501eca 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -90,7 +90,7 @@ jobs: --icon "Scriptorium.app" 200 190 \ --app-drop-link 600 185 \ dist/ \ - Scriptorium.app + Scriptorium.dmg - name: 📤 Upload DMG artifact uses: actions/upload-artifact@v4 From 0a276896f58fbb8fa01352235ff52a8d74337576 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:25:37 +0100 Subject: [PATCH 04/10] One more try --- .github/workflows/macos-build.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 1501eca..245c2a9 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -84,13 +84,12 @@ jobs: run: | create-dmg \ --volname "Scriptorium" \ - --window-pos 200 120 \ - --window-size 800 400 \ - --icon-size 100 \ + --window-size 1000 800 \ --icon "Scriptorium.app" 200 190 \ --app-drop-link 600 185 \ - dist/ \ - Scriptorium.dmg + "Scriptorium.dmg" \ + "dist/" + - name: 📤 Upload DMG artifact uses: actions/upload-artifact@v4 From 014145d0b7c1fb10435ace12ebcccff76190ca86 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:30:26 +0100 Subject: [PATCH 05/10] Fix dmg location --- .github/workflows/macos-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 245c2a9..de204b4 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -82,12 +82,13 @@ jobs: - name: 📀 Create DMG run: | + mkdir -p dist create-dmg \ --volname "Scriptorium" \ --window-size 1000 800 \ --icon "Scriptorium.app" 200 190 \ --app-drop-link 600 185 \ - "Scriptorium.dmg" \ + "dist/Scriptorium.dmg" \ "dist/" From 1d1c509f1f71bca3ba565df434f10b77e16a23df Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:35:13 +0100 Subject: [PATCH 06/10] Clean up previous output --- .github/workflows/macos-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index de204b4..2233efc 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -83,6 +83,7 @@ jobs: - name: 📀 Create DMG run: | mkdir -p dist + rm -f dist/Scriptorium.dmg create-dmg \ --volname "Scriptorium" \ --window-size 1000 800 \ From eac1831e1df0fd9f07852f1c8079a61888ab882e Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 20:38:57 +0100 Subject: [PATCH 07/10] Copy app --- .github/workflows/macos-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 2233efc..a88fa88 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -83,6 +83,7 @@ jobs: - name: 📀 Create DMG run: | mkdir -p dist + cp -R Scriptorium.app dist/ rm -f dist/Scriptorium.dmg create-dmg \ --volname "Scriptorium" \ From dc0b7164c17ea342fb2b152ef3d3cd9291f99123 Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 21:04:37 +0100 Subject: [PATCH 08/10] Use pyinstaller --- .github/workflows/macos-build.yml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index a88fa88..982ace4 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -60,30 +60,16 @@ jobs: meson compile -C builddir meson install -C builddir - - name: 🧱 Create .app bundle + - name: ⚙️ Package it with pyinstaller run: | - mkdir -p Scriptorium.app/Contents/MacOS - cp install/bin/scriptorium Scriptorium.app/Contents/MacOS/ - cp -r install/share Scriptorium.app/Contents/Resources/ - # Create basic Info.plist - cat > Scriptorium.app/Contents/Info.plist < - - - - CFBundleNameScriptorium - CFBundleIdentifierio.github.cgueret.Scriptorium - CFBundleVersion${{ github.ref_name }} - CFBundleExecutablescriptorium - CFBundlePackageTypeAPPL - - - EOF + pyinstaller --name Scriptorium \ + --windowed \ + --add-data "builddir:." \ + install/bin/scriptorium - name: 📀 Create DMG run: | mkdir -p dist - cp -R Scriptorium.app dist/ rm -f dist/Scriptorium.dmg create-dmg \ --volname "Scriptorium" \ From e7e4ca15eceaffc1dc5e204920076c6a1307fc2b Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 21:07:04 +0100 Subject: [PATCH 09/10] Fix --- .github/workflows/macos-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 982ace4..12b2d81 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -62,10 +62,10 @@ jobs: - name: ⚙️ Package it with pyinstaller run: | - pyinstaller --name Scriptorium \ - --windowed \ - --add-data "builddir:." \ - install/bin/scriptorium + pyinstaller --name Scriptorium \ + --windowed \ + --add-data "builddir:." \ + install/bin/scriptorium - name: 📀 Create DMG run: | From b3115cab1fd617d8a8fe99dc7e5fd6ac7b8d221f Mon Sep 17 00:00:00 2001 From: Christophe Gueret Date: Fri, 6 Jun 2025 21:14:06 +0100 Subject: [PATCH 10/10] Sign the app --- .github/workflows/macos-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 12b2d81..403a24b 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -66,6 +66,7 @@ jobs: --windowed \ --add-data "builddir:." \ install/bin/scriptorium + codesign --deep --force --sign - dist/Scriptorium.app - name: 📀 Create DMG run: |