Skip to content

Commit

Permalink
Merge pull request #216 from neffo/gnome-45-mr
Browse files Browse the repository at this point in the history
Version 46 (GNOME 45)
  • Loading branch information
neffo authored Oct 22, 2023
2 parents 64d516a + 0f50de2 commit e0e445a
Show file tree
Hide file tree
Showing 32 changed files with 1,137 additions and 3,521 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: [neffo]
custom: ['https://flattr.com/@neffo']
ko_fi: [michaelcarroll]
7 changes: 4 additions & 3 deletions BWClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
// (at your option) any later version.
// See the GNU General Public License, version 3 or later for details.

const St = imports.gi.St;
import St from 'gi://St';
import Gio from 'gi://Gio';

const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD;
const Gio = imports.gi.Gio;

var BWClipboard = class BWClipboard {
export default class BWClipboard {
constructor() {
this.clipboard = St.Clipboard.get_default();
}
Expand Down
60 changes: 30 additions & 30 deletions blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
// This code based on https://github.com/PRATAP-KUMAR/Control_Blur_Effect_On_Lock_Screen
// and https://github.com/sunwxg/gnome-shell-extension-unlockDialogBackground

const St = imports.gi.St;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Background = imports.ui.background;
const ScreenShield = imports.ui.screenShield;
const UnlockDialog = imports.ui.unlockDialog.UnlockDialog;
const ExtensionUtils = imports.misc.extensionUtils;
var _updateBackgroundEffects = UnlockDialog.prototype._updateBackgroundEffects;
var _showClock = UnlockDialog.prototype._showClock;
var _showPrompt = UnlockDialog.prototype._showPrompt;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;

var shellVersionMajor = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[0]);
var shellVersionMinor = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[1]);
var shellVersionPoint = parseInt(imports.misc.config.PACKAGE_VERSION.split('.')[2]);
import St from 'gi://St';
import Shell from 'gi://Shell';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Background from 'resource:///org/gnome/shell/ui/background.js';
import * as ScreenShield from 'resource:///org/gnome/shell/ui/screenShield.js';
import * as UnlockDialog from 'resource:///org/gnome/shell/ui/unlockDialog.js';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
var _updateBackgroundEffects = UnlockDialog.UnlockDialog.prototype._updateBackgroundEffects;
var _showClock = UnlockDialog.UnlockDialog.prototype._showClock;
var _showPrompt = UnlockDialog.UnlockDialog.prototype._showPrompt;
import * as Utils from './utils.js';

var shellVersionMajor = parseInt(Config.PACKAGE_VERSION.split('.')[0]);
var shellVersionMinor = parseInt(Config.PACKAGE_VERSION.split('.')[1]);
var shellVersionPoint = parseInt(Config.PACKAGE_VERSION.split('.')[2]);

// default BWP mild blur
var BWP_BLUR_SIGMA = 2;
Expand Down Expand Up @@ -86,7 +86,7 @@ function _showPrompt_BWP() {
this._updateBackgroundEffects();
}

