[gnome-shell/benzea/use-app-info-launch: 1/2] util: Add new trySpawnAppCommandline function
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/benzea/use-app-info-launch: 1/2] util: Add new trySpawnAppCommandline function
- Date: Fri, 31 Jul 2020 13:51:30 +0000 (UTC)
commit 1bd4845fdd3b1d6e15bddc1c64d3267d4a653c95
Author: Benjamin Berg <bberg redhat com>
Date: Fri Jul 31 15:28:34 2020 +0200
util: Add new trySpawnAppCommandline function
The old spawnApp function was never used, but a similar function
trySpawnAppCommandline is useful for the Alt+F2 dialog.
So remove the old function, replacing it with a new version that can be
used for the purposes of Alt+F2
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1384
js/misc/util.js | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index 314d7660f6..5e5e274f2e 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -1,7 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported findUrls, spawn, spawnCommandLine, spawnApp, trySpawnCommandLine,
- formatTime, formatTimeSpan, createTimeLabel, insertSorted,
- ensureActorVisibleInScrollView, wiggle */
+/* exported findUrls, spawn, spawnCommandLine, trySpawnAppCommandline,
+ trySpawnCommandLine, formatTime, formatTimeSpan, createTimeLabel,
+ insertSorted, ensureActorVisibleInScrollView, wiggle */
const { Clutter, Gio, GLib, Shell, St, GnomeDesktop } = imports.gi;
const Gettext = imports.gettext;
@@ -90,15 +90,30 @@ function spawnCommandLine(commandLine) {
// @argv: an argv array
//
// Runs @argv as if it was an application, handling startup notification
-function spawnApp(argv) {
- try {
- let app = Gio.AppInfo.create_from_commandline(argv.join(' '), null,
- Gio.AppInfoCreateFlags.SUPPORTS_STARTUP_NOTIFICATION);
+function trySpawnAppCommandline(command) {
+ let quoted = command.replace(/%/, '%%');
+
+ // This cannot fail currently
+ let app = Gio.AppInfo.create_from_commandline(quoted, null,
+ Gio.AppInfoCreateFlags.SUPPORTS_STARTUP_NOTIFICATION);
+
+ // Launching applications does not check whether the executable exists,
+ // it'll just log an error later on. So do an explicit check here.
+ let exec = app.get_executable();
+ if (!GLib.find_program_in_path(exec)) {
+ throw new GLib.SpawnError({ code: GLib.SpawnError.NOENT,
+ message: _("Command not found") });
+ }
+ try {
let context = global.create_app_launch_context(0, -1);
+
app.launch([], context);
} catch (err) {
- _handleSpawnError(argv[0], err);
+ // Replace "Error invoking GLib.shell_parse_argv: " with
+ // something nicer
+ err.message = err.message.replace(/[^:]*: /, '%s\n'.format(_('Could not parse command:')));
+ throw err;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]