Skip to content

Commit 306e068

Browse files
authored
Meson
* refactor: 💩 meson * fix: 🎉 IT WORKSSS
1 parent 5f04a73 commit 306e068

18 files changed

+274
-63
lines changed

data/appdata/meson.build

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
appstream_file = i18n.merge_file(
2+
input: 'surf.tangent.Tangent.metainfo.xml',
3+
output: 'surf.tangent.Tangent.metainfo.xml',
4+
po_dir: '../../po',
5+
install: true,
6+
install_dir: join_paths(get_option('datadir'), 'metainfo')
7+
)
8+
9+
appstream_util = find_program('appstream-util', required: false)
10+
if appstream_util.found()
11+
test('Validate appstream file', appstream_util,
12+
args: ['validate', appstream_file]
13+
)
14+
endif

share/metainfo/surf.tangent.Tangent.metainfo.xml data/appdata/surf.tangent.Tangent.metainfo.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<name>Tangent</name>
66
<summary>Go on tangents</summary>
7-
7+
<translation type="gettext">surf.tangent.Tangent</translation>
88
<metadata_license>CC0-1.0</metadata_license>
99
<project_license>GPL-3.0-or-later</project_license>
1010

data/icons/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
install_subdir('hicolor', install_dir: join_paths(get_option('datadir'), 'icons'))

data/meson.build

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
subdir('icons')
2+
subdir('appdata')
3+
4+
service_conf = configuration_data()
5+
service_conf.set('bindir', bindir)
6+
configure_file(
7+
input: 'surf.tangent.Tangent.service',
8+
output: 'surf.tangent.Tangent.service',
9+
configuration: service_conf,
10+
install_dir: join_paths(get_option('datadir'), 'dbus-1/services')
11+
)
12+
13+
desktop_file = i18n.merge_file(
14+
input: 'surf.tangent.Tangent.desktop',
15+
output: 'surf.tangent.Tangent.desktop',
16+
type: 'desktop',
17+
po_dir: '../po',
18+
install: true,
19+
install_dir: join_paths(get_option('datadir'), 'applications')
20+
)
21+
22+
desktop_utils = find_program('desktop-file-validate', required: false)
23+
if desktop_utils.found()
24+
test('Validate desktop file', desktop_utils,
25+
args: [desktop_file]
26+
)
27+
endif
28+
29+
install_data('surf.tangent.Tangent.gschema.xml',
30+
install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
31+
)
32+
33+
compile_schemas = find_program('glib-compile-schemas', required: false)
34+
if compile_schemas.found()
35+
test('Validate schema file', compile_schemas,
36+
args: ['--strict', '--dry-run', meson.current_source_dir()]
37+
)
38+
endif

data/surf.tangent.Tangent.desktop

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Desktop Entry]
2+
Name=Tangent
3+
GenericName=Web Browser
4+
Comment=Go on tangents
5+
Exec=surf.tangent.Tangent
6+
Terminal=false
7+
Type=Application
8+
Categories=Network;WebBrowser;GNOME;GTK;
9+
StartupNotify=true
10+
X-GNOME-UsesNotifications=true
11+
Icon=surf.tangent.Tangent
12+
DBusActivatable=true

data/surf.tangent.Tangent.gschema.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<schemalist gettext-domain="surf.tangent.Tangent">
3+
4+
</schemalist>

data/surf.tangent.Tangent.service

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[D-BUS Service]
2+
Name=surf.tangent.Tangent
3+
Exec=@bindir@/surf.tangent.Tangent --gapplication-service

flake.nix

+14-31
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@
2525
pname = "tangent";
2626
version = "0.0.1";
2727
src = self;
28-
nativeBuildInputs = [ pkgs.gjs pkgs.gobject-introspection pkgs.wrapGAppsHook pkgs.blueprint-compiler ];
28+
nativeBuildInputs = [
29+
pkgs.gjs
30+
pkgs.wrapGAppsHook
31+
pkgs.blueprint-compiler
32+
pkgs.meson
33+
pkgs.ninja
34+
pkgs.desktop-file-utils
35+
];
36+
enableParallelBuilding = true;
2937
buildInputs = [
3038
pkgs.gjs
3139
pkgs.gtk4
3240
pkgs.libadwaita
3341
pkgs.libsoup_3
34-
pkgs.gobject-introspection
3542
pkgs.webkitgtk_6_0
3643
pkgs.glib-networking
3744
pkgs.p11-kit
@@ -43,21 +50,12 @@
4350
pkgs.gst_all_1.gstreamer
4451
];
4552
dontPatchShebangs = true;
46-
buildPhase = ''
47-
ln --symbolic ${troll} ./src/troll
48-
mkdir $out
49-
export version="${finalAttrs.version}"
50-
export comments="${description}"
51-
export homepage="${finalAttrs.meta.homepage}"
52-
substituteAllInPlace ./src/main.js
53-
gjs --module ${troll}/gjspack/bin/gjspack ${lib.cli.toGNUCommandLineShell {} {
54-
inherit appid;
55-
import-map = "./src/import_map.json";
56-
resource-root="./src";
57-
}} ./src/main.js $out/bin
58-
sed --in-place "1s/.*/#!${lib.strings.escape ["/"] (lib.getExe pkgs.gjs)} --module/" $out/bin/${appid}
59-
cp --recursive ./share $out/share
53+
inherit troll;
54+
postPatch = ''
55+
cp --recursive $troll ./src/troll
56+
substituteInPlace src/bin.js src/troll/gjspack/bin/gjspack --replace-fail "#!/usr/bin/env -S gjs -m" "#!${pkgs.gjs}/bin/gjs --module"
6057
'';
58+
postInstall = ''chmod +x $out/bin/${appid}'';
6159
meta = {
6260
mainProgram = appid;
6361
description = description;
@@ -66,21 +64,6 @@
6664
longDescription = builtins.readFile ./README.md;
6765
changelog = "https://github.com/mollersuite/tangent/releases/tag/v${finalAttrs.version}";
6866
};
69-
desktopItem = pkgs.makeDesktopItem {
70-
name = appid; # Filename, not display name
71-
icon = appid;
72-
exec = "${appid} %u";
73-
desktopName = "Tangent";
74-
genericName = "Web Browser";
75-
categories = [ "GNOME" ];
76-
keywords = [ "Etcetera" ];
77-
comment = description;
78-
# TODO
79-
dbusActivatable = true;
80-
startupNotify = true;
81-
};
82-
83-
postInstall = "cp -r $desktopItem/* $out";
8467
});
8568
};
8669
};