var Blur = class Blur {
export default class Blur {
constructor() {
this.enabled = false;
log('Bing Wallpaper adjustable blur is '+supportedVersion()?'available':'not available');
Expand Down Expand Up @@ -122,15 +122,15 @@ var Blur = class Blur {

_enable() {
if (supportedVersion()) {
log("Blur._enable() called on GNOME "+imports.misc.config.PACKAGE_VERSION);
UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects_BWP;
log("Blur._enable() called on GNOME "+Config.PACKAGE_VERSION);
UnlockDialog.UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects_BWP;
// we override _showClock and _showPrompt to patch in updates to blur effect before calling the GNOME functions
UnlockDialog.prototype._showClock = _showClock_BWP;
UnlockDialog.prototype._showPrompt = _showPrompt_BWP;
UnlockDialog.UnlockDialog.prototype._showClock = _showClock_BWP;
UnlockDialog.UnlockDialog.prototype._showPrompt = _showPrompt_BWP;

// this are the original functions which we call into from our versions above
UnlockDialog.prototype._showClock_GNOME = _showClock;
UnlockDialog.prototype._showPrompt_GNOME = _showPrompt;
UnlockDialog.UnlockDialog.prototype._showClock_GNOME = _showClock;
UnlockDialog.UnlockDialog.prototype._showPrompt_GNOME = _showPrompt;

}
this.enabled = true;
Expand All @@ -142,14 +142,14 @@ var Blur = class Blur {
log("_lockscreen_blur_disable() called");
if (supportedVersion()) {
// restore default functions
UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects;
UnlockDialog.prototype._showClock = _showClock;
UnlockDialog.prototype._showPrompt = _showPrompt;
UnlockDialog.UnlockDialog.prototype._updateBackgroundEffects = _updateBackgroundEffects;
UnlockDialog.UnlockDialog.prototype._showClock = _showClock;
UnlockDialog.UnlockDialog.prototype._showPrompt = _showPrompt;
// clean up unused functions we created
UnlockDialog.prototype._showClock_GNOME = null;
delete UnlockDialog.prototype._showClock_GNOME;
UnlockDialog.prototype._showPrompt_GNOME = null;
delete UnlockDialog.prototype._showPrompt_GNOME;
UnlockDialog.UnlockDialog.prototype._showClock_GNOME = null;
delete UnlockDialog.UnlockDialog.prototype._showClock_GNOME;
UnlockDialog.UnlockDialog.prototype._showPrompt_GNOME = null;
delete UnlockDialog.UnlockDialog.prototype._showPrompt_GNOME;
}
this.enabled = false;
}
Expand Down
4 changes: 1 addition & 3 deletions buildzip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
# the tools, but test builds in VMs it (generally) should be ok

glib-compile-schemas schemas/
intltool-extract --type=gettext/glade ui/Settings.ui
intltool-extract --type=gettext/glade ui/Settings4.ui
intltool-extract --type=gettext/glade ui/carousel.ui
intltool-extract --type=gettext/glade ui/carousel4.ui
xgettext -k -k_ -kN_ --omit-header -o locale/BingWallpaper.pot ui/Settings.ui.h ui/Settings4.ui.h ui/carousel.ui.h ui/carousel4.ui.h extension.js prefs.js blur.js utils.js convenience.js --from-code=UTF-8
xgettext -k -k_ -kN_ --omit-header -o locale/BingWallpaper.pot ui/Settings4.ui.h ui/carousel4.ui.h ui/intervals.utils.js.h extension.js prefs.js blur.js utils.js convenience.js --from-code=UTF-8

DATE=`date +"%F"`
echo "# Translation status of statements as at $DATE:" > translations.txt
Expand Down
96 changes: 29 additions & 67 deletions carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
// See the GNU General Public License, version 3 or later for details.
// Based on GNOME shell extension NASA APOD by Elia Argentieri https://github.com/Elinvention/gnome-shell-extension-nasa-apod

const { Gtk, Gdk, GdkPixbuf, Gio, GLib } = imports.gi;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
import Gtk from 'gi://Gtk';
import Gdk from 'gi://Gdk';
import GdkPixbuf from 'gi://GdkPixbuf';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import * as Utils from './utils.js';
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

const Gettext = imports.gettext.domain('BingWallpaper');
const _ = Gettext.gettext;
const default_dimensions = [30, 30, 1650, 800]; // TODO: pull from and save dimensions to settings, but perhaps verify that dimensions are ok

const GALLERY_THUMB_WIDTH = 320;
const GALLERY_THUMB_HEIGHT = 180;

var Carousel = class Carousel {
export default class Carousel {
constructor(settings, button = null, callbackfunc = null, prefs_flowbox = null) {
//create_gallery(widget, settings);
this.settings = settings;
Expand All @@ -28,6 +30,7 @@ var Carousel = class Carousel {
this.window = null;
this.imageList = Utils.imageListSortByDate(Utils.getImageList(this.settings)).reverse(); // get images and reverse order
this.searchEntry = null;
this.extensionPath = ExtensionPreferences.lookupByUUID('[email protected]').path

this.log('create carousel...');

Expand Down Expand Up @@ -63,46 +66,30 @@ var Carousel = class Carousel {

win.set_default_size(dimensions[2], dimensions[3]);
win.set_title(title);

if (Gtk.get_major_version() < 4) {
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel.ui', ['carouselScrollable']);
flowBox = buildable.get_object('carouselFlowBox');
win.add(buildable.get_object('carouselScrollable'));
}
else {
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel4.ui', ['carouselViewPort']);
flowBox = buildable.get_object('carouselFlowBox');
win.set_child(buildable.get_object('carouselScrollable'));
}

buildable.add_objects_from_file(this.extensionPath + '/ui/carousel4.ui', ['carouselViewPort']);
flowBox = buildable.get_object('carouselFlowBox');
win.set_child(buildable.get_object('carouselScrollable'));
return [win, flowBox];
}

_create_gallery() {
Utils.randomIntervals.forEach((seconds, i) => {
let item = this._create_random_item(seconds, Utils.randomIntervalsTitle[i]);
if (Gtk.get_major_version() < 4)
this.flowBox.add(item);
else
this.flowBox.insert(item, -1);
Utils.randomIntervals.forEach((x) => {
let item = this._create_random_item(x.value, _(x.title));
this.flowBox.insert(item, -1);
});

this.imageList.forEach((image) => {
let item = this._create_gallery_item(image);
if (Gtk.get_major_version() < 4)
this.flowBox.add(item);
else
this.flowBox.insert(item, -1);
this.flowBox.insert(item, -1);
});
}

_create_gallery_item(image) {
let buildable = new Gtk.Builder();

// grab appropriate object from UI file
if (Gtk.get_major_version() < 4)
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel.ui', ["flowBoxChild"]);
else
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel4.ui', ["flowBoxChild"]);
buildable.add_objects_from_file(this.extensionPath + '/ui/carousel4.ui', ["flowBoxChild"]);

// assign variables to the UI objects we've just loaded
let galleryImage = buildable.get_object('galleryImage');
Expand All @@ -126,12 +113,7 @@ var Carousel = class Carousel {
this._load_image(galleryImage, filename);
}
catch (e) {
if (Gtk.get_major_version() < 4) {
galleryImage.set_from_icon_name('image-missing', '64x64');
}
else {
galleryImage.set_from_icon_name('image-missing');
}
galleryImage.set_from_icon_name('image-missing');
galleryImage.set_icon_size = 2; // Gtk.GTK_ICON_SIZE_LARGE;
this.log('create_gallery_image: '+e);
}
Expand All @@ -156,6 +138,8 @@ var Carousel = class Carousel {
deleteButton.connect('clicked', (widget) => {
this.log('Delete requested for '+filename);
Utils.deleteImage(filename);
//Utils.cleanupImageList(this.settings);
Utils.hideImage(this.settings, [image]);
Utils.cleanupImageList(this.settings);
widget.get_parent().get_parent().set_visible(false); // bit of a hack
if (this.callbackfunc)
Expand All @@ -182,26 +166,21 @@ var Carousel = class Carousel {
return item;
}

_create_random_item(seconds, title) {
_create_random_item(interval, title) {
let buildable = new Gtk.Builder();

// grab appropriate object from UI file
if (Gtk.get_major_version() < 4) {
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel.ui', ["flowBoxRandom"]);
}
else {
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel4.ui', ["flowBoxRandom"]);
}
buildable.add_objects_from_file(this.extensionPath + '/ui/carousel4.ui', ["flowBoxRandom"]);

let randomLabel = buildable.get_object('randomLabel');
randomLabel.set_text(title);
let filename = 'random';
let applyButton = buildable.get_object('randomButton');

applyButton.connect('clicked', (widget) => {
this.settings.set_string('selected-image', filename);
this.settings.set_int('random-interval', seconds);
this.log('gallery selected random with interval '+seconds);
this.settings.set_string('random-interval-mode', interval);
this.settings.set_boolean('random-mode-enabled', true);
this.log('gallery selected random with interval '+interval+' ('+title+')');
});

let item = buildable.get_object('flowBoxRandom');
Expand All @@ -213,16 +192,12 @@ var Carousel = class Carousel {
this.flowBox.set_max_children_per_line(1);

// grab appropriate object from UI file
if (Gtk.get_major_version() >= 4) {
buildable.add_objects_from_file(Me.dir.get_path() + '/ui/carousel4.ui', ["flowBoxPlaceholder"]);
}
else {
return null;
}
buildable.add_objects_from_file(this.extensionPath + '/ui/carousel4.ui', ["flowBoxPlaceholder"]);

let loadButton = buildable.get_object('loadButton');

loadButton.connect('clicked', (widget) => {
widget.set_label(_("Loading...")); // does this work???
this.flowBox.remove(widget.get_parent());
this.flowBox.set_max_children_per_line(2);
this._create_gallery();
Expand Down Expand Up @@ -264,13 +239,7 @@ var Carousel = class Carousel {
pixbuf.savev(image_thumb_path,'jpeg',['quality'], ['90']);
}

if (Gtk.get_major_version() < 4) {
galleryImage.set_from_pixbuf(pixbuf);
}
else {
galleryImage.set_pixbuf(pixbuf);
}

galleryImage.set_pixbuf(pixbuf);
}
catch (e) {
this._set_blank_image(galleryImage);
Expand All @@ -280,15 +249,8 @@ var Carousel = class Carousel {
}

_set_blank_image(galleryImage) {
if (Gtk.get_major_version() < 4) {
galleryImage.set_from_icon_name('image-missing', '64x64');
galleryImage.set_icon_size = 3; // Gtk.GTK_ICON_SIZE_LARGE;
}
else {
//galleryImage.set_from_icon_name('image-missing');
//galleryImage.set_icon_size = 2; // Gtk.GTK_ICON_SIZE_LARGE;
}

}

log(msg) {
Expand Down
45 changes: 6 additions & 39 deletions convenience.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

const Config = imports.misc.config;

const versionArray = (v) => v.split(".").map(Number);

Expand All @@ -44,7 +43,7 @@ function versionEqual(a, b) {
, true);
}

function versionGreater(a, b) {
export function versionGreater(a, b) {
const diff = zip(versionArray(a), versionArray(b), 0).find(([a, b]) => a !== b);
if (!diff) {
return false;
Expand All @@ -53,42 +52,10 @@ function versionGreater(a, b) {
return x > y;
}

function versionSmaller(a, b) {
return (!versionEqual(a, b)) && (!versionGreater(a, b));
}

function currentVersion() {
return ''+Config.PACKAGE_VERSION.replace(/(alpha|beta)/,'0');
}

function currentVersionEqual(v) {
return versionEqual(currentVersion(), v);
}

function currentVersionGreater(v) {
return versionGreater(currentVersion(), v);
}

function currentVersionGreaterEqual(v) {
return versionEqual(currentVersion(), v)
|| versionGreater(currentVersion(), v);
}

function currentVersionSmaller(v) {
return versionSmaller(currentVersion(), v);
}

function currentVersionSmallerEqual(v) {
return versionEqual(currentVersion(), v)
&& (!versionGreater(currentVersion(), v));
export function versionGreaterEqual(a,b) {
return versionEqual(a, b) || versionGreater(a, b);
}

var exports = {
currentVersion,
currentVersionEqual,
currentVersionGreater,
currentVersionGreaterEqual,
currentVersionSmaller,
currentVersionSmallerEqual
};

function versionSmaller(a, b) {
return (!versionEqual(a, b)) && (!versionGreater(a, b));
}
Loading

0 comments on commit e0e445a

Please sign in to comment.