Skip to content

Commit d008ce2

Browse files
committed
extension/install: return Gio.DesktopAppInfo for installed entry
1 parent 06a42b1 commit d008ce2

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

ddterm/shell/extension.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function create_panel_icon(settings, window_matcher, app_control, icon, gettext_
136136

137137
function install(extension, rollback) {
138138
const installer = new Installer(extension.launcher_path);
139-
installer.install();
139+
const app_info = installer.install();
140140

141141
if (GObject.signal_lookup('shutdown', Shell.Global)) {
142142
const shutdown_handler = global.connect('shutdown', () => {
@@ -161,6 +161,8 @@ function install(extension, rollback) {
161161

162162
installer.uninstall();
163163
});
164+
165+
return app_info;
164166
}
165167

166168
function bind_keys(settings, app_control, rollback) {

ddterm/shell/install.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import GLib from 'gi://GLib';
77
import Gio from 'gi://Gio';
88
import Shell from 'gi://Shell';
99

10+
import Gi from 'gi';
11+
12+
function try_require(namespace, version = undefined) {
13+
try {
14+
return Gi.require(namespace, version);
15+
} catch (ex) {
16+
logError(ex);
17+
return null;
18+
}
19+
}
20+
21+
const GioUnix = GLib.check_version(2, 79, 2) === null ? try_require('GioUnix') : null;
22+
const DesktopAppInfo = GioUnix?.DesktopAppInfo ?? Gio.DesktopAppInfo;
23+
1024
class File {
1125
constructor(source_url, target_file, fallback_files = []) {
1226
const [source_file] = GLib.filename_from_uri(
@@ -26,21 +40,24 @@ class File {
2640
get_existing_content() {
2741
for (const existing_file of [this.target_file, ...this.fallback_files]) {
2842
try {
29-
return Shell.get_file_contents_utf8_sync(existing_file);
43+
return {
44+
filename: existing_file,
45+
content: Shell.get_file_contents_utf8_sync(existing_file),
46+
};
3047
} catch (ex) {
3148
if (!ex.matches(GLib.file_error_quark(), GLib.FileError.NOENT))
3249
logError(ex, `Can't read ${JSON.stringify(existing_file)}`);
3350
}
3451
}
3552

36-
return null;
53+
return { filename: this.target_file, content: null };
3754
}
3855

3956
install() {
40-
const existing_content = this.get_existing_content();
57+
const { filename, content } = this.get_existing_content();
4158

42-
if (this.content === existing_content)
43-
return false;
59+
if (this.content === content)
60+
return { filename, changed: false };
4461

4562
GLib.mkdir_with_parents(
4663
GLib.path_get_dirname(this.target_file),
@@ -56,7 +73,7 @@ class File {
5673
0o600
5774
);
5875

59-
return true;
76+
return { filename: this.target_file, changed: true };
6077
}
6178

6279
uninstall() {
@@ -109,9 +126,11 @@ export class Installer {
109126
}
110127

111128
install() {
112-
this.desktop_entry.install();
129+
const dbus_service = this.dbus_service.install();
130+
const desktop_entry = this.desktop_entry.install();
131+
const app_info = DesktopAppInfo.new_from_filename(desktop_entry.filename);
113132

114-
if (this.dbus_service.install()) {
133+
if (dbus_service.changed) {
115134
Gio.DBus.session.call(
116135
'org.freedesktop.DBus',
117136
'/org/freedesktop/DBus',
@@ -125,6 +144,8 @@ export class Installer {
125144
null
126145
);
127146
}
147+
148+
return app_info;
128149
}
129150

130151
uninstall() {

0 commit comments

Comments
 (0)