2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported findUrls, spawn, spawnCommandLine, spawnApp, trySpawnCommandLine,
|
|
|
|
formatTime, formatTimeSpan, createTimeLabel, insertSorted,
|
2021-06-16 17:09:42 +00:00
|
|
|
ensureActorVisibleInScrollView, wiggle, lerp, GNOMEversionCompare,
|
|
|
|
DBusSenderChecker */
|
2010-10-03 19:48:56 +00:00
|
|
|
|
2020-06-02 14:16:36 +00:00
|
|
|
const { Clutter, Gio, GLib, Shell, St, GnomeDesktop } = imports.gi;
|
2017-02-27 01:17:29 +00:00
|
|
|
const Gettext = imports.gettext;
|
2010-11-17 16:43:08 +00:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
2015-02-25 15:43:59 +00:00
|
|
|
const Params = imports.misc.params;
|
2013-03-11 17:43:38 +00:00
|
|
|
|
2019-08-01 23:13:10 +00:00
|
|
|
var SCROLL_TIME = 100;
|
2010-11-17 16:43:08 +00:00
|
|
|
|
2020-01-21 09:32:59 +00:00
|
|
|
const WIGGLE_OFFSET = 6;
|
|
|
|
const WIGGLE_DURATION = 65;
|
|
|
|
const N_WIGGLES = 3;
|
|
|
|
|
2011-04-13 13:18:00 +00:00
|
|
|
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
2018-02-27 12:20:02 +00:00
|
|
|
const _balancedParens = '\\([^\\s()<>]+\\)';
|
2011-04-13 13:40:28 +00:00
|
|
|
const _leadingJunk = '[\\s`(\\[{\'\\"<\u00AB\u201C\u2018]';
|
2019-09-13 22:03:02 +00:00
|
|
|
const _notTrailingJunk = '[^\\s`!()\\[\\]{};:\'\\".,<>?\u00AB\u00BB\u200E\u200F\u201C\u201D\u2018\u2019\u202A\u202C]';
|
2011-04-13 13:18:00 +00:00
|
|
|
|
|
|
|
const _urlRegexp = new RegExp(
|
2020-02-14 15:10:34 +00:00
|
|
|
'(^|%s)'.format(_leadingJunk) +
|
2011-04-13 13:40:28 +00:00
|
|
|
'(' +
|
2011-04-13 13:18:00 +00:00
|
|
|
'(?:' +
|
2013-04-14 20:15:04 +00:00
|
|
|
'(?:http|https|ftp)://' + // scheme://
|
2011-04-13 13:18:00 +00:00
|
|
|
'|' +
|
|
|
|
'www\\d{0,3}[.]' + // www.
|
|
|
|
'|' +
|
|
|
|
'[a-z0-9.\\-]+[.][a-z]{2,4}/' + // foo.xx/
|
|
|
|
')' +
|
|
|
|
'(?:' + // one or more:
|
|
|
|
'[^\\s()<>]+' + // run of non-space non-()
|
|
|
|
'|' + // or
|
2020-02-14 15:10:34 +00:00
|
|
|
'%s'.format(_balancedParens) + // balanced parens
|
2011-04-13 13:18:00 +00:00
|
|
|
')+' +
|
|
|
|
'(?:' + // end with:
|
2020-02-14 15:10:34 +00:00
|
|
|
'%s'.format(_balancedParens) + // balanced parens
|
2011-04-13 13:18:00 +00:00
|
|
|
'|' + // or
|
2020-02-14 15:10:34 +00:00
|
|
|
'%s'.format(_notTrailingJunk) + // last non-junk char
|
2011-04-13 13:18:00 +00:00
|
|
|
')' +
|
|
|
|
')', 'gi');
|
2010-10-03 19:48:56 +00:00
|
|
|
|
2015-02-25 15:43:59 +00:00
|
|
|
let _desktopSettings = null;
|
|
|
|
|
2010-10-03 19:48:56 +00:00
|
|
|
// findUrls:
|
|
|
|
// @str: string to find URLs in
|
|
|
|
//
|
|
|
|
// Searches @str for URLs and returns an array of objects with %url
|
|
|
|
// properties showing the matched URL string, and %pos properties indicating
|
|
|
|
// the position within @str where the URL was found.
|
|
|
|
//
|
|
|
|
// Return value: the list of match objects, as described above
|
|
|
|
function findUrls(str) {
|
|
|
|
let res = [], match;
|
|
|
|
while ((match = _urlRegexp.exec(str)))
|
2011-04-13 13:40:28 +00:00
|
|
|
res.push({ url: match[2], pos: match.index + match[1].length });
|
2010-10-03 19:48:56 +00:00
|
|
|
return res;
|
|
|
|
}
|
2010-11-17 16:43:08 +00:00
|
|
|
|
|
|
|
// spawn:
|
|
|
|
// @argv: an argv array
|
|
|
|
//
|
|
|
|
// Runs @argv in the background, handling any errors that occur
|
|
|
|
// when trying to start the program.
|
|
|
|
function spawn(argv) {
|
|
|
|
try {
|
|
|
|
trySpawn(argv);
|
|
|
|
} catch (err) {
|
|
|
|
_handleSpawnError(argv[0], err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// spawnCommandLine:
|
2019-01-31 13:43:52 +00:00
|
|
|
// @commandLine: a command line
|
2010-11-17 16:43:08 +00:00
|
|
|
//
|
2019-01-31 13:43:52 +00:00
|
|
|
// Runs @commandLine in the background, handling any errors that
|
2010-11-17 16:43:08 +00:00
|
|
|
// occur when trying to parse or start the program.
|
2019-01-31 13:43:52 +00:00
|
|
|
function spawnCommandLine(commandLine) {
|
2010-11-17 16:43:08 +00:00
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [success_, argv] = GLib.shell_parse_argv(commandLine);
|
2010-11-17 16:43:08 +00:00
|
|
|
trySpawn(argv);
|
|
|
|
} catch (err) {
|
2019-01-31 13:43:52 +00:00
|
|
|
_handleSpawnError(commandLine, err);
|
2010-11-17 16:43:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 17:39:58 +00:00
|
|
|
// spawnApp:
|
|
|
|
// @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);
|
|
|
|
|
2014-01-19 17:34:32 +00:00
|
|
|
let context = global.create_app_launch_context(0, -1);
|
2017-07-15 01:42:06 +00:00
|
|
|
app.launch([], context);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (err) {
|
2013-10-02 17:39:58 +00:00
|
|
|
_handleSpawnError(argv[0], err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 16:43:08 +00:00
|
|
|
// trySpawn:
|
|
|
|
// @argv: an argv array
|
|
|
|
//
|
|
|
|
// Runs @argv in the background. If launching @argv fails,
|
|
|
|
// this will throw an error.
|
2019-01-29 21:02:57 +00:00
|
|
|
function trySpawn(argv) {
|
2019-01-31 14:08:00 +00:00
|
|
|
var success_, pid;
|
2010-11-17 16:43:08 +00:00
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
[success_, pid] = GLib.spawn_async(null, argv, null,
|
|
|
|
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
|
|
|
null);
|
2010-11-17 16:43:08 +00:00
|
|
|
} catch (err) {
|
2012-06-19 21:32:45 +00:00
|
|
|
/* Rewrite the error in case of ENOENT */
|
|
|
|
if (err.matches(GLib.SpawnError, GLib.SpawnError.NOENT)) {
|
|
|
|
throw new GLib.SpawnError({ code: GLib.SpawnError.NOENT,
|
|
|
|
message: _("Command not found") });
|
|
|
|
} else if (err instanceof GLib.Error) {
|
2011-01-27 20:26:58 +00:00
|
|
|
// The exception from gjs contains an error string like:
|
|
|
|
// Error invoking GLib.spawn_command_line_async: Failed to
|
|
|
|
// execute child process "foo" (No such file or directory)
|
|
|
|
// We are only interested in the part in the parentheses. (And
|
|
|
|
// we can't pattern match the text, since it gets localized.)
|
2012-06-19 21:32:45 +00:00
|
|
|
let message = err.message.replace(/.*\((.+)\)/, '$1');
|
2019-08-19 19:38:51 +00:00
|
|
|
throw new err.constructor({ code: err.code, message });
|
2012-06-19 21:32:45 +00:00
|
|
|
} else {
|
|
|
|
throw err;
|
2011-01-27 20:26:58 +00:00
|
|
|
}
|
2010-11-17 16:43:08 +00:00
|
|
|
}
|
2019-11-27 15:35:45 +00:00
|
|
|
|
|
|
|
// Async call, we don't need the reply though
|
|
|
|
GnomeDesktop.start_systemd_scope(argv[0], pid, null, null, null, () => {});
|
|
|
|
|
2012-05-10 01:23:19 +00:00
|
|
|
// Dummy child watch; we don't want to double-fork internally
|
|
|
|
// because then we lose the parent-child relationship, which
|
|
|
|
// can break polkit. See https://bugzilla.redhat.com//show_bug.cgi?id=819275
|
2017-10-31 00:38:18 +00:00
|
|
|
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, () => {});
|
2010-11-17 16:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// trySpawnCommandLine:
|
2019-01-31 13:43:52 +00:00
|
|
|
// @commandLine: a command line
|
2010-11-17 16:43:08 +00:00
|
|
|
//
|
2019-01-31 13:43:52 +00:00
|
|
|
// Runs @commandLine in the background. If launching @commandLine
|
2010-11-17 16:43:08 +00:00
|
|
|
// fails, this will throw an error.
|
2019-01-31 13:43:52 +00:00
|
|
|
function trySpawnCommandLine(commandLine) {
|
2019-01-31 14:08:00 +00:00
|
|
|
let success_, argv;
|
2010-11-17 16:43:08 +00:00
|
|
|
|
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
[success_, argv] = GLib.shell_parse_argv(commandLine);
|
2010-11-17 16:43:08 +00:00
|
|
|
} catch (err) {
|
|
|
|
// Replace "Error invoking GLib.shell_parse_argv: " with
|
|
|
|
// something nicer
|
2020-02-14 15:10:34 +00:00
|
|
|
err.message = err.message.replace(/[^:]*: /, '%s\n'.format(_('Could not parse command:')));
|
2010-11-17 16:43:08 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
trySpawn(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleSpawnError(command, err) {
|
2014-01-17 21:30:49 +00:00
|
|
|
let title = _("Execution of “%s” failed:").format(command);
|
2011-03-19 17:59:22 +00:00
|
|
|
Main.notifyError(title, err.message);
|
2010-11-17 16:43:08 +00:00
|
|
|
}
|
2010-12-17 20:30:12 +00:00
|
|
|
|
2017-02-27 01:17:29 +00:00
|
|
|
function formatTimeSpan(date) {
|
|
|
|
let now = GLib.DateTime.new_now_local();
|
|
|
|
|
|
|
|
let timespan = now.difference(date);
|
|
|
|
|
|
|
|
let minutesAgo = timespan / GLib.TIME_SPAN_MINUTE;
|
|
|
|
let hoursAgo = timespan / GLib.TIME_SPAN_HOUR;
|
|
|
|
let daysAgo = timespan / GLib.TIME_SPAN_DAY;
|
|
|
|
let weeksAgo = daysAgo / 7;
|
|
|
|
let monthsAgo = daysAgo / 30;
|
|
|
|
let yearsAgo = weeksAgo / 52;
|
|
|
|
|
|
|
|
if (minutesAgo < 5)
|
|
|
|
return _("Just now");
|
2019-08-20 00:51:42 +00:00
|
|
|
if (hoursAgo < 1) {
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d minute ago",
|
|
|
|
"%d minutes ago", minutesAgo).format(minutesAgo);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
|
|
|
if (daysAgo < 1) {
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d hour ago",
|
|
|
|
"%d hours ago", hoursAgo).format(hoursAgo);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2017-02-27 01:17:29 +00:00
|
|
|
if (daysAgo < 2)
|
|
|
|
return _("Yesterday");
|
2019-08-20 00:51:42 +00:00
|
|
|
if (daysAgo < 15) {
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d day ago",
|
|
|
|
"%d days ago", daysAgo).format(daysAgo);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
|
|
|
if (weeksAgo < 8) {
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d week ago",
|
|
|
|
"%d weeks ago", weeksAgo).format(weeksAgo);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
|
|
|
if (yearsAgo < 1) {
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d month ago",
|
|
|
|
"%d months ago", monthsAgo).format(monthsAgo);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2017-02-27 01:17:29 +00:00
|
|
|
return Gettext.ngettext("%d year ago",
|
|
|
|
"%d years ago", yearsAgo).format(yearsAgo);
|
|
|
|
}
|
|
|
|
|
2015-02-25 19:25:04 +00:00
|
|
|
function formatTime(time, params) {
|
|
|
|
let date;
|
|
|
|
// HACK: The built-in Date type sucks at timezones, which we need for the
|
|
|
|
// world clock; it's often more convenient though, so allow either
|
|
|
|
// Date or GLib.DateTime as parameter
|
|
|
|
if (time instanceof Date)
|
|
|
|
date = GLib.DateTime.new_from_unix_local(time.getTime() / 1000);
|
|
|
|
else
|
|
|
|
date = time;
|
2015-02-25 15:43:59 +00:00
|
|
|
|
2015-02-25 19:25:04 +00:00
|
|
|
let now = GLib.DateTime.new_now_local();
|
|
|
|
|
|
|
|
let daysAgo = now.difference(date) / (24 * 60 * 60 * 1000 * 1000);
|
2015-02-25 15:43:59 +00:00
|
|
|
|
|
|
|
let format;
|
|
|
|
|
|
|
|
if (_desktopSettings == null)
|
|
|
|
_desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
|
|
|
let clockFormat = _desktopSettings.get_string('clock-format');
|
|
|
|
|
2019-11-19 21:15:34 +00:00
|
|
|
params = Params.parse(params, {
|
|
|
|
timeOnly: false,
|
|
|
|
ampm: true,
|
|
|
|
});
|
2015-02-25 15:43:59 +00:00
|
|
|
|
2017-05-21 19:12:49 +00:00
|
|
|
if (clockFormat == '24h') {
|
2015-02-25 15:43:59 +00:00
|
|
|
// Show only the time if date is on today
|
|
|
|
if (daysAgo < 1 || params.timeOnly)
|
|
|
|
/* Translators: Time in 24h format */
|
|
|
|
format = N_("%H\u2236%M");
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
2019-01-29 01:27:05 +00:00
|
|
|
else if (daysAgo < 2)
|
2015-02-25 15:43:59 +00:00
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 24h format. i.e. "Yesterday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("Yesterday, %H\u2236%M");
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7)
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 24h format. i.e. "Monday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("%A, %H\u2236%M");
|
2015-02-25 19:25:04 +00:00
|
|
|
else if (date.get_year() == now.get_year())
|
2015-02-25 15:43:59 +00:00
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 24h format.
|
|
|
|
i.e. "May 25, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 14:50:02 +00:00
|
|
|
format = N_("%B %-d, %H\u2236%M");
|
2015-02-25 15:43:59 +00:00
|
|
|
else
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 24h format.
|
|
|
|
i.e. "May 25 2012, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 14:50:02 +00:00
|
|
|
format = N_("%B %-d %Y, %H\u2236%M");
|
2015-02-25 15:43:59 +00:00
|
|
|
} else {
|
|
|
|
// Show only the time if date is on today
|
2019-08-20 02:24:37 +00:00
|
|
|
if (daysAgo < 1 || params.timeOnly) // eslint-disable-line no-lonely-if
|
2015-02-25 15:43:59 +00:00
|
|
|
/* Translators: Time in 12h format */
|
|
|
|
format = N_("%l\u2236%M %p");
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
2019-01-29 01:27:05 +00:00
|
|
|
else if (daysAgo < 2)
|
2015-02-25 15:43:59 +00:00
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 12h format. i.e. "Yesterday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("Yesterday, %l\u2236%M %p");
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7)
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 12h format. i.e. "Monday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = N_("%A, %l\u2236%M %p");
|
2015-02-25 19:25:04 +00:00
|
|
|
else if (date.get_year() == now.get_year())
|
2015-02-25 15:43:59 +00:00
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 12h format.
|
|
|
|
i.e. "May 25, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 14:50:02 +00:00
|
|
|
format = N_("%B %-d, %l\u2236%M %p");
|
2015-02-25 15:43:59 +00:00
|
|
|
else
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 12h format.
|
|
|
|
i.e. "May 25 2012, 2:30 pm"*/
|
|
|
|
// xgettext:no-c-format
|
2018-10-15 14:50:02 +00:00
|
|
|
format = N_("%B %-d %Y, %l\u2236%M %p");
|
2015-02-25 15:43:59 +00:00
|
|
|
}
|
2017-06-23 15:37:13 +00:00
|
|
|
|
2019-11-19 21:15:34 +00:00
|
|
|
// Time in short 12h format, without the equivalent of "AM" or "PM"; used
|
|
|
|
// when it is clear from the context
|
|
|
|
if (!params.ampm)
|
|
|
|
format = format.replace(/\s*%p/g, '');
|
|
|
|
|
2017-06-23 15:37:13 +00:00
|
|
|
let formattedTime = date.format(Shell.util_translate_time_string(format));
|
|
|
|
// prepend LTR-mark to colon/ratio to force a text direction on times
|
|
|
|
return formattedTime.replace(/([:\u2236])/g, '\u200e$1');
|
2015-02-25 15:43:59 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 22:23:49 +00:00
|
|
|
function createTimeLabel(date, params) {
|
|
|
|
if (_desktopSettings == null)
|
|
|
|
_desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
|
|
|
|
|
|
|
let label = new St.Label({ text: formatTime(date, params) });
|
2017-10-31 00:38:18 +00:00
|
|
|
let id = _desktopSettings.connect('changed::clock-format', () => {
|
2015-02-25 22:23:49 +00:00
|
|
|
label.text = formatTime(date, params);
|
|
|
|
});
|
2019-01-28 00:42:00 +00:00
|
|
|
label.connect('destroy', () => _desktopSettings.disconnect(id));
|
2015-02-25 22:23:49 +00:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2011-12-17 22:52:11 +00:00
|
|
|
// lowerBound:
|
|
|
|
// @array: an array or array-like object, already sorted
|
|
|
|
// according to @cmp
|
|
|
|
// @val: the value to add
|
|
|
|
// @cmp: a comparator (or undefined to compare as numbers)
|
|
|
|
//
|
|
|
|
// Returns the position of the first element that is not
|
|
|
|
// lower than @val, according to @cmp.
|
|
|
|
// That is, returns the first position at which it
|
|
|
|
// is possible to insert @val without violating the
|
|
|
|
// order.
|
|
|
|
// This is quite like an ordinary binary search, except
|
|
|
|
// that it doesn't stop at first element comparing equal.
|
|
|
|
|
|
|
|
function lowerBound(array, val, cmp) {
|
|
|
|
let min, max, mid, v;
|
2017-10-31 00:38:18 +00:00
|
|
|
cmp = cmp || ((a, b) => a - b);
|
2011-12-17 22:52:11 +00:00
|
|
|
|
|
|
|
if (array.length == 0)
|
|
|
|
return 0;
|
|
|
|
|
2019-08-19 19:13:52 +00:00
|
|
|
min = 0;
|
|
|
|
max = array.length;
|
2011-12-17 22:52:11 +00:00
|
|
|
while (min < (max - 1)) {
|
|
|
|
mid = Math.floor((min + max) / 2);
|
|
|
|
v = cmp(array[mid], val);
|
|
|
|
|
|
|
|
if (v < 0)
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
return min == max || cmp(array[min], val) < 0 ? max : min;
|
2011-12-17 22:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// insertSorted:
|
|
|
|
// @array: an array sorted according to @cmp
|
|
|
|
// @val: a value to insert
|
|
|
|
// @cmp: the sorting function
|
|
|
|
//
|
|
|
|
// Inserts @val into @array, preserving the
|
|
|
|
// sorting invariants.
|
|
|
|
// Returns the position at which it was inserted
|
|
|
|
function insertSorted(array, val, cmp) {
|
|
|
|
let pos = lowerBound(array, val, cmp);
|
|
|
|
array.splice(pos, 0, val);
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
2013-02-18 20:35:02 +00:00
|
|
|
|
2013-03-11 17:43:38 +00:00
|
|
|
function ensureActorVisibleInScrollView(scrollView, actor) {
|
|
|
|
let adjustment = scrollView.vscroll.adjustment;
|
2019-01-31 14:08:00 +00:00
|
|
|
let [value, lower_, upper, stepIncrement_, pageIncrement_, pageSize] = adjustment.get_values();
|
2013-03-11 17:43:38 +00:00
|
|
|
|
|
|
|
let offset = 0;
|
|
|
|
let vfade = scrollView.get_effect("fade");
|
|
|
|
if (vfade)
|
2021-04-10 13:02:31 +00:00
|
|
|
offset = vfade.fade_margins.top;
|
2013-03-11 17:43:38 +00:00
|
|
|
|
|
|
|
let box = actor.get_allocation_box();
|
|
|
|
let y1 = box.y1, y2 = box.y2;
|
|
|
|
|
|
|
|
let parent = actor.get_parent();
|
|
|
|
while (parent != scrollView) {
|
|
|
|
if (!parent)
|
|
|
|
throw new Error("actor not in scroll view");
|
|
|
|
|
2019-08-20 00:20:08 +00:00
|
|
|
box = parent.get_allocation_box();
|
2013-03-11 17:43:38 +00:00
|
|
|
y1 += box.y1;
|
|
|
|
y2 += box.y1;
|
|
|
|
parent = parent.get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y1 < value + offset)
|
|
|
|
value = Math.max(0, y1 - offset);
|
|
|
|
else if (y2 > value + pageSize - offset)
|
|
|
|
value = Math.min(upper, y2 + offset - pageSize);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2019-07-24 19:03:17 +00:00
|
|
|
adjustment.ease(value, {
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 21:43:54 +00:00
|
|
|
duration: SCROLL_TIME,
|
2019-07-24 19:03:17 +00:00
|
|
|
});
|
2013-03-11 17:43:38 +00:00
|
|
|
}
|
2019-10-17 10:26:04 +00:00
|
|
|
|
|
|
|
function wiggle(actor, params) {
|
2020-02-22 13:25:37 +00:00
|
|
|
if (!St.Settings.get().enable_animations)
|
|
|
|
return;
|
|
|
|
|
2019-10-17 10:26:04 +00:00
|
|
|
params = Params.parse(params, {
|
2020-01-21 09:32:59 +00:00
|
|
|
offset: WIGGLE_OFFSET,
|
|
|
|
duration: WIGGLE_DURATION,
|
|
|
|
wiggleCount: N_WIGGLES,
|
2019-10-17 10:26:04 +00:00
|
|
|
});
|
|
|
|
actor.translation_x = 0;
|
|
|
|
|
|
|
|
// Accelerate before wiggling
|
|
|
|
actor.ease({
|
|
|
|
translation_x: -params.offset,
|
|
|
|
duration: params.duration,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => {
|
|
|
|
// Wiggle
|
|
|
|
actor.ease({
|
|
|
|
translation_x: params.offset,
|
|
|
|
duration: params.duration,
|
|
|
|
mode: Clutter.AnimationMode.LINEAR,
|
|
|
|
repeatCount: params.wiggleCount,
|
|
|
|
autoReverse: true,
|
|
|
|
onComplete: () => {
|
|
|
|
// Decelerate and return to the original position
|
|
|
|
actor.ease({
|
|
|
|
translation_x: 0,
|
|
|
|
duration: params.duration,
|
|
|
|
mode: Clutter.AnimationMode.EASE_IN_QUAD,
|
|
|
|
});
|
2019-08-20 21:43:54 +00:00
|
|
|
},
|
2019-10-17 10:26:04 +00:00
|
|
|
});
|
2019-08-20 21:43:54 +00:00
|
|
|
},
|
2019-10-17 10:26:04 +00:00
|
|
|
});
|
|
|
|
}
|
2020-12-31 17:18:42 +00:00
|
|
|
|
|
|
|
function lerp(start, end, progress) {
|
|
|
|
return start + progress * (end - start);
|
|
|
|
}
|
2021-02-04 11:26:15 +00:00
|
|
|
|
|
|
|
// _GNOMEversionToNumber:
|
|
|
|
// @version: a GNOME version element
|
|
|
|
//
|
|
|
|
// Like Number() but returns sortable values for special-cases
|
|
|
|
// 'alpha' and 'beta'. Returns NaN for unhandled 'versions'.
|
|
|
|
function _GNOMEversionToNumber(version) {
|
|
|
|
let ret = Number(version);
|
|
|
|
if (!isNaN(ret))
|
|
|
|
return ret;
|
|
|
|
if (version === 'alpha')
|
|
|
|
return -2;
|
|
|
|
if (version === 'beta')
|
|
|
|
return -1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GNOMEversionCompare:
|
|
|
|
// @version1: a string containing a GNOME version
|
|
|
|
// @version2: a string containing another GNOME version
|
|
|
|
//
|
|
|
|
// Returns an integer less than, equal to, or greater than
|
|
|
|
// zero, if version1 is older, equal or newer than version2
|
|
|
|
function GNOMEversionCompare(version1, version2) {
|
|
|
|
const v1Array = version1.split('.');
|
|
|
|
const v2Array = version2.split('.');
|
|
|
|
|
|
|
|
for (let i = 0; i < Math.max(v1Array.length, v2Array.length); i++) {
|
|
|
|
let elemV1 = _GNOMEversionToNumber(v1Array[i] || '0');
|
|
|
|
let elemV2 = _GNOMEversionToNumber(v2Array[i] || '0');
|
|
|
|
if (elemV1 < elemV2)
|
|
|
|
return -1;
|
|
|
|
if (elemV1 > elemV2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-06-16 17:09:42 +00:00
|
|
|
|
|
|
|
var DBusSenderChecker = class {
|
|
|
|
/**
|
|
|
|
* @param {string[]} allowList - list of allowed well-known names
|
|
|
|
*/
|
|
|
|
constructor(allowList) {
|
|
|
|
this._allowlistMap = new Map();
|
|
|
|
|
2021-11-23 01:48:04 +00:00
|
|
|
this._uninitializedNames = new Set(allowList);
|
|
|
|
this._initializedPromise = new Promise(resolve => {
|
|
|
|
this._resolveInitialized = resolve;
|
|
|
|
});
|
|
|
|
|
2021-06-16 17:09:42 +00:00
|
|
|
this._watchList = allowList.map(name => {
|
|
|
|
return Gio.DBus.watch_name(Gio.BusType.SESSION,
|
|
|
|
name,
|
|
|
|
Gio.BusNameWatcherFlags.NONE,
|
2021-11-23 01:48:04 +00:00
|
|
|
(conn_, name_, owner) => {
|
|
|
|
this._allowlistMap.set(name, owner);
|
|
|
|
this._checkAndResolveInitialized(name);
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this._allowlistMap.delete(name);
|
|
|
|
this._checkAndResolveInitialized(name);
|
|
|
|
});
|
2021-06-16 17:09:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-23 01:48:04 +00:00
|
|
|
* @param {string} name - bus name for which the watcher got initialized
|
|
|
|
*/
|
|
|
|
_checkAndResolveInitialized(name) {
|
|
|
|
if (this._uninitializedNames.delete(name) &&
|
|
|
|
this._uninitializedNames.size === 0)
|
|
|
|
this._resolveInitialized();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @async
|
2021-06-16 17:09:42 +00:00
|
|
|
* @param {string} sender - the bus name that invoked the checked method
|
|
|
|
* @returns {bool}
|
|
|
|
*/
|
2021-11-23 01:48:04 +00:00
|
|
|
async _isSenderAllowed(sender) {
|
|
|
|
await this._initializedPromise;
|
2021-06-16 17:09:42 +00:00
|
|
|
return [...this._allowlistMap.values()].includes(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the bus name that invoked @invocation maps
|
|
|
|
* to an entry in the allow list.
|
|
|
|
*
|
2021-11-23 01:48:04 +00:00
|
|
|
* @async
|
2021-06-16 17:09:42 +00:00
|
|
|
* @throws
|
|
|
|
* @param {Gio.DBusMethodInvocation} invocation - the invocation
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-11-23 01:48:04 +00:00
|
|
|
async checkInvocation(invocation) {
|
2021-06-16 17:09:42 +00:00
|
|
|
if (global.context.unsafe_mode)
|
|
|
|
return;
|
|
|
|
|
2021-11-23 01:48:04 +00:00
|
|
|
if (await this._isSenderAllowed(invocation.get_sender()))
|
2021-06-16 17:09:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
throw new GLib.Error(Gio.DBusError,
|
|
|
|
Gio.DBusError.ACCESS_DENIED,
|
|
|
|
'%s is not allowed'.format(invocation.get_method_name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
destroy() {
|
|
|
|
for (const id in this._watchList)
|
|
|
|
Gio.DBus.unwatch_name(id);
|
|
|
|
this._watchList = [];
|
|
|
|
}
|
|
|
|
};
|