meson.build

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
project('Tangent',
2+
version: '1.0',
3+
meson_version: '>= 0.59.0',
4+
license: 'GPL-3.0-only'
5+
)
6+
7+
gnome = import('gnome')
8+
i18n = import('i18n')
9+
10+
app_id = 'surf.tangent.Tangent'
11+
prefix = get_option('prefix')
12+
bindir = join_paths(prefix, 'bin')
13+
datadir = join_paths(prefix, get_option('datadir'))
14+
pkgdatadir = join_paths(datadir, app_id)
15+
16+
subdir('data')
17+
subdir('src')
18+
subdir('po')
19+
20+
gnome.post_install(
21+
glib_compile_schemas: true,
22+
gtk_update_icon_cache: true,
23+
update_desktop_database: true
24+
)

po/LINGUAS

Whitespace-only changes.

po/POTFILES

Whitespace-only changes.

po/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i18n.gettext(meson.project_name(), preset: 'glib', args: ['--no-wrap'])

src/bin.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env -S gjs -m
2+
/// <reference types="gjs/dom" />
3+
4+
import { exit, programArgs, programInvocationName } from "system"
5+
import { setConsoleLogDomain } from "console"
6+
import Gio from "gi://Gio?version=2.0"
7+
8+
imports.package.init({
9+
name: "@app_id@",
10+
version: "@version@",
11+
prefix: "@prefix@",
12+
libdir: "@libdir@",
13+
datadir: "@datadir@",
14+
})
15+
16+
imports.package._findEffectiveEntryPointName = () => "@app_id@" // https://github.com/NixOS/nixpkgs/issues/31168#issuecomment-341793501
17+
18+
setConsoleLogDomain(pkg.name)
19+
20+
const resource = Gio.resource_load("@datadir@/@app_id@/Tangent.src.gresource")
21+
Gio.resources_register(resource)
22+
23+
const { main } = await import("resource:///Tangent/src/main.js")
24+
const exit_code = await main([programInvocationName, ...programArgs])
25+
exit(exit_code)

src/main.js

+86-31
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,33 @@ import GLib from "gi://GLib"
88
import { programArgs, programInvocationName } from "system"
99
import { build } from "troll"
1010
import "troll/globals.js"
11-
import Interface from "./window.blp" with { type: "uri" }
12-
import meta from "../share/metainfo/surf.tangent.Tangent.metainfo.xml" with {type: "uri"}
13-
11+
import Interface from "./window.blp" assert { type: "uri" }
12+
//import meta from "../share/metainfo/surf.tangent.Tangent.metainfo.xml" assert { type: "uri" }
13+
// import Preferences from "./settings.js"
14+
// imports.package.init({
15+
// name: "@app_id@",
16+
// version: "@version@",
17+
// prefix: "@prefix@",
18+
// libdir: "@libdir@",
19+
// datadir: "@datadir@",
20+
// })
1421
GLib.set_application_name("Tangent")
1522

