Skip to content

Commit c84a099

Browse files
authored
Use runtime extensions instead of copying into /app (#639)
1 parent c4c16d0 commit c84a099

16 files changed

+348
-59
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SHELL:=/bin/bash -O globstar
44

55
setup:
66
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
7-
flatpak install --or-update --user --noninteractive flathub org.gnome.Sdk//45 org.gnome.Sdk.Docs//45 org.flatpak.Builder org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.node18//23.08 org.freedesktop.Sdk.Extension.vala//23.08
7+
flatpak install --or-update --user --noninteractive flathub org.gnome.Sdk//45 org.gnome.Sdk.Docs//45 org.flatpak.Builder org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.node18//23.08 org.freedesktop.Sdk.Extension.vala//23.08 org.freedesktop.Sdk.Extension.llvm16//23.08
88
npm install
99

1010
lint:
@@ -39,7 +39,7 @@ ci: setup unit lint
3939
# make sure to test without the sdk extensions installed
4040
sandbox: setup
4141
flatpak-builder --ccache --user --install --force-clean flatpak build-aux/re.sonny.Workbench.Devel.json
42-
# flatpak remove --noninteractive org.gnome.Sdk.Docs//45 org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.vala//23.08
42+
# flatpak remove --noninteractive org.gnome.Sdk.Docs//45 org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.vala//23.08 org.freedesktop.Sdk.Extension.llvm16//23.08
4343
flatpak run --command="bash" re.sonny.Workbench.Devel
4444

4545
flatpak: setup

build-aux/list-demo-blp-files.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

build-aux/re.sonny.Workbench.Devel.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
"runtime": "org.gnome.Sdk",
44
"runtime-version": "45",
55
"sdk": "org.gnome.Sdk",
6-
"separate-locales": false,
76
"sdk-extensions": [
87
"org.gnome.Sdk.Docs",
98
"org.freedesktop.Sdk.Extension.vala",
10-
"org.freedesktop.Sdk.Extension.rust-stable"
9+
"org.freedesktop.Sdk.Extension.rust-stable",
10+
"org.freedesktop.Sdk.Extension.llvm16"
1111
],
1212
"build-options": {
13-
"strip": false,
14-
"no-debuginfo": true,
1513
"append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin",
1614
"append-ld-library-path": "/usr/lib/sdk/vala/lib"
1715
},
@@ -57,14 +55,6 @@
5755
"type": "dir",
5856
"path": ".."
5957
}
60-
],
61-
"post-install": [
62-
"cp -a /usr/share/runtime/docs/doc/. /app/share/doc/",
63-
"cp -a /usr/lib/sdk/vala/bin/. /app/bin/",
64-
"cp -a /usr/lib/sdk/vala/lib/. /app/lib/",
65-
"true #cp -a /usr/lib/sdk/vala/share/. /app/share/ # org.gnome.Sdk already ships what we need",
66-
"cp -a /usr/lib/sdk/rust-stable/bin/. /app/bin/",
67-
"cp -a /usr/lib/sdk/rust-stable/lib/. /app/lib/"
6858
]
6959
}
7060
]

build-aux/re.sonny.Workbench.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
"sdk-extensions": [
77
"org.gnome.Sdk.Docs",
88
"org.freedesktop.Sdk.Extension.vala",
9-
"org.freedesktop.Sdk.Extension.rust-stable"
9+
"org.freedesktop.Sdk.Extension.rust-stable",
10+
"org.freedesktop.Sdk.Extension.llvm16"
1011
],
1112
"build-options": {
12-
"strip": false,
13-
"no-debuginfo": true,
1413
"append-path": "/usr/lib/sdk/vala/bin:/usr/lib/sdk/rust-stable/bin",
1514
"append-ld-library-path": "/usr/lib/sdk/vala/lib"
1615
},
@@ -56,14 +55,6 @@
5655
"type": "dir",
5756
"path": ".."
5857
}
59-
],
60-
"post-install": [
61-
"cp -a /usr/share/runtime/docs/doc/. /app/share/doc/",
62-
"cp -a /usr/lib/sdk/vala/bin/. /app/bin/",
63-
"cp -a /usr/lib/sdk/vala/lib/. /app/lib/",
64-
"#cp -a /usr/lib/sdk/vala/share/. /app/share/",
65-
"cp -a /usr/lib/sdk/rust-stable/bin/. /app/bin/",
66-
"cp -a /usr/lib/sdk/rust-stable/lib/. /app/lib/"
6758
]
6859
}
6960
]

