94 lines
3.7 KiB
JavaScript
94 lines
3.7 KiB
JavaScript
//////////////////////////////////////////////////////////////////////////////////////////
|
|
// ) ( //
|
|
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
|
|
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
|
|
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
|
|
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
|
|
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
|
|
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
|
|
// |__/ //
|
|
// Copyright (c) 2021 Simon Schneegans //
|
|
// Released under the GPLv3 or later. See LICENSE file for details. //
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
'use strict';
|
|
|
|
const {Gtk, Gio} = imports.gi;
|
|
const ByteArray = imports.byteArray;
|
|
|
|
// Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3,
|
|
// -2, and -1 are returned respectively.
|
|
function toNumericVersion(x) {
|
|
switch (x) {
|
|
case 'alpha':
|
|
return -3;
|
|
case 'beta':
|
|
return -2;
|
|
case 'rc':
|
|
return -1;
|
|
}
|
|
return x;
|
|
}
|
|
|
|
const Config = imports.misc.config;
|
|
const [GS_MAJOR, GS_MINOR] = Config.PACKAGE_VERSION.split('.').map(toNumericVersion);
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
|
|
|
// This method can be used to write a message to GNOME Shell's log. This is enhances
|
|
// the standard log() functionality by prepending the extension's name and the location
|
|
// where the message was logged. As the extensions name is part of the location, you
|
|
// can more effectively watch the log output of GNOME Shell:
|
|
// journalctl -f -o cat | grep -E 'particle-effects|'
|
|
// This method is based on a similar script from the Fly-Pie GNOME Shell extension which
|
|
// os published under the MIT License (https://github.com/Schneegans/Fly-Pie).
|
|
function debug(message) {
|
|
const stack = new Error().stack.split('\n');
|
|
|
|
// Remove debug() function call from stack.
|
|
stack.shift();
|
|
|
|
// Find the index of the extension directory (e.g. particles@schneegans.github.com) in
|
|
// the stack entry. We do not want to print the entire absolute file path.
|
|
const extensionRoot = stack[0].indexOf(Me.metadata.uuid);
|
|
|
|
log('[' + stack[0].slice(extensionRoot) + '] ' + message);
|
|
}
|
|
|
|
// This method simply returns true if we are currently using GTK4.
|
|
function isGTK4() {
|
|
return Gtk.get_major_version() == 4;
|
|
}
|
|
|
|
// This method returns 'gtk3' or 'gtk4' depending on the currently used gtk version.
|
|
function getGTKString() {
|
|
return isGTK4() ? 'gtk4' : 'gtk3';
|
|
}
|
|
|
|
// This method returns true if the current GNOME Shell version matches the given
|
|
// arguments.
|
|
function shellVersionIs(major, minor) {
|
|
return GS_MAJOR == major && GS_MINOR == toNumericVersion(minor);
|
|
}
|
|
|
|
// This method returns true if the current GNOME Shell version is at least as high as the
|
|
// given arguments. Supports "alpha" and "beta" for the minor version number.
|
|
function shellVersionIsAtLeast(major, minor) {
|
|
if (GS_MAJOR > major) {
|
|
return true;
|
|
}
|
|
|
|
if (GS_MAJOR == major) {
|
|
return GS_MINOR >= toNumericVersion(minor);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Reads the contents of a file contained in the global resources archive. The data
|
|
// is returned as a string.
|
|
function getStringResource(path) {
|
|
const data = Gio.resources_lookup_data(path, 0);
|
|
return ByteArray.toString(ByteArray.fromGBytes(data));
|
|
} |