@zeppos/zeus-cli 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.ts",
6
6
  "author": "zepp",
@@ -22,7 +22,7 @@
22
22
  "qrcode-terminal": "^0.12.0",
23
23
  "vorpal": "^1.12.0",
24
24
  "yargs": "^17.7.2",
25
- "@zeppos/zpm": "^3.3.0",
25
+ "@zeppos/zpm": "^3.3.1",
26
26
  "axios": "1.8.2",
27
27
  "chalk": "^4.1.2",
28
28
  "chokidar": "^3.6.0",
@@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.logout = exports.login = void 0;
43
43
  var open_1 = __importDefault(require("./open"));
44
44
  var http_1 = __importDefault(require("http"));
45
- var url_1 = __importDefault(require("url"));
46
45
  var qs_1 = __importDefault(require("qs"));
47
46
  var lodash_1 = __importDefault(require("lodash"));
48
47
  var get_port_1 = __importDefault(require("get-port"));
@@ -59,15 +58,17 @@ var loginCallbackServer = function (cb) { return __awaiter(void 0, void 0, void
59
58
  case 1:
60
59
  port = _a.sent();
61
60
  server = (0, stoppable_1.default)(http_1.default.createServer(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
62
- var reqUrl, query, appToken, userId, cname;
61
+ var reqUrl, parsedReqUrl, appToken, userId, cname;
63
62
  return __generator(this, function (_a) {
64
63
  reqUrl = req.url || '';
65
64
  if (lodash_1.default.startsWith(reqUrl, callbackPath)) {
66
65
  res.statusCode = 200;
67
66
  res.setHeader('Content-Type', 'text/html');
68
67
  res.end("<!DOCTYPE html>\n <html lang=\"en\">\n <head> \n <meta charset=\"utf-8\"> \n <title>Login | Zepp Health</title>\n <style>html,iframe,body,div{margin: 0;padding: 0;border: 0;outline: 0;font-size: 0;vertical-align: baseline;background: transparent;}</style>\n </head> \n <body>\n <iframe src=\"https://upload-cdn.huami.com/tposts/4436118\" style=\"width: 100vw; height: 100vh;\"></iframe>\n </body>\n </html>");
69
- query = url_1.default.parse(reqUrl, true).query;
70
- appToken = query.apptoken, userId = query.userid, cname = query.cname;
68
+ parsedReqUrl = new URL("http://localhost:".concat(port).concat(reqUrl));
69
+ appToken = parsedReqUrl.searchParams.get('apptoken');
70
+ userId = parsedReqUrl.searchParams.get('userid');
71
+ cname = parsedReqUrl.searchParams.get('cname');
71
72
  cb &&
72
73
  cb({
73
74
  appToken: appToken,
@@ -163,9 +163,9 @@ var pTryEach = function (array, mapper) { return __awaiter(void 0, void 0, void
163
163
  });
164
164
  }); };
165
165
  var baseOpen = function (options) { return __awaiter(void 0, void 0, void 0, function () {
166
- var _a, app, _b, appArguments, command, cliArguments, childProcessOptions, mountPoint, encodedArguments, isBundled, exeLocalXdgOpen, _c, useSystemXdgOpen, subprocess;
167
- return __generator(this, function (_d) {
168
- switch (_d.label) {
166
+ var _a, app, _b, appArguments, command, cliArguments, childProcessOptions, _c, _d, mountPoint, encodedArguments, isBundled, exeLocalXdgOpen, _e, useSystemXdgOpen, subprocess;
167
+ return __generator(this, function (_f) {
168
+ switch (_f.label) {
169
169
  case 0:
170
170
  options = __assign({ wait: false, background: false, newInstance: false, allowNonzeroExitCode: false }, options);
171
171
  if (Array.isArray(options.app)) {
@@ -199,12 +199,24 @@ var baseOpen = function (options) { return __awaiter(void 0, void 0, void 0, fun
199
199
  if (app) {
200
200
  cliArguments.push('-a', app);
201
201
  }
202
- return [3, 10];
202
+ return [3, 13];
203
203
  case 1:
204
- if (!(platform === 'win32' || (is_wsl_1.default && !isInsideContainer() && !app))) return [3, 3];
205
- return [4, getWslDrivesMountPoint()];
204
+ _c = platform === 'win32';
205
+ if (_c) return [3, 4];
206
+ _d = is_wsl_1.default;
207
+ if (!_d) return [3, 3];
208
+ return [4, isInsideContainer()];
206
209
  case 2:
207
- mountPoint = _d.sent();
210
+ _d = !(_f.sent());
211
+ _f.label = 3;
212
+ case 3:
213
+ _c = (_d && !app);
214
+ _f.label = 4;
215
+ case 4:
216
+ if (!_c) return [3, 6];
217
+ return [4, getWslDrivesMountPoint()];
218
+ case 5:
219
+ mountPoint = _f.sent();
208
220
  command = is_wsl_1.default
209
221
  ? "".concat(mountPoint, "c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
210
222
  : "".concat(process.env.SYSTEMROOT, "\\System32\\WindowsPowerShell\\v1.0\\powershell");
@@ -230,30 +242,30 @@ var baseOpen = function (options) { return __awaiter(void 0, void 0, void 0, fun
230
242
  encodedArguments.push(appArguments.join(','));
231
243
  }
232
244
  options.target = Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');
233
- return [3, 10];
234
- case 3:
235
- if (!app) return [3, 4];
245
+ return [3, 13];
246
+ case 6:
247
+ if (!app) return [3, 7];
236
248
  command = app;
237
- return [3, 9];
238
- case 4:
249
+ return [3, 12];
250
+ case 7:
239
251
  isBundled = !__dirname || __dirname === '/';
240
252
  exeLocalXdgOpen = false;
241
- _d.label = 5;
242
- case 5:
243
- _d.trys.push([5, 7, , 8]);
253
+ _f.label = 8;
254
+ case 8:
255
+ _f.trys.push([8, 10, , 11]);
244
256
  return [4, fs_1.promises.access(localXdgOpenPath, fs_1.constants.X_OK)];
245
- case 6:
246
- _d.sent();
257
+ case 9:
258
+ _f.sent();
247
259
  exeLocalXdgOpen = true;
248
- return [3, 8];
249
- case 7:
250
- _c = _d.sent();
251
- return [3, 8];
252
- case 8:
260
+ return [3, 11];
261
+ case 10:
262
+ _e = _f.sent();
263
+ return [3, 11];
264
+ case 11:
253
265
  useSystemXdgOpen = process.versions.electron || platform === 'android' || isBundled || !exeLocalXdgOpen;
254
266
  command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
255
- _d.label = 9;
256
- case 9:
267
+ _f.label = 12;
268
+ case 12:
257
269
  if (appArguments.length > 0) {
258
270
  cliArguments.push.apply(cliArguments, appArguments);
259
271
  }
@@ -261,8 +273,8 @@ var baseOpen = function (options) { return __awaiter(void 0, void 0, void 0, fun
261
273
  childProcessOptions.stdio = 'ignore';
262
274
  childProcessOptions.detached = true;
263
275
  }
264
- _d.label = 10;
265
- case 10:
276
+ _f.label = 13;
277
+ case 13:
266
278
  if (options.target) {
267
279
  cliArguments.push(options.target);
268
280
  }
@@ -7,7 +7,7 @@
7
7
  # Refer to the usage() function below for usage.
8
8
  #
9
9
  # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
10
- # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
10
+ # Copyright 2009-2016, Rex Dieter <rdieter@fedoraproject.org>
11
11
  # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
12
12
  # Copyright 2006, Jeremy White <jwhite@codeweavers.com>
13
13
  #
@@ -35,7 +35,7 @@
35
35
 
36
36
  manualpage()
37
37
  {
38
- cat << _MANUALPAGE
38
+ cat << '_MANUALPAGE'
39
39
  Name
40
40
 
41
41
  xdg-open -- opens a file or URL in the user's preferred
@@ -58,6 +58,14 @@ Description
58
58
  xdg-open is for use inside a desktop session only. It is not
59
59
  recommended to use xdg-open as root.
60
60
 
61
+ As xdg-open can not handle arguments that begin with a "-" it
62
+ is recommended to pass filepaths in one of the following ways:
63
+ * Pass absolute paths, i.e. by using realpath as a
64
+ preprocessor.
65
+ * Prefix known relative filepaths with a "./". For example
66
+ using sed -E 's|^[^/]|./\0|'.
67
+ * Pass a file URL.
68
+
61
69
  Options
62
70
 
63
71
  --help
@@ -87,6 +95,37 @@ Exit Codes
87
95
  4
88
96
  The action failed.
89
97
 
98
+ In case of success the process launched from the .desktop file
99
+ will not be forked off and therefore may result in xdg-open
100
+ running for a very long time. This behaviour intentionally
101
+ differs from most desktop specific openers to allow terminal
102
+ based applications to run using the same terminal xdg-open was
103
+ called from.
104
+
105
+ Reporting Issues
106
+
107
+ Please keep in mind xdg-open inherits most of the flaws of its
108
+ configuration and the underlying opener.
109
+
110
+ In case the command xdg-mime query default "$(xdg-mime query
111
+ filetype path/to/troublesome_file)" names the program
112
+ responsible for any unexpected behaviour you can fix that by
113
+ setting a different handler. (If the program is broken let the
114
+ developers know)
115
+
116
+ Also see the security note on xdg-mime(1) for the default
117
+ subcommand.
118
+
119
+ If a flaw is reproducible using the desktop specific opener
120
+ (and isn't a configuration issue): Please report to whoever is
121
+ responsible for that first (reporting to xdg-utils is better
122
+ than not reporting at all, but since the xdg-utils are
123
+ maintained in very little spare time a fix will take much
124
+ longer)
125
+
126
+ In case an issue specific to xdg-open please report it to
127
+ https://gitlab.freedesktop.org/xdg/xdg-utils/-/issues .
128
+
90
129
  See Also
91
130
 
92
131
  xdg-mime(1), xdg-settings(1), MIME applications associations
@@ -108,7 +147,7 @@ _MANUALPAGE
108
147
 
109
148
  usage()
110
149
  {
111
- cat << _USAGE
150
+ cat << '_USAGE'
112
151
  xdg-open -- opens a file or URL in the user's preferred
113
152
  application
114
153
 
@@ -122,15 +161,16 @@ _USAGE
122
161
  }
123
162
 
124
163
  #@xdg-utils-common@
125
-
126
164
  #----------------------------------------------------------------------------
127
165
  # Common utility functions included in all XDG wrapper scripts
128
166
  #----------------------------------------------------------------------------
129
167
 
168
+ #shellcheck shell=sh
169
+
130
170
  DEBUG()
131
171
  {
132
172
  [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
133
- [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
173
+ [ "${XDG_UTILS_DEBUG_LEVEL}" -lt "$1" ] && return 0;
134
174
  shift
135
175
  echo "$@" >&2
136
176
  }
@@ -138,6 +178,7 @@ DEBUG()
138
178
  # This handles backslashes but not quote marks.
139
179
  first_word()
140
180
  {
181
+ # shellcheck disable=SC2162 # No -r is intended here
141
182
  read first rest
142
183
  echo "$first"
143
184
  }
@@ -147,9 +188,9 @@ first_word()
147
188
  binary_to_desktop_file()
148
189
  {
149
190
  search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
150
- binary="`which "$1"`"
151
- binary="`readlink -f "$binary"`"
152
- base="`basename "$binary"`"
191
+ binary="$(command -v "$1")"
192
+ binary="$(xdg_realpath "$binary")"
193
+ base="$(basename "$binary")"
153
194
  IFS=:
154
195
  for dir in $search; do
155
196
  unset IFS
@@ -161,11 +202,11 @@ binary_to_desktop_file()
161
202
  grep -q "^Exec.*$base" "$file" || continue
162
203
  # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
163
204
  grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
164
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
165
- command="`which "$command"`"
166
- if [ x"`readlink -f "$command"`" = x"$binary" ]; then
205
+ command="$(grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word)"
206
+ command="$(command -v "$command")"
207
+ if [ x"$(xdg_realpath "$command")" = x"$binary" ]; then
167
208
  # Fix any double slashes that got added path composition
168
- echo "$file" | sed -e 's,//*,/,g'
209
+ echo "$file" | tr -s /
169
210
  return
170
211
  fi
171
212
  done
@@ -177,7 +218,7 @@ binary_to_desktop_file()
177
218
  desktop_file_to_binary()
178
219
  {
179
220
  search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
180
- desktop="`basename "$1"`"
221
+ desktop="$(basename "$1")"
181
222
  IFS=:
182
223
  for dir in $search; do
183
224
  unset IFS
@@ -186,10 +227,10 @@ desktop_file_to_binary()
186
227
  if [ "${desktop#*-}" != "$desktop" ]; then
187
228
  vendor=${desktop%-*}
188
229
  app=${desktop#*-}
189
- if [ -r $dir/applications/$vendor/$app ]; then
190
- file_path=$dir/applications/$vendor/$app
191
- elif [ -r $dir/applnk/$vendor/$app ]; then
192
- file_path=$dir/applnk/$vendor/$app
230
+ if [ -r "$dir/applications/$vendor/$app" ]; then
231
+ file_path="$dir/applications/$vendor/$app"
232
+ elif [ -r "$dir/applnk/$vendor/$app" ]; then
233
+ file_path="$dir/applnk/$vendor/$app"
193
234
  fi
194
235
  fi
195
236
  if test -z "$file_path" ; then
@@ -203,9 +244,9 @@ desktop_file_to_binary()
203
244
  fi
204
245
  if [ -r "$file_path" ]; then
205
246
  # Remove any arguments (%F, %f, %U, %u, etc.).
206
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file_path" | cut -d= -f 2- | first_word`"
207
- command="`which "$command"`"
208
- readlink -f "$command"
247
+ command="$(grep -E "^Exec(\[[^]=]*])?=" "$file_path" | cut -d= -f 2- | first_word)"
248
+ command="$(command -v "$command")"
249
+ xdg_realpath "$command"
209
250
  return
210
251
  fi
211
252
  done
@@ -214,10 +255,11 @@ desktop_file_to_binary()
214
255
  #-------------------------------------------------------------
215
256
  # Exit script on successfully completing the desired operation
216
257
 
258
+ # shellcheck disable=SC2120 # It is okay to call this without arguments
217
259
  exit_success()
218
260
  {
219
261
  if [ $# -gt 0 ]; then
220
- echo "$@"
262
+ echo "$*"
221
263
  echo
222
264
  fi
223
265
 
@@ -233,7 +275,7 @@ exit_success()
233
275
  exit_failure_syntax()
234
276
  {
235
277
  if [ $# -gt 0 ]; then
236
- echo "xdg-open: $@" >&2
278
+ echo "xdg-open: $*" >&2
237
279
  echo "Try 'xdg-open --help' for more information." >&2
238
280
  else
239
281
  usage
@@ -249,7 +291,7 @@ exit_failure_syntax()
249
291
  exit_failure_file_missing()
250
292
  {
251
293
  if [ $# -gt 0 ]; then
252
- echo "xdg-open: $@" >&2
294
+ echo "xdg-open: $*" >&2
253
295
  fi
254
296
 
255
297
  exit 2
@@ -261,7 +303,7 @@ exit_failure_file_missing()
261
303
  exit_failure_operation_impossible()
262
304
  {
263
305
  if [ $# -gt 0 ]; then
264
- echo "xdg-open: $@" >&2
306
+ echo "xdg-open: $*" >&2
265
307
  fi
266
308
 
267
309
  exit 3
@@ -273,7 +315,7 @@ exit_failure_operation_impossible()
273
315
  exit_failure_operation_failed()
274
316
  {
275
317
  if [ $# -gt 0 ]; then
276
- echo "xdg-open: $@" >&2
318
+ echo "xdg-open: $*" >&2
277
319
  fi
278
320
 
279
321
  exit 4
@@ -285,7 +327,7 @@ exit_failure_operation_failed()
285
327
  exit_failure_file_permission_read()
286
328
  {
287
329
  if [ $# -gt 0 ]; then
288
- echo "xdg-open: $@" >&2
330
+ echo "xdg-open: $*" >&2
289
331
  fi
290
332
 
291
333
  exit 5
@@ -297,7 +339,7 @@ exit_failure_file_permission_read()
297
339
  exit_failure_file_permission_write()
298
340
  {
299
341
  if [ $# -gt 0 ]; then
300
- echo "xdg-open: $@" >&2
342
+ echo "xdg-open: $*" >&2
301
343
  fi
302
344
 
303
345
  exit 6
@@ -317,7 +359,7 @@ check_vendor_prefix()
317
359
  {
318
360
  file_label="$2"
319
361
  [ -n "$file_label" ] || file_label="filename"
320
- file=`basename "$1"`
362
+ file="$(basename "$1")"
321
363
  case "$file" in
322
364
  [[:alpha:]]*-*)
323
365
  return
@@ -340,7 +382,7 @@ check_output_file()
340
382
  exit_failure_file_permission_write "no permission to write to file '$1'"
341
383
  fi
342
384
  else
343
- DIR=`dirname "$1"`
385
+ DIR="$(dirname "$1")"
344
386
  if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
345
387
  exit_failure_file_permission_write "no permission to create file '$1'"
346
388
  fi
@@ -369,9 +411,13 @@ check_common_commands()
369
411
  ;;
370
412
 
371
413
  --version)
372
- echo "xdg-open 1.1.3"
414
+ echo "xdg-open 1.2.1"
373
415
  exit_success
374
416
  ;;
417
+
418
+ --)
419
+ [ -z "$XDG_UTILS_ENABLE_DOUBLE_HYPEN" ] || break
420
+ ;;
375
421
  esac
376
422
  done
377
423
  }
@@ -379,7 +425,8 @@ check_common_commands()
379
425
  check_common_commands "$@"
380
426
 
381
427
  [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
382
- if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
428
+ # shellcheck disable=SC2034
429
+ if [ "${XDG_UTILS_DEBUG_LEVEL-0}" -lt 1 ]; then
383
430
  # Be silent
384
431
  xdg_redirect_output=" > /dev/null 2> /dev/null"
385
432
  else
@@ -412,9 +459,8 @@ detectDE()
412
459
  KDE)
413
460
  DE=kde;
414
461
  ;;
415
- # Deepin Desktop Environments
416
462
  DEEPIN|Deepin|deepin)
417
- DE=dde;
463
+ DE=deepin;
418
464
  ;;
419
465
  LXDE)
420
466
  DE=lxde;
@@ -434,27 +480,28 @@ detectDE()
434
480
  esac
435
481
  fi
436
482
 
437
- if [ x"$DE" = x"" ]; then
483
+ # shellcheck disable=SC2153
484
+ if [ -z "$DE" ]; then
438
485
  # classic fallbacks
439
- if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
440
- elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
441
- elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
442
- elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
486
+ if [ -n "$KDE_FULL_SESSION" ]; then DE=kde;
487
+ elif [ -n "$GNOME_DESKTOP_SESSION_ID" ]; then DE=gnome;
488
+ elif [ -n "$MATE_DESKTOP_SESSION_ID" ]; then DE=mate;
489
+ elif dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1 ; then DE=gnome;
443
490
  elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
444
491
  elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
445
- elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
446
- elif [ x"$LXQT_SESSION_CONFIG" != x"" ]; then DE=lxqt;
492
+ elif echo "$DESKTOP" | grep -q '^Enlightenment'; then DE=enlightenment;
493
+ elif [ -n "$LXQT_SESSION_CONFIG" ]; then DE=lxqt;
447
494
  fi
448
495
  fi
449
496
 
450
- if [ x"$DE" = x"" ]; then
497
+ if [ -z "$DE" ]; then
451
498
  # fallback to checking $DESKTOP_SESSION
452
499
  case "$DESKTOP_SESSION" in
453
500
  gnome)
454
501
  DE=gnome;
455
502
  ;;
456
503
  LXDE|Lubuntu)
457
- DE=lxde;
504
+ DE=lxde;
458
505
  ;;
459
506
  MATE)
460
507
  DE=mate;
@@ -465,22 +512,27 @@ detectDE()
465
512
  esac
466
513
  fi
467
514
 
468
- if [ x"$DE" = x"" ]; then
515
+ if [ -z "$DE" ]; then
469
516
  # fallback to uname output for other platforms
470
- case "$(uname 2>/dev/null)" in
517
+ case "$(uname 2>/dev/null)" in
471
518
  CYGWIN*)
472
519
  DE=cygwin;
473
520
  ;;
474
521
  Darwin)
475
522
  DE=darwin;
476
523
  ;;
524
+ Linux)
525
+ grep -q microsoft /proc/version > /dev/null 2>&1 && \
526
+ command -v explorer.exe > /dev/null 2>&1 && \
527
+ DE=wsl;
528
+ ;;
477
529
  esac
478
530
  fi
479
531
 
480
532
  if [ x"$DE" = x"gnome" ]; then
481
533
  # gnome-default-applications-properties is only available in GNOME 2.x
482
534
  # but not in GNOME 3.x
483
- which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
535
+ command -v gnome-default-applications-properties > /dev/null || DE="gnome3"
484
536
  fi
485
537
 
486
538
  if [ -f "$XDG_RUNTIME_DIR/flatpak-info" ]; then
@@ -495,13 +547,13 @@ detectDE()
495
547
 
496
548
  kfmclient_fix_exit_code()
497
549
  {
498
- version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
499
- major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
500
- minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
501
- release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
502
- test "$major" -gt 3 && return $1
503
- test "$minor" -gt 5 && return $1
504
- test "$release" -gt 4 && return $1
550
+ version="$(LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE')"
551
+ major="$(echo "$version" | sed 's/KDE.*: \([0-9]\).*/\1/')"
552
+ minor="$(echo "$version" | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/')"
553
+ release="$(echo "$version" | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/')"
554
+ test "$major" -gt 3 && return "$1"
555
+ test "$minor" -gt 5 && return "$1"
556
+ test "$release" -gt 4 && return "$1"
505
557
  return 0
506
558
  }
507
559
 
@@ -517,9 +569,67 @@ has_display()
517
569
  fi
518
570
  }
519
571
 
572
+ #----------------------------------------------------------------------------
573
+ # Prefixes a path with a "./" if it starts with a "-".
574
+ # This is useful for programs to not confuse paths with options.
575
+
576
+ unoption_path()
577
+ {
578
+ case "$1" in
579
+ -*)
580
+ printf "./%s" "$1" ;;
581
+ *)
582
+ printf "%s" "$1" ;;
583
+ esac
584
+ }
585
+
586
+ #----------------------------------------------------------------------------
587
+ # Performs a symlink and relative path resolving for a single argument.
588
+ # This will always fail if the given file does not exist!
589
+
590
+ xdg_realpath()
591
+ {
592
+ # allow caching and external configuration
593
+ if [ -z "$XDG_UTILS_REALPATH_BACKEND" ] ; then
594
+ if command -v realpath >/dev/null 2>/dev/null ; then
595
+ lines="$(realpath -- / 2>&1)"
596
+ if [ $? = 0 ] && [ "$lines" = "/" ] ; then
597
+ XDG_UTILS_REALPATH_BACKEND="realpath"
598
+ else
599
+ # The realpath took the -- literally, probably the busybox implementation
600
+ XDG_UTILS_REALPATH_BACKEND="busybox-realpath"
601
+ fi
602
+ unset lines
603
+ elif command -v readlink >/dev/null 2>/dev/null ; then
604
+ XDG_UTILS_REALPATH_BACKEND="readlink"
605
+ else
606
+ exit_failure_operation_failed "No usable realpath backend found. Have a realpath binary or a readlink -f that canonicalizes paths."
607
+ fi
608
+ fi
609
+ # Always fail if the file doesn't exist (busybox realpath does that for example)
610
+ [ -e "$1" ] || return 1
611
+ case "$XDG_UTILS_REALPATH_BACKEND" in
612
+ realpath)
613
+ realpath -- "$1"
614
+ ;;
615
+ busybox-realpath)
616
+ # busybox style realpath implementations have options too
617
+ realpath "$(unoption_path "$1")"
618
+ ;;
619
+ readlink)
620
+ readlink -f "$(unoption_path "$1")"
621
+ ;;
622
+ *)
623
+ exit_failure_operation_impossible "Realpath backend '$XDG_UTILS_REALPATH_BACKEND' not recognized."
624
+ ;;
625
+ esac
626
+ }
627
+
520
628
  # This handles backslashes but not quote marks.
521
629
  last_word()
522
630
  {
631
+ # Backslash handling is intended, not using `first` too
632
+ # shellcheck disable=SC2162,SC2034
523
633
  read first rest
524
634
  echo "$rest"
525
635
  }
@@ -535,7 +645,8 @@ get_key()
535
645
 
536
646
  IFS_="${IFS}"
537
647
  IFS=""
538
- while read line
648
+ # No backslash handling here, first_word and last_word do that
649
+ while read -r line
539
650
  do
540
651
  case "$line" in
541
652
  "[Desktop Entry]")
@@ -556,26 +667,47 @@ get_key()
556
667
  IFS="${IFS_}"
557
668
  }
558
669
 
670
+ has_url_scheme()
671
+ {
672
+ echo "$1" | LC_ALL=C grep -Eq '^[[:alpha:]][[:alpha:][:digit:]+\.\-]*:'
673
+ }
674
+
559
675
  # Returns true if argument is a file:// URL or path
560
676
  is_file_url_or_path()
561
677
  {
562
- if echo "$1" | grep -q '^file://' \
563
- || ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'; then
678
+ if echo "$1" | grep -q '^file://' || ! has_url_scheme "$1" ; then
564
679
  return 0
565
680
  else
566
681
  return 1
567
682
  fi
568
683
  }
569
684
 
685
+ get_hostname() {
686
+ if [ -z "$HOSTNAME" ]; then
687
+ if command -v hostname > /dev/null; then
688
+ HOSTNAME=$(hostname)
689
+ else
690
+ HOSTNAME=$(uname -n)
691
+ fi
692
+ fi
693
+ }
694
+
570
695
  # If argument is a file URL, convert it to a (percent-decoded) path.
571
696
  # If not, leave it as it is.
572
697
  file_url_to_path()
573
698
  {
574
699
  local file="$1"
575
- if echo "$file" | grep -q '^file:///'; then
700
+ get_hostname
701
+ if echo "$file" | grep -q '^file://'; then
702
+ file=${file#file://localhost}
703
+ file=${file#file://"$HOSTNAME"}
576
704
  file=${file#file://}
705
+ if ! echo "$file" | grep -q '^/'; then
706
+ echo "$file"
707
+ return
708
+ fi
577
709
  file=${file%%#*}
578
- file=$(echo "$file" | sed -r 's/\?.*$//')
710
+ file=${file%%\?*}
579
711
  local printf=printf
580
712
  if [ -x /usr/bin/printf ]; then
581
713
  printf=/usr/bin/printf
@@ -615,9 +747,9 @@ open_kde()
615
747
  kde-open "$1"
616
748
  ;;
617
749
  5)
618
- kde-open${KDE_SESSION_VERSION} "$1"
750
+ "kde-open${KDE_SESSION_VERSION}" "$1"
619
751
  ;;
620
- *)
752
+ 6)
621
753
  kde-open "$1"
622
754
  ;;
623
755
  esac
@@ -633,7 +765,7 @@ open_kde()
633
765
  fi
634
766
  }
635
767
 
636
- open_dde()
768
+ open_deepin()
637
769
  {
638
770
  if dde-open -version >/dev/null 2>&1; then
639
771
  dde-open "$1"
@@ -739,11 +871,28 @@ open_enlightenment()
739
871
 
740
872
  open_flatpak()
741
873
  {
742
- gdbus call --session \
743
- --dest org.freedesktop.portal.Desktop \
744
- --object-path /org/freedesktop/portal/desktop \
745
- --method org.freedesktop.portal.OpenURI.OpenURI \
746
- "" "$1" {}
874
+ if is_file_url_or_path "$1"; then
875
+ local file
876
+ file="$(file_url_to_path "$1")"
877
+
878
+ check_input_file "$file"
879
+
880
+ gdbus call --session \
881
+ --dest org.freedesktop.portal.Desktop \
882
+ --object-path /org/freedesktop/portal/desktop \
883
+ --method org.freedesktop.portal.OpenURI.OpenFile \
884
+ --timeout 5 \
885
+ "" "3" {} 3< "$file"
886
+ else
887
+ # $1 contains an URI
888
+
889
+ gdbus call --session \
890
+ --dest org.freedesktop.portal.Desktop \
891
+ --object-path /org/freedesktop/portal/desktop \
892
+ --method org.freedesktop.portal.OpenURI.OpenURI \
893
+ --timeout 5 \
894
+ "" "$1" {}
895
+ fi
747
896
 
748
897
  if [ $? -eq 0 ]; then
749
898
  exit_success
@@ -755,79 +904,91 @@ open_flatpak()
755
904
  #-----------------------------------------
756
905
  # Recursively search .desktop file
757
906
 
907
+ #(application, directory, target file, target_url)
758
908
  search_desktop_file()
759
909
  {
760
910
  local default="$1"
761
911
  local dir="$2"
762
912
  local target="$3"
913
+ local target_uri="$4"
763
914
 
764
915
  local file=""
765
916
  # look for both vendor-app.desktop, vendor/app.desktop
766
917
  if [ -r "$dir/$default" ]; then
767
918
  file="$dir/$default"
768
- elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then
769
- file="$dir/`echo $default | sed -e 's|-|/|'`"
919
+ elif [ -r "$dir/$(echo "$default" | sed -e 's|-|/|')" ]; then
920
+ file="$dir/$(echo "$default" | sed -e 's|-|/|')"
770
921
  fi
771
922
 
772
923
  if [ -r "$file" ] ; then
773
924
  command="$(get_key "${file}" "Exec" | first_word)"
774
- command_exec=`which $command 2>/dev/null`
775
- icon="$(get_key "${file}" "Icon")"
776
- # FIXME: Actually LC_MESSAGES should be used as described in
777
- # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
778
- localised_name="$(get_key "${file}" "Name")"
779
- set -- $(get_key "${file}" "Exec" | last_word)
780
- # We need to replace any occurrence of "%f", "%F" and
781
- # the like by the target file. We examine each
782
- # argument and append the modified argument to the
783
- # end then shift.
784
- local args=$#
785
- local replaced=0
786
- while [ $args -gt 0 ]; do
787
- case $1 in
788
- %[c])
789
- replaced=1
790
- arg="${localised_name}"
791
- shift
792
- set -- "$@" "$arg"
793
- ;;
794
- %[fFuU])
795
- replaced=1
796
- arg="$target"
797
- shift
798
- set -- "$@" "$arg"
799
- ;;
800
- %[i])
801
- replaced=1
802
- shift
803
- set -- "$@" "--icon" "$icon"
804
- ;;
805
- *)
806
- arg="$1"
807
- shift
808
- set -- "$@" "$arg"
809
- ;;
810
- esac
811
- args=$(( $args - 1 ))
812
- done
813
- [ $replaced -eq 1 ] || set -- "$@" "$target"
814
- "$command_exec" "$@"
815
-
816
- if [ $? -eq 0 ]; then
925
+ if command -v "$command" >/dev/null; then
926
+ icon="$(get_key "${file}" "Icon")"
927
+ # FIXME: Actually LC_MESSAGES should be used as described in
928
+ # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
929
+ localised_name="$(get_key "${file}" "Name")"
930
+ #shellcheck disable=SC2046 # Splitting is intentional here
931
+ set -- $(get_key "${file}" "Exec" | last_word)
932
+ # We need to replace any occurrence of "%f", "%F" and
933
+ # the like by the target file. We examine each
934
+ # argument and append the modified argument to the
935
+ # end then shift.
936
+ local args=$#
937
+ local replaced=0
938
+ while [ $args -gt 0 ]; do
939
+ case $1 in
940
+ %[c])
941
+ replaced=1
942
+ arg="${localised_name}"
943
+ shift
944
+ set -- "$@" "$arg"
945
+ ;;
946
+ %[fF])
947
+ # if there is only a target_url return,
948
+ # this application can't handle it.
949
+ [ -n "$target" ] || return
950
+ replaced=1
951
+ arg="$target"
952
+ shift
953
+ set -- "$@" "$arg"
954
+ ;;
955
+ %[uU])
956
+ replaced=1
957
+ # When an URI is requested use it,
958
+ # otherwise fall back to the filepath.
959
+ arg="${target_uri:-$target}"
960
+ shift
961
+ set -- "$@" "$arg"
962
+ ;;
963
+ %[i])
964
+ replaced=1
965
+ shift
966
+ set -- "$@" "--icon" "$icon"
967
+ ;;
968
+ *)
969
+ arg="$1"
970
+ shift
971
+ set -- "$@" "$arg"
972
+ ;;
973
+ esac
974
+ args=$(( args - 1 ))
975
+ done
976
+ [ $replaced -eq 1 ] || set -- "$@" "${target:-$target_uri}"
977
+ env "$command" "$@"
817
978
  exit_success
818
979
  fi
819
980
  fi
820
981
 
821
- for d in $dir/*/; do
822
- [ -d "$d" ] && search_desktop_file "$default" "$d" "$target"
982
+ for d in "$dir/"*/; do
983
+ [ -d "$d" ] && search_desktop_file "$default" "$d" "$target" "$target_uri"
823
984
  done
824
985
  }
825
986
 
826
-
987
+ # (file (or empty), mimetype, optional url)
827
988
  open_generic_xdg_mime()
828
989
  {
829
990
  filetype="$2"
830
- default=`xdg-mime query default "$filetype"`
991
+ default="$(xdg-mime query default "$filetype")"
831
992
  if [ -n "$default" ] ; then
832
993
  xdg_user_dir="$XDG_DATA_HOME"
833
994
  [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
@@ -835,25 +996,23 @@ open_generic_xdg_mime()
835
996
  xdg_system_dirs="$XDG_DATA_DIRS"
836
997
  [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
837
998
 
838
- DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
839
- for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
840
- search_desktop_file "$default" "$x/applications/" "$1"
999
+ search_dirs="$xdg_user_dir:$xdg_system_dirs"
1000
+ DEBUG 3 "$search_dirs"
1001
+ old_ifs="$IFS"
1002
+ IFS=:
1003
+ for x in $search_dirs ; do
1004
+ IFS="$old_ifs"
1005
+ search_desktop_file "$default" "$x/applications/" "$1" "$3"
841
1006
  done
842
1007
  fi
843
1008
  }
844
1009
 
845
- open_generic_xdg_file_mime()
846
- {
847
- filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
848
- open_generic_xdg_mime "$1" "$filetype"
849
- }
850
-
851
1010
  open_generic_xdg_x_scheme_handler()
852
1011
  {
853
- scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
854
- if [ -n $scheme ]; then
1012
+ scheme="$(echo "$1" | LC_ALL=C sed -n 's/\(^[[:alpha:]][[:alnum:]+\.-]*\):.*$/\1/p')"
1013
+ if [ -n "$scheme" ]; then
855
1014
  filetype="x-scheme-handler/$scheme"
856
- open_generic_xdg_mime "$1" "$filetype"
1015
+ open_generic_xdg_mime "" "$filetype" "$1"
857
1016
  fi
858
1017
  }
859
1018
 
@@ -865,7 +1024,7 @@ has_single_argument()
865
1024
  open_envvar()
866
1025
  {
867
1026
  local oldifs="$IFS"
868
- local browser browser_with_arg
1027
+ local browser
869
1028
 
870
1029
  IFS=":"
871
1030
  for browser in $BROWSER; do
@@ -879,6 +1038,8 @@ open_envvar()
879
1038
  # Avoid argument injection.
880
1039
  # See https://bugs.freedesktop.org/show_bug.cgi?id=103807
881
1040
  # URIs don't have IFS characters spaces anyway.
1041
+ # shellcheck disable=SC2086,SC2091,SC2059
1042
+ # All the scary things here are intentional
882
1043
  has_single_argument $1 && $(printf "$browser" "$1")
883
1044
  else
884
1045
  $browser "$1"
@@ -890,19 +1051,41 @@ open_envvar()
890
1051
  done
891
1052
  }
892
1053
 
1054
+ open_wsl()
1055
+ {
1056
+ local win_path
1057
+ if is_file_url_or_path "$1" ; then
1058
+ win_path="$(file_url_to_path "$1")"
1059
+ win_path="$(wslpath -aw "$win_path")"
1060
+ [ $? -eq 0 ] || exit_failure_operation_failed
1061
+ explorer.exe "${win_path}"
1062
+ else
1063
+ rundll32.exe url.dll,FileProtocolHandler "$1"
1064
+ fi
1065
+
1066
+ if [ $? -eq 0 ]; then
1067
+ exit_success
1068
+ else
1069
+ exit_failure_operation_failed
1070
+ fi
1071
+ }
1072
+
893
1073
  open_generic()
894
1074
  {
895
1075
  if is_file_url_or_path "$1"; then
896
- local file="$(file_url_to_path "$1")"
1076
+ local file
1077
+ file="$(file_url_to_path "$1")"
897
1078
 
898
1079
  check_input_file "$file"
899
1080
 
900
1081
  if has_display; then
901
- filetype=`xdg-mime query filetype "$file" | sed "s/;.*//"`
902
- open_generic_xdg_mime "$file" "$filetype"
1082
+ filetype="$(xdg-mime query filetype "$file" | sed "s/;.*//")"
1083
+ # passing a path a url is okay too,
1084
+ # see desktop file specification for '%u'
1085
+ open_generic_xdg_mime "$file" "$filetype" "$1"
903
1086
  fi
904
1087
 
905
- if which run-mailcap 2>/dev/null 1>&2; then
1088
+ if command -v run-mailcap >/dev/null; then
906
1089
  run-mailcap --action=view "$file"
907
1090
  if [ $? -eq 0 ]; then
908
1091
  exit_success
@@ -929,7 +1112,7 @@ open_generic()
929
1112
  if [ x"$BROWSER" = x"" ]; then
930
1113
  BROWSER=www-browser:links2:elinks:links:lynx:w3m
931
1114
  if has_display; then
932
- BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:microsoft-edge:$BROWSER
1115
+ BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:$BROWSER
933
1116
  fi
934
1117
  fi
935
1118
 
@@ -943,7 +1126,8 @@ open_lxde()
943
1126
 
944
1127
  # pcmanfm only knows how to handle file:// urls and filepaths, it seems.
945
1128
  if pcmanfm --help >/dev/null 2>&1 && is_file_url_or_path "$1"; then
946
- local file="$(file_url_to_path "$1")"
1129
+ local file
1130
+ file="$(file_url_to_path "$1")"
947
1131
 
948
1132
  # handle relative paths
949
1133
  if ! echo "$file" | grep -q ^/; then
@@ -964,7 +1148,17 @@ open_lxde()
964
1148
 
965
1149
  open_lxqt()
966
1150
  {
967
- open_generic "$1"
1151
+ if qtxdg-mat open --help 2>/dev/null 1>&2; then
1152
+ qtxdg-mat open "$1"
1153
+ else
1154
+ exit_failure_operation_impossible "no method available for opening '$1'"
1155
+ fi
1156
+
1157
+ if [ $? -eq 0 ]; then
1158
+ exit_success
1159
+ else
1160
+ exit_failure_operation_failed
1161
+ fi
968
1162
  }
969
1163
 
970
1164
  [ x"$1" != x"" ] || exit_failure_syntax
@@ -1000,10 +1194,10 @@ fi
1000
1194
 
1001
1195
  DEBUG 2 "Selected DE $DE"
1002
1196
 
1003
- # sanitize BROWSER (avoid caling ourselves in particular)
1197
+ # sanitize BROWSER (avoid calling ourselves in particular)
1004
1198
  case "${BROWSER}" in
1005
1199
  *:"xdg-open"|"xdg-open":*)
1006
- BROWSER=$(echo $BROWSER | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')
1200
+ BROWSER="$(echo "$BROWSER" | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')"
1007
1201
  ;;
1008
1202
  "xdg-open")
1009
1203
  BROWSER=
@@ -1015,8 +1209,8 @@ case "$DE" in
1015
1209
  open_kde "$url"
1016
1210
  ;;
1017
1211
 
1018
- dde)
1019
- open_dde "$url"
1212
+ deepin)
1213
+ open_deepin "$url"
1020
1214
  ;;
1021
1215
 
1022
1216
  gnome3|cinnamon)
@@ -1059,6 +1253,10 @@ case "$DE" in
1059
1253
  open_flatpak "$url"
1060
1254
  ;;
1061
1255
 
1256
+ wsl)
1257
+ open_wsl "$url"
1258
+ ;;
1259
+
1062
1260
  generic)
1063
1261
  open_generic "$url"
1064
1262
  ;;
@@ -8,7 +8,7 @@ var Simulator = (function () {
8
8
  function Simulator(url) {
9
9
  this.previewId = 1;
10
10
  this.previewMethod = 'ide.simulator.preview';
11
- index_1.logger.info('connecting to simulator');
11
+ index_1.logger.info("connecting to simulator on ".concat(url, " ..."));
12
12
  this.socket = (0, socket_io_client_1.io)(url);
13
13
  this.socket.on('connect', function () {
14
14
  var _a;
@@ -20,6 +20,10 @@ var Simulator = (function () {
20
20
  index_1.globalStorage.set((_a = {}, _a[simulatorStorageKey.simulatorConnectStatus] = 'disconnected', _a));
21
21
  index_1.logger.error('simulator disconnected, please restart the simulator');
22
22
  });
23
+ this.socket.on('connect_error', function () {
24
+ index_1.logger.error("connect simulator failed on ".concat(url, " !"));
25
+ process.exit(1);
26
+ });
23
27
  }
24
28
  Simulator.prototype.sendMessage = function (message) {
25
29
  this.socket.send(message);
@@ -13,7 +13,7 @@
13
13
  "dev": "nodemon -e ts,tsx --exec \"rimraf dist && tsc && ts-node build.ts\" --ignore types/ --ignore dist/"
14
14
  },
15
15
  "dependencies": {
16
- "@zeppos/zpm": "^3.3.0",
16
+ "@zeppos/zpm": "^3.3.1",
17
17
  "axios": "1.8.2",
18
18
  "chalk": "^4.1.2",
19
19
  "chokidar": "^3.6.0",