data/app.gschema.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<key name="recent-code-language" type="i">
1616
<default>0</default>
1717
</key>
18+
<key name="open-extensions" type="b">
19+
<default>false</default>
20+
</key>
1821
</schema>
1922
<schema id="@[email protected]" path="/re/sonny/Workbench/">
2023
<key name="show-code" type="b">

po/POTFILES

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ src/langs/css/css.js
6363

6464
src/langs/rust/Compiler.js
6565
troll/src/async.js
66-
src/lib/prettier-estree.js
66+
src/lib/prettier-estree.js
67+
src/Extensions.blp
68+
src/Extensions.js
69+
src/Extensions/Extension.blp
70+
src/Extensions/Extension.js
71+
troll/src/gsx.js
72+
troll/src/builder.js
73+
troll/src/main.js
74+
src/Extensions/Extensions.blp
75+
src/Extensions/Extensions.js

src/DocumentationViewer.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import GLib from "gi://GLib";
55
import WebKit from "gi://WebKit";
66
import { decode } from "./util.js";
77
import resource from "./DocumentationViewer.blp";
8+
import {
9+
action_extensions,
10+
isDocumentationEnabled,
11+
} from "./Extensions/Extensions.js";
812

913
const DocumentationPage = GObject.registerClass(
1014
{
@@ -56,8 +60,6 @@ export default function DocumentationViewer({ application }) {
5660
const search_page = builder.get_object("search_page");
5761
const search_entry = builder.get_object("search_entry");
5862

59-
const base_path = Gio.File.new_for_path("/app/share/doc");
60-
6163
const user_content_manager = webview.get_user_content_manager();
6264

6365
const stylesheet = new WebKit.UserStyleSheet(
@@ -118,23 +120,26 @@ export default function DocumentationViewer({ application }) {
118120

119121
async function open() {
120122
const root_model = Gio.ListStore.new(DocumentationPage);
123+
browse_list_view.model = createBrowseSelectionModel(root_model, webview);
121124

122-
scanLibraries(root_model, base_path)
123-
.then(() => {
124-
browse_list_view.model.selected = 12;
125-
const search_model = flattenModel(root_model);
126-
filter_model.model = search_model;
127-
})
128-
.catch(console.error);
125+
await scanLibraries(root_model, Gio.File.new_for_path("/usr/share/doc"));
126+
browse_list_view.model.selected = 12;
127+
await scanLibraries(root_model, Gio.File.new_for_path("/app/share/doc"));
129128

130-
browse_list_view.model = createBrowseSelectionModel(root_model, webview);
129+
const search_model = flattenModel(root_model);
130+
filter_model.model = search_model;
131131
}
132132

133133
const action_documentation = new Gio.SimpleAction({
134134
name: "documentation",
135135
parameter_type: null,
136136
});
137137
action_documentation.connect("activate", () => {
138+
if (!isDocumentationEnabled()) {
139+
action_extensions.activate(null);
140+
return;
141+
}
142+
138143
window.present();
139144
open().catch(console.error);
140145
});

src/Extensions/Extension.blp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Gtk 4.0;
2+
3+
template $Extension : Box {
4+
orientation: vertical;
5+
6+
CenterBox {
7+
[start]
8+
Box {
9+
spacing: 4;
10+
Image image_enabled {
11+
icon-name: "test-pass-symbolic";
12+
styles ["success"]
13+
}
14+
15+
Label label_title {
16+
xalign: 0;
17+
styles [
18+
"heading"
19+
]
20+
}
21+
}
22+
23+
[end]
24+
ToggleButton toggle {
25+
icon-name: "flatpak-symbolic";
26+
styles ["flat", "circular"]
27+
}
28+
}
29+
30+
Revealer revealer {
31+
reveal-child: bind toggle.active;
32+
33+
Box {
34+
orientation: vertical;
35+
Label label_hint {
36+
margin-top: 8;
37+
xalign: 0;
38+
styles [
39+
"dim-label"
40+
]
41+
}
42+
43+
Label label_command {
44+
margin-top: 2;
45+
use-markup: true;
46+
wrap: true;
47+
selectable: true;
48+
xalign: 0;
49+
50+
styles [
51+
"code",
52+
"view",
53+
"frame",
54+
"monospace"
55+
]
56+
}
57+
}
58+
}
59+
}

src/Extensions/Extension.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import GObject from "gi://GObject";
2+
import Gtk from "gi://Gtk";
3+
4+
import Template from "./Extension.blp" with { type: "uri" };
5+
6+
export default GObject.registerClass(
7+
{
8+
GTypeName: "Extension",
9+
Template,
10+
InternalChildren: [
11+
"label_title",
12+
"image_enabled",
13+
"revealer",
14+
"toggle",
15+
"label_hint",
16+
"label_command",
17+
],
18+
Properties: {
19+
title: GObject.ParamSpec.string(
20+
"title",
21+
"",
22+
"",
23+
GObject.ParamFlags.READWRITE,
24+
"",
25+
),
26+
enabled: GObject.ParamSpec.boolean(
27+
"enabled",
28+
"",
29+
"",
30+
GObject.ParamFlags.READWRITE,
31+
false,
32+
),
33+
hint: GObject.ParamSpec.string(
34+
"hint",
35+
"",
36+
"",
37+
GObject.ParamFlags.READWRITE,
38+
"",
39+
),
40+
command: GObject.ParamSpec.string(
41+
"command",
42+
"",
43+
"",
44+
GObject.ParamFlags.READWRITE,
45+
"",
46+
),
47+
},
48+
},
49+
class Extension extends Gtk.Box {
50+
constructor(properties = {}) {
51+
super(properties);
52+
53+
this.bind_property(
54+
"title",
55+
this._label_title,
56+
"label",
57+
GObject.BindingFlags.SYNC_CREATE,
58+
);
59+
60+
this.bind_property(
61+
"enabled",
62+
this._image_enabled,
63+
"visible",
64+
GObject.BindingFlags.SYNC_CREATE,
65+
);
66+
67+
this.bind_property(
68+
"hint",
69+
this._label_hint,
70+
"label",
71+
GObject.BindingFlags.SYNC_CREATE,
72+
);
73+
74+
this.bind_property(
75+
"command",
76+
this._label_command,
77+
"label",
78+
GObject.BindingFlags.SYNC_CREATE,
79+
);
80+
81+
// FIXME: report GJS bug
82+
setTimeout(() => {
83+
this._toggle.active = !this.enabled;
84+
85+
if (!this.hint || !this.command) {
86+
this._toggle.visible = false;
87+
}
88+
}, 0);
89+
}
90+
},
91+
);

src/Extensions/Extensions.blp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.Window window {
5+
hide-on-close: true;
6+
modal: false;
7+
default-height: 700;
8+
default-width: 700;
9+
10+
Adw.ToolbarView {
11+
extend-content-to-top-edge: true;
12+
[top]
13+
Adw.HeaderBar {
14+
show-title: false;
15+
}
16+
17+
content: Adw.StatusPage {
18+
title: _("Extensions");
19+
20+
Adw.Clamp {
21+
Box {
22+
orientation: vertical;
23+
spacing: 12;
24+
25+
$Extension {
26+
title: _("JavaScript language support");
27+
enabled: true;
28+
}
29+
30+
$Extension extension_rust {
31+
title: _("Rust language support");
32+
hint: _("To enable Rust run the following command in your Console or Terminal.");
33+
command: "flatpak install flathub org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.llvm16//23.08";
34+
}
35+
36+
$Extension extension_vala {
37+
title: _("Vala language support");
38+
hint: _("To enable Vala run the following command in your Console or Terminal.");
39+
command: "flatpak install flathub org.freedesktop.Sdk.Extension.vala//23.08";
40+
}
41+
42+
$Extension extension_documentation {
43+
title: _("Documentation");
44+
hint: _("To enable documentation run the following command in your Console or Terminal.");
45+
command: "flatpak install flathub org.gnome.Sdk.Docs//45";
46+
}
47+
48+
Box {
49+
margin-top: 18;
50+
halign: center;
51+
Image {
52+
icon-name: "refresh-large-symbolic";
53+
margin-end: 12;
54+
}
55+
Label {
56+
label: "To apply changes, restart Workbench\nonce the commands have completed.";
57+
styles [
58+
"heading"
59+
]
60+
}
61+
}
62+
}
63+
}
64+
};
65+
}
66+
}

0 commit comments

Comments
 (0)