| 1 |
|
| 2 |
pkg.initGettext(); |
| 3 |
pkg.initFormat(); |
| 4 |
pkg.require({ |
| 5 |
'GdkPixbuf': '2.0', |
| 6 |
'Gio': '2.0', |
| 7 |
'Gst': '1.0', |
| 8 |
'Gtk': '4.0', |
| 9 |
'Xdp': '1.0', |
| 10 |
'XdpGtk4': '1.0', |
| 11 |
}); |
| 12 |
|
| 13 |
const { Gdk, Gio, GLib, Gst, Gtk } = imports.gi; |
| 14 |
|
| 15 |
const { Application } = imports.application; |
| 16 |
|
| 17 |
function stopRunningInstance() { |
| 18 |
const bus = Gio.DBus.session; |
| 19 |
|
| 20 |
const mainloop = GLib.MainLoop.new(null, false); |
| 21 |
|
| 22 |
const watchId = bus.watch_name( |
| 23 |
'org.gnome.PortalTest.Gtk4', |
| 24 |
0, |
| 25 |
(bus, name, owner) => { |
| 26 |
log(`Name ${name} owned by ${owner}`); |
| 27 |
}, |
| 28 |
(bus, name) => { |
| 29 |
log(`Name ${name} unowned`); |
| 30 |
mainloop.quit(); |
| 31 |
}); |
| 32 |
|
| 33 |
try { |
| 34 |
bus.call_sync( |
| 35 |
'org.gnome.PortalTest.Gtk4', |
| 36 |
'/org/gnome/PortalTest/Gtk4', |
| 37 |
'org.gtk.Actions', |
| 38 |
'Activate', GLib.Variant.new_tuple([ |
| 39 |
GLib.Variant.new_string('quit'), |
| 40 |
new GLib.Variant('av', []), |
| 41 |
new GLib.Variant('a{sv}', {}), |
| 42 |
]), |
| 43 |
null, |
| 44 |
Gio.DBusCallFlags.NONE, |
| 45 |
-1, null); |
| 46 |
} catch(e) { |
| 47 |
logError(e); |
| 48 |
} |
| 49 |
|
| 50 |
mainloop.run(); |
| 51 |
|
| 52 |
bus.unwatch_name(watchId); |
| 53 |
} |
| 54 |
|
| 55 |
function main(argv) { |
| 56 |
Gst.init(null); |
| 57 |
|
| 58 |
if (argv.indexOf('--replace') !== -1) |
| 59 |
stopRunningInstance(); |
| 60 |
|
| 61 |
const application = new Application({ |
| 62 |
application_id: 'org.gnome.PortalTest.Gtk4', |
| 63 |
flags: Gio.ApplicationFlags.FLAGS_NONE, |
| 64 |
}); |
| 65 |
|
| 66 |
return application.run(argv); |
| 67 |
} |