Skip to content

Commit 3e95644

Browse files
authored
Merge pull request #20 from cgueret/19-package-the-application-for-macos
19 package the application for macos
2 parents 4eb60cf + b3115ca commit 3e95644

File tree

5 files changed

+54
-48
lines changed

5 files changed

+54
-48
lines changed

.github/workflows/macos-build.yml

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,29 @@ jobs:
6060
meson compile -C builddir
6161
meson install -C builddir
6262
63-
- name: 🧱 Create .app bundle
63+
- name: ⚙️ Package it with pyinstaller
6464
run: |
65-
mkdir -p MyApp.app/Contents/MacOS
66-
cp install/bin/my-gtk-app MyApp.app/Contents/MacOS/
67-
cp -r install/share MyApp.app/Contents/Resources/
68-
# Create basic Info.plist
69-
cat > MyApp.app/Contents/Info.plist <<EOF
70-
<?xml version="1.0" encoding="UTF-8"?>
71-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
72-
<plist version="1.0">
73-
<dict>
74-
<key>CFBundleName</key><string>MyApp</string>
75-
<key>CFBundleIdentifier</key><string>com.example.myapp</string>
76-
<key>CFBundleVersion</key><string>${{ github.ref_name }}</string>
77-
<key>CFBundleExecutable</key><string>my-gtk-app</string>
78-
<key>CFBundlePackageType</key><string>APPL</string>
79-
</dict>
80-
</plist>
81-
EOF
65+
pyinstaller --name Scriptorium \
66+
--windowed \
67+
--add-data "builddir:." \
68+
install/bin/scriptorium
69+
codesign --deep --force --sign - dist/Scriptorium.app
8270
8371
- name: 📀 Create DMG
8472
run: |
73+
mkdir -p dist
74+
rm -f dist/Scriptorium.dmg
8575
create-dmg \
86-
--volname "MyApp" \
87-
--window-pos 200 120 \
88-
--window-size 800 400 \
89-
--icon-size 100 \
90-
--icon "MyApp.app" 200 190 \
76+
--volname "Scriptorium" \
77+
--window-size 1000 800 \
78+
--icon "Scriptorium.app" 200 190 \
9179
--app-drop-link 600 185 \
92-
dist/ \
93-
MyApp.app
80+
"dist/Scriptorium.dmg" \
81+
"dist/"
82+
9483
9584
- name: 📤 Upload DMG artifact
9685
uses: actions/upload-artifact@v4
9786
with:
98-
name: MyApp-macos-dmg
87+
name: Scriptorium-macos-dmg
9988
path: dist/*.dmg

scriptorium/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
import gi
33
gi.require_version("Gtk", "4.0")
44
gi.require_version("Adw", "1")
5-
gi.require_version("WebKit", "6.0")
65
gi.require_version("Tsparql", "3.0")
6+
gi.require_version("WebKit", "6.0")
77

scriptorium/main.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# SPDX-License-Identifier: GPL-3.0-or-later
1919
import sys
2020
from scriptorium.widgets.multiline_entry_row import MultiLineEntryRow
21-
from gi.repository import Gio, Adw, WebKit, GLib
21+
from gi.repository import Gio, Adw, GLib
2222
from .window import ScrptWindow
2323
import logging
2424

@@ -54,11 +54,7 @@ def __init__(self):
5454
current_value = self.settings.get_string("style-variant")
5555
style_variant_action.activate(GLib.Variant('s', current_value))
5656

57-
# Force loading WebKit, otherwise it is not recognized in Builder
58-
dummy = WebKit.WebView()
59-
del dummy
60-
61-
# Same for MultiLineEntryRow
57+
# Force loading MultiLineEntryRow, otherwise it is not recognized in Builder
6258
dummy = MultiLineEntryRow()
6359
del dummy
6460

scriptorium/views/editor_formatting.blp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Gtk 4.0;
22
using Adw 1;
3-
using WebKit 6.0;
43

54
template $ScrptFormattingPanel: Adw.NavigationPage {
65
title: "Formatting";
@@ -76,19 +75,10 @@ template $ScrptFormattingPanel: Adw.NavigationPage {
7675
margin-start: 12;
7776
margin-end: 12;
7877

79-
Box {
78+
Box web_view_placeholder {
8079
styles [
8180
"card",
8281
]
83-
WebKit.WebView web_view {
84-
zoom-level: 1;
85-
vexpand: true;
86-
hexpand: true;
87-
margin-start: 6;
88-
margin-end: 6;
89-
margin-top: 6;
90-
margin-bottom: 6;
91-
}
9282
}
9383
}
9484
};

scriptorium/views/editor_formatting.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
#
1818
# SPDX-License-Identifier: GPL-3.0-or-later
1919

20-
from gi.repository import Adw, Gtk, Gio, GObject
20+
import logging
21+
from gi.repository import Adw, Gtk, Gio
2122
from scriptorium.models import Chapter
2223
from scriptorium.globals import BASE
23-
import logging
24+
25+
try:
26+
from gi.repository import WebKit
27+
HAVE_WEBKIT = True
28+
except ImportError:
29+
HAVE_WEBKIT = False
2430

2531
logger = logging.getLogger(__name__)
2632

@@ -33,7 +39,7 @@ class ScrptFormattingPanel(Adw.NavigationPage):
3339
__icon_name__ = "open-book-symbolic"
3440
__description__ = "Preview and modify the formatting"
3541

36-
web_view = Gtk.Template.Child()
42+
web_view_placeholder = Gtk.Template.Child()
3743
button_next = Gtk.Template.Child()
3844
button_previous = Gtk.Template.Child()
3945
chapters_drop_down = Gtk.Template.Child()
@@ -42,6 +48,29 @@ def __init__(self, editor, **kwargs):
4248
super().__init__(**kwargs)
4349
self._editor = editor
4450

51+
# If we have WebKit set the component, otherwise show placeholder
52+
if HAVE_WEBKIT:
53+
logger.info("Webkit is available")
54+
self.web_view = WebKit.WebView()
55+
self.web_view.set_zoom_level(1)
56+
self.web_view.set_margin_start(6)
57+
self.web_view.set_margin_end(6)
58+
self.web_view.set_margin_top(6)
59+
self.web_view.set_margin_bottom(6)
60+
self.web_view.set_vexpand(True)
61+
self.web_view.set_hexpand(True)
62+
self.web_view_placeholder.append(self.web_view)
63+
else:
64+
widget = Adw.StatusPage(
65+
title = "Not available",
66+
icon_name = "process-stop-symbolic",
67+
description = "This feature is not available on your operating system"
68+
)
69+
widget.set_vexpand(True)
70+
widget.set_hexpand(True)
71+
self.web_view_placeholder.append(widget)
72+
73+
4574
self.chapters_drop_down.connect(
4675
"notify::selected-item",
4776
self.on_selected_item
@@ -57,6 +86,7 @@ def __init__(self, editor, **kwargs):
5786

5887
self._position = 0
5988

89+
6090
def on_selected_item(self, _drop_down, _selected_item):
6191
selected_chapter = _drop_down.get_selected_item()
6292
if selected_chapter is None:
@@ -77,7 +107,8 @@ def on_selected_item(self, _drop_down, _selected_item):
77107
html_content = html_content.replace("{content}", content)
78108

79109
# Load the content
80-
self.web_view.load_html(html_content)
110+
if HAVE_WEBKIT:
111+
self.web_view.load_html(html_content)
81112

82113
# Find the position of the chapter
83114
chapters = self._editor.project.manuscript.chapters

0 commit comments

Comments
 (0)