23+
/**
24+
* @param {string} fail_url
25+
* @param {string} msg
26+
*/
27+
function error_page(fail_url, msg) {
28+
const error = `
29+
<meta name="color-scheme" content="dark light">
30+
<div style="text-align:center; margin:24px;">
31+
<h2>An error occurred while loading ${fail_url}</h2>
32+
<p>${msg}</p>
33+
</div>
34+
`
35+
return error
36+
}
37+
1638
const Tangent = GObject.registerClass(
1739
{},
1840
class Tangent extends Adw.Application {
@@ -26,19 +48,27 @@ const Tangent = GObject.registerClass(
2648
vfunc_startup() {
2749
super.vfunc_startup()
2850

29-
const about_action = new Gio.SimpleAction({
51+
const about = new Gio.SimpleAction({
3052
name: "about",
31-
parameterType: null
53+
parameterType: null,
3254
})
33-
about_action.connect("activate", () => {
55+
about.connect("activate", () => {
3456
const about = Adw.AboutWindow.new_from_appdata(
35-
meta.replace("resource://", ""),
36-
""
57+
meta.replace("resource://", ""),
58+
""
3759
)
38-
about.set_transient_for(this.get_active_window())
60+
about.set_transient_for(this.get_active_window())
3961
about.present()
4062
})
41-
this.add_action(about_action)
63+
this.add_action(about)
64+
const preferences = new Gio.SimpleAction({
65+
name: "preferences",
66+
parameterType: null,
67+
})
68+
preferences.connect("activate", () =>
69+
Preferences(this.get_active_window())
70+
)
71+
this.add_action(preferences)
4272
}
4373

4474
vfunc_activate() {
@@ -51,34 +81,59 @@ const Tangent = GObject.registerClass(
5181
window.present()
5282
window.connect("close-request", win => win.run_dispose())
5383
const webview = new WebKit2.WebView({
54-
settings:
55-
new WebKit2.Settings({
56-
enableDeveloperExtras: true
57-
})
58-
84+
settings: new WebKit2.Settings({
85+
enableDeveloperExtras: true,
86+
// enableCaretBrowsing: true,
87+
enableHyperlinkAuditing: false,
88+
}),
5989
})
6090

61-
6291
content.append(webview)
6392
webview.vexpand = true
6493
webview.hexpand = true
65-
webview.load_uri("https://tangent.surf")
94+
webview.load_uri("https://duckduckgo.com/lite")
6695
webview.bind_property(
67-
"uri",
68-
urlbar.buffer,
69-
"text",
70-
GObject.BindingFlags.DEFAULT,
71-
);
72-
webview.connect("notify::estimated-load-progress", () => {
73-
urlbar.progressFraction = webview.estimatedLoadProgress;
74-
if (urlbar.progressFraction === 1) {
75-
setTimeout(() => {
76-
urlbar.progressFraction = 0;
77-
}, 500);
78-
}
79-
});
96+
"uri",
97+
urlbar.buffer,
98+
"text",
99+
GObject.BindingFlags.DEFAULT
100+
)
101+
webview.connect("notify::estimated-load-progress", () => {
102+
urlbar.progressFraction = webview.estimatedLoadProgress
103+
if (urlbar.progressFraction === 1) {
104+
setTimeout(() => {
105+
urlbar.progressFraction = 0
106+
}, 500)
107+
}
108+
})
109+
webview.connect("load-failed", (_self, _load_event, fail_url, error) => {
110+
// Loading failed as a result of calling stop_loading
111+
if (
112+
error.matches(WebKit2.NetworkError, WebKit2.NetworkError.CANCELLED)
113+
) {
114+
return
115+
}
116+
webview.load_alternate_html(
117+
error_page(fail_url, error.message),
118+
fail_url,
119+
null
120+
)
121+
})
122+
urlbar.connect("activate", () => {
123+
let url = urlbar.buffer.text
124+
const scheme = GLib.Uri.peek_scheme(url)
125+
if (!scheme) {
126+
url = `https://${url}`
127+
}
128+
webview.load_uri(url)
129+
})
80130
}
81131
}
82132
)
83133

84-
new Tangent().run([programInvocationName].concat(programArgs))
134+
135+
export function main(argv = []) {
136+
const application = new Tangent()
137+
return application.runAsync(argv)
138+
}
139+
// new Tangent().run([programInvocationName].concat(programArgs))

src/meson.build

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
bin_conf = configuration_data()
2+
bin_conf.set('GJS', find_program('gjs').full_path())
3+
bin_conf.set('version', meson.project_version())
4+
bin_conf.set('app_id', app_id)
5+
bin_conf.set('prefix', prefix)
6+
bin_conf.set('libdir', join_paths(get_option('prefix'), get_option('libdir')))
7+
bin_conf.set('datadir', datadir)
8+
bin_conf.set('pkgdatadir', pkgdatadir)
9+
10+
configure_file(
11+
input: 'bin.js',
12+
output: 'surf.tangent.Tangent',
13+
configuration: bin_conf,
14+
install: true,
15+
install_dir: get_option('bindir')
16+
)
17+
18+
gresource = custom_target('gjspack',
19+
input: ['main.js', '../po/POTFILES'],
20+
output: meson.project_name() + '.src.gresource',
21+
command: [
22+
'../src/troll/gjspack/bin/gjspack',
23+
'--appid=' + meson.project_name(),
24+
'--project-root', meson.source_root(),
25+
'--resource-root', meson.project_source_root(),
26+
'--import-map', '../src/import_map.json',
27+
'@INPUT0@',
28+
'--potfiles', '@INPUT1@',
29+
'@OUTDIR@',
30+
],
31+
install: true,
32+
install_dir: pkgdatadir,
33+
build_always_stale: true,
34+
)

0 commit comments

Comments
 (0)