Use Time enumeration
This commit is contained in:
@@ -14,6 +14,7 @@ build:
|
|||||||
--force \
|
--force \
|
||||||
--extra-source=./config.js \
|
--extra-source=./config.js \
|
||||||
--extra-source=./utils.js \
|
--extra-source=./utils.js \
|
||||||
|
--extra-source=./enums/ \
|
||||||
--extra-source=./icons/ \
|
--extra-source=./icons/ \
|
||||||
--extra-source=./modules/ \
|
--extra-source=./modules/ \
|
||||||
--extra-source=./preferences/ \
|
--extra-source=./preferences/ \
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test-lint": "eslint .",
|
"test-lint": "eslint .",
|
||||||
"pretest-variants": "cat ./src/modules/GtkVariants.js ./tests/gtk_themes/_variants.js.template > ./tests/gtk_themes/_variants.js & cat ./src/modules/ShellVariants.js ./tests/shell_themes/_variants.js.template > ./tests/shell_themes/_variants.js",
|
"pretest-variants": "./tests/prepare_variants.sh",
|
||||||
"test-variants": "ava",
|
"test-variants": "ava",
|
||||||
"test": "npm run test-lint && npm run test-variants"
|
"test": "npm run test-lint && npm run test-variants"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 Romain Vigier <contact AT romainvigier.fr>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time is an enumeration of the possible time values.
|
||||||
|
*/
|
||||||
|
var Time = {
|
||||||
|
UNKNOWN: 'unknown',
|
||||||
|
DAY: 'day',
|
||||||
|
NIGHT: 'night',
|
||||||
|
};
|
||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Backgrounder is responsible for changing the desktop background
|
* The Backgrounder is responsible for changing the desktop background
|
||||||
* according to the time.
|
* according to the time.
|
||||||
@@ -121,12 +123,14 @@ var Backgrounder = class {
|
|||||||
|
|
||||||
|
|
||||||
_updateCurrentBackground() {
|
_updateCurrentBackground() {
|
||||||
if (e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
this._backgroundsSettings.set_string(e.timer.time, this._systemBackgroundSettings.get_string('picture-uri'));
|
return;
|
||||||
|
this._backgroundsSettings.set_string(e.timer.time, this._systemBackgroundSettings.get_string('picture-uri'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSystemBackground() {
|
_updateSystemBackground() {
|
||||||
if (e.timer.time && this._backgroundsSettings.get_string(e.timer.time))
|
if (e.timer.time === Time.UNKNOWN || !this._backgroundsSettings.get_string(e.timer.time))
|
||||||
this._systemBackgroundSettings.set_string('picture-uri', this._backgroundsSettings.get_string(e.timer.time));
|
return;
|
||||||
|
this._systemBackgroundSettings.set_string('picture-uri', this._backgroundsSettings.get_string(e.timer.time));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Commander is responsible for spawning commands according to the time.
|
* The Commander is responsible for spawning commands according to the time.
|
||||||
@@ -77,7 +79,7 @@ var Commander = class {
|
|||||||
|
|
||||||
|
|
||||||
_spawnCommand() {
|
_spawnCommand() {
|
||||||
if (!e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
return;
|
return;
|
||||||
const command = this._commandsSettings.get_string(e.timer.time === 'day' ? 'sunrise' : 'sunset');
|
const command = this._commandsSettings.get_string(e.timer.time === 'day' ? 'sunrise' : 'sunset');
|
||||||
GLib.spawn_async(null, ['sh', '-c', command], null, GLib.SpawnFlags.SEARCH_PATH, null);
|
GLib.spawn_async(null, ['sh', '-c', command], null, GLib.SpawnFlags.SEARCH_PATH, null);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Cursor Themer is responsible for changing the cursor theme according to
|
* The Cursor Themer is responsible for changing the cursor theme according to
|
||||||
@@ -120,12 +122,14 @@ var CursorThemer = class {
|
|||||||
|
|
||||||
|
|
||||||
_updateCurrentVariant() {
|
_updateCurrentVariant() {
|
||||||
if (e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
this._cursorVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('cursor-theme'));
|
return;
|
||||||
|
this._cursorVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('cursor-theme'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSystemCursorTheme() {
|
_updateSystemCursorTheme() {
|
||||||
if (e.timer.time && this._cursorVariantsSettings.get_string(e.timer.time))
|
if (e.timer.time === Time.UNKNOWN || !this._cursorVariantsSettings.get_string(e.timer.time))
|
||||||
this._interfaceSettings.set_string('cursor-theme', this._cursorVariantsSettings.get_string(e.timer.time));
|
return;
|
||||||
|
this._interfaceSettings.set_string('cursor-theme', this._cursorVariantsSettings.get_string(e.timer.time));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
const { GtkVariants } = Me.imports.modules.GtkVariants;
|
const { GtkVariants } = Me.imports.modules.GtkVariants;
|
||||||
|
|
||||||
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
||||||
@@ -159,12 +161,13 @@ var GtkThemer = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateCurrentVariant() {
|
_updateCurrentVariant() {
|
||||||
if (this._gtkVariantsSettings.get_boolean('manual') && e.timer.time)
|
if (e.timer.time === Time.UNKNOWN || !this._gtkVariantsSettings.get_boolean('manual'))
|
||||||
this._gtkVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('gtk-theme'));
|
return;
|
||||||
|
this._gtkVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('gtk-theme'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSystemGtkTheme() {
|
_updateSystemGtkTheme() {
|
||||||
if (!e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
return;
|
return;
|
||||||
console.debug(`Setting the ${e.timer.time} GTK variant...`);
|
console.debug(`Setting the ${e.timer.time} GTK variant...`);
|
||||||
this._interfaceSettings.set_string('gtk-theme', this._gtkVariantsSettings.get_string(e.timer.time));
|
this._interfaceSettings.set_string('gtk-theme', this._gtkVariantsSettings.get_string(e.timer.time));
|
||||||
@@ -179,13 +182,13 @@ var GtkThemer = class {
|
|||||||
const variants = GtkVariants.guessFrom(originalTheme);
|
const variants = GtkVariants.guessFrom(originalTheme);
|
||||||
const installedThemes = utils.getInstalledGtkThemes();
|
const installedThemes = utils.getInstalledGtkThemes();
|
||||||
|
|
||||||
if (!installedThemes.has(variants.get('day')) || !installedThemes.has(variants.get('night'))) {
|
if (!installedThemes.has(variants.get(Time.DAY)) || !installedThemes.has(variants.get(Time.NIGHT))) {
|
||||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GTK theme. Please manually choose them in the extension\'s preferences.').format(originalTheme);
|
const message = _('Unable to automatically detect the day and night variants for the "%s" GTK theme. Please manually choose them in the extension\'s preferences.').format(originalTheme);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._gtkVariantsSettings.set_string('day', variants.get('day'));
|
this._gtkVariantsSettings.set_string('day', variants.get(Time.DAY));
|
||||||
this._gtkVariantsSettings.set_string('night', variants.get('night'));
|
this._gtkVariantsSettings.set_string('night', variants.get(Time.NIGHT));
|
||||||
console.debug(`New GTK variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
console.debug(`New GTK variants. { day: '${variants.get(Time.DAY)}'; night: '${variants.get(Time.NIGHT)}' }`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+36
-30
@@ -2,6 +2,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2020 Matti Hyttinen
|
// SPDX-FileCopyrightText: 2020 Matti Hyttinen
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
const { extensionUtils } = imports.misc;
|
||||||
|
|
||||||
|
const Me = extensionUtils.getCurrentExtension();
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The magic of guessing theme variants happens here.
|
* The magic of guessing theme variants happens here.
|
||||||
*
|
*
|
||||||
@@ -30,56 +36,56 @@ var GtkVariants = class {
|
|||||||
const variants = new Map();
|
const variants = new Map();
|
||||||
|
|
||||||
if (name.includes('Adapta')) {
|
if (name.includes('Adapta')) {
|
||||||
variants.set('day', name.replace('-Nokto', ''));
|
variants.set(Time.DAY, name.replace('-Nokto', ''));
|
||||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('Adapta', 'Adapta-Nokto'));
|
||||||
} else if (name.includes('Arc')) {
|
} else if (name.includes('Arc')) {
|
||||||
variants.set('day', name.replace(/-Dark(?!er)/, ''));
|
variants.set(Time.DAY, name.replace(/-Dark(?!er)/, ''));
|
||||||
variants.set('night', variants.get('day').replace(/Arc(-Darker)?/, 'Arc-Dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/Arc(-Darker)?/, 'Arc-Dark'));
|
||||||
} else if (name.match('Cabinet')) {
|
} else if (name.match('Cabinet')) {
|
||||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
variants.set(Time.DAY, name.replace(/-Dark(?!er)/, '-Light'));
|
||||||
variants.set('night', variants.get('day').replace(/(-Light|-Darker)/, '-Dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-Light|-Darker)/, '-Dark'));
|
||||||
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-light)?-compact/, '-dark-compact'));
|
||||||
} else if (name.includes('Flat-Remix-GTK')) {
|
} else if (name.includes('Flat-Remix-GTK')) {
|
||||||
const isSolid = name.includes('-Solid');
|
const isSolid = name.includes('-Solid');
|
||||||
const withoutBorder = name.includes('-NoBorder');
|
const withoutBorder = name.includes('-NoBorder');
|
||||||
const basename = name.split('-').slice(0, 4).join('-');
|
const basename = name.split('-').slice(0, 4).join('-');
|
||||||
variants.set('day', basename + (name.includes('-Darker') ? '-Darker' : '') + (isSolid ? '-Solid' : ''));
|
variants.set(Time.DAY, basename + (name.includes('-Darker') ? '-Darker' : '') + (isSolid ? '-Solid' : ''));
|
||||||
variants.set('night', basename + (name.includes('-Darkest') ? '-Darkest' : '-Dark') + (isSolid ? '-Solid' : '') + (withoutBorder ? '-NoBorder' : ''));
|
variants.set(Time.NIGHT, basename + (name.includes('-Darkest') ? '-Darkest' : '-Dark') + (isSolid ? '-Solid' : '') + (withoutBorder ? '-NoBorder' : ''));
|
||||||
} else if (name.includes('HighContrast')) {
|
} else if (name.includes('HighContrast')) {
|
||||||
variants.set('day', 'HighContrast');
|
variants.set(Time.DAY, 'HighContrast');
|
||||||
variants.set('night', 'HighContrastInverse');
|
variants.set(Time.NIGHT, 'HighContrastInverse');
|
||||||
} else if (name.match(/^(Layan|Macwaita|Matcha|Nextwaita)/)) {
|
} else if (name.match(/^(Layan|Macwaita|Matcha|Nextwaita)/)) {
|
||||||
const basename = name.split('-')[0];
|
const basename = name.split('-')[0];
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||||
} else if (name.match(/^Mc-?OS-CTLina-Gnome/)) {
|
} else if (name.match(/^Mc-?OS-CTLina-Gnome/)) {
|
||||||
const version = name.split('-').pop();
|
const version = name.split('-').pop();
|
||||||
variants.set('day', `McOS-CTLina-Gnome-${version}`);
|
variants.set(Time.DAY, `McOS-CTLina-Gnome-${version}`);
|
||||||
variants.set('night', `Mc-OS-CTLina-Gnome-Dark-${version}`);
|
variants.set(Time.NIGHT, `Mc-OS-CTLina-Gnome-Dark-${version}`);
|
||||||
} else if (name.match(/^(Mojave|WhiteSur)/)) {
|
} else if (name.match(/^(Mojave|WhiteSur)/)) {
|
||||||
variants.set('day', name.replace('-dark', '-light'));
|
variants.set(Time.DAY, name.replace('-dark', '-light'));
|
||||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('-light', '-dark'));
|
||||||
} else if (name.includes('Plata')) {
|
} else if (name.includes('Plata')) {
|
||||||
variants.set('day', name.replace('-Noir', ''));
|
variants.set(Time.DAY, name.replace('-Noir', ''));
|
||||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||||
} else if (name.match(/^Prof-Gnome-(.+)-3(.*)/)) {
|
} else if (name.match(/^Prof-Gnome-(.+)-3(.*)/)) {
|
||||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
variants.set(Time.DAY, name.replace(/-Dark(?!er)/, '-Light'));
|
||||||
variants.set('night', variants.get('day').replace(/(-Light(-DS)?|-Darker)/, '-Dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-Light(-DS)?|-Darker)/, '-Dark'));
|
||||||
} else if (name.includes('Simply_Circles')) {
|
} else if (name.includes('Simply_Circles')) {
|
||||||
variants.set('day', name.replace('_Dark', '_Light'));
|
variants.set(Time.DAY, name.replace('_Dark', '_Light'));
|
||||||
variants.set('night', name.replace('_Light', '_Dark'));
|
variants.set(Time.NIGHT, name.replace('_Light', '_Dark'));
|
||||||
} else if (name.includes('Teja')) {
|
} else if (name.includes('Teja')) {
|
||||||
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
||||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
variants.set(Time.DAY, name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||||
variants.set('night', variants.get('day').replace('_Light', '') + darkVariant);
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('_Light', '') + darkVariant);
|
||||||
} else if (name.includes('vimix')) {
|
} else if (name.includes('vimix')) {
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/vimix(-light)?/, 'vimix-dark'));
|
||||||
} else {
|
} else {
|
||||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
variants.set(Time.DAY, name.replace(/-dark(?!er)(est)?/, ''));
|
||||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return variants;
|
return variants;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Icon Themer is responsible for changing the icon theme according to the
|
* The Icon Themer is responsible for changing the icon theme according to the
|
||||||
@@ -120,12 +122,14 @@ var IconThemer = class {
|
|||||||
|
|
||||||
|
|
||||||
_updateCurrentVariant() {
|
_updateCurrentVariant() {
|
||||||
if (e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
this._iconVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('icon-theme'));
|
return;
|
||||||
|
this._iconVariantsSettings.set_string(e.timer.time, this._interfaceSettings.get_string('icon-theme'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSystemIconTheme() {
|
_updateSystemIconTheme() {
|
||||||
if (e.timer.time && this._iconVariantsSettings.get_string(e.timer.time))
|
if (e.timer.time === Time.UNKNOWN || !this._iconVariantsSettings.get_string(e.timer.time))
|
||||||
this._interfaceSettings.set_string('icon-theme', this._iconVariantsSettings.get_string(e.timer.time));
|
return;
|
||||||
|
this._interfaceSettings.set_string('icon-theme', this._iconVariantsSettings.get_string(e.timer.time));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
const { ShellVariants } = Me.imports.modules.ShellVariants;
|
const { ShellVariants } = Me.imports.modules.ShellVariants;
|
||||||
|
|
||||||
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
||||||
@@ -164,12 +166,13 @@ var ShellThemer = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateCurrentVariant() {
|
_updateCurrentVariant() {
|
||||||
if (this._userthemesSettings && this._shellVariantsSettings.get_boolean('manual') && e.timer.time)
|
if (e.timer.time === Time.UNKNOWN || !this._userthemesSettings || !this._shellVariantsSettings.get_boolean('manual'))
|
||||||
this._shellVariantsSettings.set_string(e.timer.time, this._userthemesSettings.get_string('name'));
|
return;
|
||||||
|
this._shellVariantsSettings.set_string(e.timer.time, this._userthemesSettings.get_string('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSystemShellTheme() {
|
_updateSystemShellTheme() {
|
||||||
if (!e.timer.time)
|
if (e.timer.time === Time.UNKNOWN)
|
||||||
return;
|
return;
|
||||||
console.debug(`Setting the ${e.timer.time} Shell variant...`);
|
console.debug(`Setting the ${e.timer.time} Shell variant...`);
|
||||||
const shellTheme = this._shellVariantsSettings.get_string(e.timer.time);
|
const shellTheme = this._shellVariantsSettings.get_string(e.timer.time);
|
||||||
@@ -190,13 +193,13 @@ var ShellThemer = class {
|
|||||||
const variants = ShellVariants.guessFrom(originalTheme);
|
const variants = ShellVariants.guessFrom(originalTheme);
|
||||||
const installedThemes = utils.getInstalledShellThemes();
|
const installedThemes = utils.getInstalledShellThemes();
|
||||||
|
|
||||||
if (!installedThemes.has(variants.get('day')) || !installedThemes.has(variants.get('night'))) {
|
if (!installedThemes.has(variants.get(Time.DAY)) || !installedThemes.has(variants.get(Time.NIGHT))) {
|
||||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GNOME Shell theme. Please manually choose them in the extension\'s preferences.').format(originalTheme);
|
const message = _('Unable to automatically detect the day and night variants for the "%s" GNOME Shell theme. Please manually choose them in the extension\'s preferences.').format(originalTheme);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._shellVariantsSettings.set_string('day', variants.get('day'));
|
this._shellVariantsSettings.set_string('day', variants.get(Time.DAY));
|
||||||
this._shellVariantsSettings.set_string('night', variants.get('night'));
|
this._shellVariantsSettings.set_string('night', variants.get(Time.NIGHT));
|
||||||
console.debug(`New Shell variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
console.debug(`New Shell variants. { day: '${variants.get(Time.DAY)}'; night: '${variants.get(Time.NIGHT)}' }`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
// Copyright (C) 2019, 2020 Romain Vigier
|
|
||||||
// Copyright (C) 2020 Matti Hyttinen
|
|
||||||
// SPDX-FileCopyrightText: 2019-2021 Romain Vigier <contact AT romainvigier.fr>
|
// SPDX-FileCopyrightText: 2019-2021 Romain Vigier <contact AT romainvigier.fr>
|
||||||
// SPDX-FileCopyrightText: 2020 Matti Hyttinen
|
// SPDX-FileCopyrightText: 2020 Matti Hyttinen
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
const { extensionUtils } = imports.misc;
|
||||||
|
|
||||||
|
const Me = extensionUtils.getCurrentExtension();
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The magic of guessing theme variants happens here.
|
* The magic of guessing theme variants happens here.
|
||||||
*
|
*
|
||||||
@@ -32,53 +36,53 @@ var ShellVariants = class {
|
|||||||
const variants = new Map();
|
const variants = new Map();
|
||||||
|
|
||||||
if (name === '') {
|
if (name === '') {
|
||||||
variants.set('day', '');
|
variants.set(Time.DAY, '');
|
||||||
variants.set('night', '');
|
variants.set(Time.NIGHT, '');
|
||||||
} else if (name.includes('Adapta')) {
|
} else if (name.includes('Adapta')) {
|
||||||
variants.set('day', name.replace('-Nokto', ''));
|
variants.set(Time.DAY, name.replace('-Nokto', ''));
|
||||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('Adapta', 'Adapta-Nokto'));
|
||||||
} else if (name.includes('Arc')) {
|
} else if (name.includes('Arc')) {
|
||||||
variants.set('day', name.replace('-Dark', ''));
|
variants.set(Time.DAY, name.replace('-Dark', ''));
|
||||||
variants.set('night', variants.get('day').replace('Arc', 'Arc-Dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('Arc', 'Arc-Dark'));
|
||||||
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-light)?-compact/, '-dark-compact'));
|
||||||
} else if (name.includes('Flat-Remix')) {
|
} else if (name.includes('Flat-Remix')) {
|
||||||
const color = name.split('-')[2] && !['Dark', 'Darkest', 'fullPanel'].includes(name.split('-')[2]) ? `-${name.split('-')[2]}` : '';
|
const color = name.split('-')[2] && !['Dark', 'Darkest', 'fullPanel'].includes(name.split('-')[2]) ? `-${name.split('-')[2]}` : '';
|
||||||
const darkVariant = name.includes('Darkest') ? '-Darkest' : '-Dark';
|
const darkVariant = name.includes('Darkest') ? '-Darkest' : '-Dark';
|
||||||
const size = name.includes('fullPanel') ? '-fullPanel' : '';
|
const size = name.includes('fullPanel') ? '-fullPanel' : '';
|
||||||
variants.set('day', name.replace(/-Dark(est)?/, ''));
|
variants.set(Time.DAY, name.replace(/-Dark(est)?/, ''));
|
||||||
variants.set('night', `Flat-Remix${color}${darkVariant}${size}`);
|
variants.set(Time.NIGHT, `Flat-Remix${color}${darkVariant}${size}`);
|
||||||
} else if (name.match(/^(Layan|Matcha)/)) {
|
} else if (name.match(/^(Layan|Matcha)/)) {
|
||||||
const basename = name.split('-')[0];
|
const basename = name.split('-')[0];
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||||
} else if (name.includes('mcOS11-Shell')) {
|
} else if (name.includes('mcOS11-Shell')) {
|
||||||
variants.set('day', name.replace('-Dark', ''));
|
variants.set(Time.DAY, name.replace('-Dark', ''));
|
||||||
variants.set('night', `${variants.get('day')}-Dark`);
|
variants.set(Time.NIGHT, `${variants.get(Time.DAY)}-Dark`);
|
||||||
} else if (name.match(/^Mc-?OS-CTLina-Gnome/)) {
|
} else if (name.match(/^Mc-?OS-CTLina-Gnome/)) {
|
||||||
const version = name.split('-').pop();
|
const version = name.split('-').pop();
|
||||||
variants.set('day', `McOS-CTLina-Gnome-${version}`);
|
variants.set(Time.DAY, `McOS-CTLina-Gnome-${version}`);
|
||||||
variants.set('night', `Mc-OS-CTLina-Gnome-Dark-${version}`);
|
variants.set(Time.NIGHT, `Mc-OS-CTLina-Gnome-Dark-${version}`);
|
||||||
} else if (name.match(/^(Mojave|WhiteSur)/)) {
|
} else if (name.match(/^(Mojave|WhiteSur)/)) {
|
||||||
variants.set('day', name.replace('-dark', '-light'));
|
variants.set(Time.DAY, name.replace('-dark', '-light'));
|
||||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('-light', '-dark'));
|
||||||
} else if (name.includes('Plata')) {
|
} else if (name.includes('Plata')) {
|
||||||
variants.set('day', name.replace('-Noir', ''));
|
variants.set(Time.DAY, name.replace('-Noir', ''));
|
||||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||||
} else if (name.includes('Simply_Circles')) {
|
} else if (name.includes('Simply_Circles')) {
|
||||||
variants.set('day', name.replace('_Dark', '_Light'));
|
variants.set(Time.DAY, name.replace('_Dark', '_Light'));
|
||||||
variants.set('night', name.replace('_Light', '_Dark'));
|
variants.set(Time.NIGHT, name.replace('_Light', '_Dark'));
|
||||||
} else if (name.includes('Teja')) {
|
} else if (name.includes('Teja')) {
|
||||||
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
||||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
variants.set(Time.DAY, name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||||
variants.set('night', variants.get('day').replace('_Light', '') + darkVariant);
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace('_Light', '') + darkVariant);
|
||||||
} else if (name.includes('vimix')) {
|
} else if (name.includes('vimix')) {
|
||||||
variants.set('day', name.replace('-dark', ''));
|
variants.set(Time.DAY, name.replace('-dark', ''));
|
||||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/vimix(-light)?/, 'vimix-dark'));
|
||||||
} else {
|
} else {
|
||||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
variants.set(Time.DAY, name.replace(/-dark(?!er)(est)?/, ''));
|
||||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
variants.set(Time.NIGHT, variants.get(Time.DAY).replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return variants;
|
return variants;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
const { TimerNightlight } = Me.imports.modules.TimerNightlight;
|
const { TimerNightlight } = Me.imports.modules.TimerNightlight;
|
||||||
const { TimerLocation } = Me.imports.modules.TimerLocation;
|
const { TimerLocation } = Me.imports.modules.TimerLocation;
|
||||||
const { TimerSchedule } = Me.imports.modules.TimerSchedule;
|
const { TimerSchedule } = Me.imports.modules.TimerSchedule;
|
||||||
@@ -36,7 +37,7 @@ var Timer = class {
|
|||||||
this._colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
|
this._colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
|
||||||
this._locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
|
this._locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
|
||||||
this._sources = [];
|
this._sources = [];
|
||||||
this._previousTime = null;
|
this._previousTime = Time.UNKNOWN;
|
||||||
this._settingsConnections = [];
|
this._settingsConnections = [];
|
||||||
this._timeConnections = [];
|
this._timeConnections = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Location Timer uses Location Services to get the current sunrise and
|
* The Location Timer uses Location Services to get the current sunrise and
|
||||||
@@ -57,7 +59,7 @@ var TimerLocation = class {
|
|||||||
|
|
||||||
|
|
||||||
get time() {
|
get time() {
|
||||||
return this._isDaytime() ? 'day' : 'night';
|
return this._isDaytime() ? Time.DAY : Time.NIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
const COLOR_INTERFACE = `
|
const COLOR_INTERFACE = `
|
||||||
<node>
|
<node>
|
||||||
@@ -53,7 +55,7 @@ var TimerNightlight = class {
|
|||||||
|
|
||||||
|
|
||||||
get time() {
|
get time() {
|
||||||
return this._isNightlightActive() ? 'night' : 'day';
|
return this._isNightlightActive() ? Time.NIGHT : Time.DAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
const e = Me.imports.extension;
|
const e = Me.imports.extension;
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
||||||
const _ = Gettext.gettext;
|
const _ = Gettext.gettext;
|
||||||
|
|
||||||
@@ -186,7 +188,7 @@ var TimerOndemand = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_toggleTime() {
|
_toggleTime() {
|
||||||
this._timeSettings.set_string('ondemand-time', e.timer.time === 'day' ? 'night' : 'day');
|
this._timeSettings.set_string('ondemand-time', e.timer.time === Time.DAY ? Time.NIGHT : Time.DAY);
|
||||||
this.emit('time-changed', this.time);
|
this.emit('time-changed', this.time);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -234,7 +236,7 @@ var NtsPopupMenuItem = GObject.registerClass(
|
|||||||
);
|
);
|
||||||
|
|
||||||
var _getIconNameForTime = time => {
|
var _getIconNameForTime = time => {
|
||||||
return time === 'day' ? 'nightthemeswitcher-ondemand-off-symbolic' : 'nightthemeswitcher-ondemand-on-symbolic';
|
return time === Time.DAY ? 'nightthemeswitcher-ondemand-off-symbolic' : 'nightthemeswitcher-ondemand-on-symbolic';
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getGiconForTime = time => {
|
var _getGiconForTime = time => {
|
||||||
@@ -242,5 +244,5 @@ var _getGiconForTime = time => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var _getLabelForTime = time => {
|
var _getLabelForTime = time => {
|
||||||
return time === 'day' ? _('Switch to night theme') : _('Switch to day theme');
|
return time === Time.DAY ? _('Switch to night theme') : _('Switch to day theme');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Me = extensionUtils.getCurrentExtension();
|
|||||||
|
|
||||||
const utils = Me.imports.utils;
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
const { Time } = Me.imports.enums.Time;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Schedule Timer uses a manual schedule to get the current time.
|
* The Schedule Timer uses a manual schedule to get the current time.
|
||||||
@@ -40,7 +42,7 @@ var TimerSchedule = class {
|
|||||||
|
|
||||||
|
|
||||||
get time() {
|
get time() {
|
||||||
return this._isDaytime() ? 'day' : 'night';
|
return this._isDaytime() ? Time.DAY : Time.NIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# SPDX-FileCopyrightText: 2021 Romain Vigier <contact AT romainvigier.fr>
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
grep -vE 'imports|^const Me' ./src/modules/GtkVariants.js | cat ./src/enums/Time.js - ./tests/gtk_themes/_variants.js.template > ./tests/gtk_themes/_variants.js
|
||||||
|
grep -vE 'imports|^const Me' ./src/modules/ShellVariants.js | cat ./src/enums/Time.js - ./tests/shell_themes/_variants.js.template > ./tests/shell_themes/_variants.js
|
||||||
Reference in New Issue
Block a user