Skip to content

Commit

Permalink
Merge branch 'release/version-31'
Browse files Browse the repository at this point in the history
  • Loading branch information
BigE committed Aug 17, 2021
2 parents 55a01be + e4abccd commit c1af96d
Show file tree
Hide file tree
Showing 26 changed files with 2,811 additions and 689 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
UUID = [email protected]
VERSION = 29
VERSION = 31

ifeq ($(strip $(DESTDIR)),)
INSTALLBASE = $(HOME)/.local/share/gnome-shell/extensions
Expand All @@ -21,8 +21,12 @@ install: update-translation
echo done

pot:
xgettext --package-name=DeskChanger --package-version=$(VERSION) -k --keyword=_ -o ./po/desk-changer.pot -D ./$(UUID)/ _deskchanger.js convenience.js extension.js prefs.js service.js common/utils.js daemon/interface.js daemon/profile.js daemon/server.js daemon/timer.js ui/control.js ui/panelMenu.js ui/popupMenu.js
xgettext --package-name=DeskChanger --package-version=$(VERSION) -k --keyword=_ -o ./po/desk-changer.pot -D ./$(UUID)/ _deskchanger.js convenience.js extension.js prefs.js resources/ui/prefs.ui service.js common/utils.js daemon/interface.js daemon/profile.js daemon/server.js daemon/timer.js ui/control.js ui/panelMenu.js ui/popupMenu.js

update-translation: all
cd po; \
./compile.sh ../[email protected]/locale;

zipfile: all
cd ./$(UUID)/; \
zip -r ../$(UUID)-$(VERSION).zip . -x 'resources/ui/*' -x 'resources/icons/*' -x 'resources/*.xml' -x 'resources/*.in'
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ interface. The only interface available to the daemon now is the DBus
interface.

#### DBUS Interface
**Name**: org.gnome.Shell.Extensions.DeskChanger.Daemon
**Name**: `org.gnome.Shell.Extensions.DeskChanger.Daemon`

**Path**: /org/gnome/Shell/Extensions/DeskChanger/Daemon
**Path**: `/org/gnome/Shell/Extensions/DeskChanger/Daemon`

##### Methods
* Load(String profile) - Loads the specified profile
* Next() - Moves to the next wallpaper, returns the uri
* Prev() - Moves to the previous wallpaper, returns the uri
* Quit() - Terminates the daemon process
* Start() - Starts the daemon
* Stop() - Stops the daemon
* `Load(String profile)` Loads the specified profile and respective locations
* `Next()` Switches to the next wallpaper, returns the uri
* `Prev()` Switches to the previous wallpaper, returns the uri
* `Quit()` Terminates the daemon process.
* `Start()` Enables automatic rotation and makes the daemon available
* `Stop([Boolean quit])` Disables automatic rotation and makes the daemon
unavaialble for use. If `quit` is `true` then the daemon process will be
terminated.

##### Properties
* History - Read only array of history
Expand All @@ -75,7 +77,7 @@ To view the settings in dconf-editor, just use the `GSETTINGS_SCHEMA_DIR=`
environment variable to open dconf-editor with the extensions schema available
to the editor.

>$ GSETTINGS_SCHEMA_DIR=~/.local/share/gnome-shell/extensions/desk-[email protected]/schemas/ dconf-editor`
>$ GSETTINGS_SCHEMA_DIR=~/.local/share/gnome-shell/extensions/desk-[email protected]/schemas/ dconf-editor /org/gnome/shell/extensions/desk-changer
Then navigate to `org.gnome.shell.extensions.desk-changer` and you will see
Then navigate to `/org/gnome/shell/extensions/desk-changer` and you will see
all of the available settings for the extension and daemon.
27 changes: 19 additions & 8 deletions [email protected]/_deskchanger.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';

const Gio = imports.gi.Gio;
const GIRepository = imports.gi.GIRepository;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const {Gio, GIRepository, GLib, GObject, Gtk} = imports.gi;

String.prototype.format = imports.format.format;

globalThis.deskchanger = {
let _deskchanger = {
extdatadir: (() => {
let m = /@(.+):\d+/.exec((new Error()).stack.split('\n')[1]);
return Gio.File.new_for_path(m[1]).get_parent().get_path();
Expand Down Expand Up @@ -53,6 +50,12 @@ globalThis.deskchanger = {
},
};

if (typeof globalThis === 'undefined') {
window.deskchanger = _deskchanger;
} else {
globalThis.deskchanger = _deskchanger;
}

deskchanger.app_id = 'org.gnome.Shell.Extensions.DeskChanger';
deskchanger.app_path = '/org/gnome/Shell/Extensions/DeskChanger';
deskchanger.metadata = (() => {
Expand Down Expand Up @@ -134,7 +137,7 @@ deskchanger._ = Gettext.gettext;
var Settings = GObject.registerClass(
class DeskChangerSettings extends Gio.Settings {
get allowed_mime_types() {
return this.get_value('allowed-mime-types').deep_unpack();
return this.get_value('allowed-mime-types').recursiveUnpack();
}

set allowed_mime_types(value) {
Expand Down Expand Up @@ -199,15 +202,15 @@ class DeskChangerSettings extends Gio.Settings {
}

get profile_state() {
return this.get_value('profile-state').deep_unpack();
return this.get_value('profile-state').recursiveUnpack();
}

set profile_state(value) {
this.set_value('profile-state', new GLib.Variant('a{sas}', value));
}

get profiles() {
return this.get_value('profiles').deep_unpack();
return this.get_value('profiles').recursiveUnpack();
}

set profiles(value) {
Expand Down Expand Up @@ -298,3 +301,11 @@ deskchanger.dbusxml = deskchanger.get_resource(`${deskchanger.app_id}.xml`);
deskchanger.dbusinfo = Gio.DBusNodeInfo.new_for_xml(deskchanger.dbusxml);

deskchanger.dbusinfo.nodes.forEach(info => info.cache_build());


let builder = new Gtk.Builder();

builder.set_translation_domain('desk-changer');
builder.add_from_resource(`${deskchanger.app_path}/ui/rotation.ui`);

deskchanger.rotation = builder.get_object('rotation');
46 changes: 34 additions & 12 deletions [email protected]/daemon/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;

if (!globalThis.deskchanger) {
if ((typeof globalThis !== 'undefined' && !globalThis.deskchanger) || !window.deskchanger) {
// Find the root datadir of the extension
function get_datadir() {
let m = /@(.+):\d+/.exec((new Error()).stack.split('\n')[1]);
Expand Down Expand Up @@ -83,7 +83,7 @@ class Server extends Gio.Application {
let connection = this.get_dbus_connection();

if (connection) {
deskchanger.debug(`DBUS::${signal}(${variant.deepUnpack()})`);
deskchanger.debug(`DBUS::${signal}(${variant.recursiveUnpack()})`);
connection.emit_signal(null, Interface.APP_PATH, Interface.APP_ID, signal, variant);
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ class Server extends Gio.Application {
object_path,
deskchanger.dbusinfo.lookup_interface(Interface.APP_ID),
(connection, sender, object_path, interface_name, method_name, parameters, invocation) => {
parameters = parameters.unpack();
parameters = parameters.recursiveUnpack();
deskchanger.debug(`[DBUS.call] ${interface_name}.${method_name}(${parameters})`)

if (!this._running && ['quit', 'start'].indexOf(method_name.toLowerCase()) === -1) {
Expand Down Expand Up @@ -263,14 +263,32 @@ class Server extends Gio.Application {
}

_create_timer() {
if (deskchanger.settings.rotation === 'interval') {
this._timer = new Timer.Interval(deskchanger.settings.interval, this.next.bind(this));
this._interval_changed_id = deskchanger.settings.connect('changed::interval', () => {
this._timer.destroy();
this._timer = new Timer.Interval(deskchanger.settings.interval, this.next.bind(this));
});
let interval,
rotation = deskchanger.settings.rotation,
[success, iterator] = deskchanger.rotation.get_iter_first();

while (success) {
if (deskchanger.rotation.get_value(iterator, 0) === rotation) {
interval = (rotation === 'interval')? deskchanger.settings.interval : deskchanger.rotation.get_value(iterator, 3);
rotation = deskchanger.rotation.get_value(iterator, 1);
break;
}

success = deskchanger.rotation.iter_next(iterator);
}

if (rotation === 'interval') {
this._timer = new Timer.Interval(interval, this.next.bind(this));
if (deskchanger.settings.rotation === 'interval') {
this._interval_changed_id = deskchanger.settings.connect('changed::interval', () => {
this._timer.destroy();
this._timer = new Timer.Interval(deskchanger.settings.interval, this.next.bind(this));
});
}
} else if (deskchanger.settings.rotation === 'hourly') {
this._timer = new Timer.Hourly(this.next.bind(this));
} else if (deskchanger.settings.rotation === 'daily') {
this._timer = new Timer.Daily(this.next.bind(this));
}
}

Expand All @@ -286,8 +304,8 @@ class Server extends Gio.Application {
}
}

_dbus_call_loadprofile(invocation, profile) {
invocation.return_value(new GLib.Variant('(b)', [this.loadprofile(profile.get_string()[0])]));
_dbus_call_load(invocation, profile) {
invocation.return_value(new GLib.Variant('(b)', [this.loadprofile(profile)]));
}

_dbus_call_next(invocation) {
Expand All @@ -307,8 +325,12 @@ class Server extends Gio.Application {
invocation.return_value(new GLib.Variant('(b)', [this.start(), ]));
}

_dbus_call_stop(invocation) {
_dbus_call_stop(invocation, quit) {
invocation.return_value(new GLib.Variant('(b)', [this.stop(), ]));

if (quit) {
this.quit();
}
}

_handle_dbus_get(connection, sender, object_path, interface_name, property_name) {
Expand Down
38 changes: 30 additions & 8 deletions [email protected]/daemon/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ const Signals = imports.signals;

var Interval = GObject.registerClass({
Properties: {
interval: GObject.ParamSpec.uint('interval', 'Interval', 'The interval that the callback is called.',
GObject.ParamFlags.READABLE, 0, GLib.MAXUINT32, 300),
interval: GObject.ParamSpec.uint('interval', 'Interval',
'The interval at which the callback is triggered',
GObject.ParamFlags.READABLE, 1, GLib.MAXUINT32, 300),
},
},
class DeskChangerTimerInterval extends GObject.Object {
_init(interval = 300, callback = null, params = {}) {
_init(interval, callback = null, params = {}) {
if (callback && typeof callback !== 'function') {
throw 'callback must be function';
}

if (!interval || interval < 1) {
throw 'invalid interval, must be 1 or higher';
}

this._callback = callback;
this._interval = parseInt(interval);
super._init(params);
this._timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this._interval, this.__callback__.bind(this));
deskchanger.debug(`added timer ${this._timer}`);
deskchanger.debug(`added interval(${this._interval}) timer ${this._timer}`);
}

get callback() {
Expand All @@ -41,7 +46,7 @@ class DeskChangerTimerInterval extends GObject.Object {
}

destroy() {
deskchanger.debug(`removing timer ${this._timer}`);
deskchanger.debug(`removing interval timer ${this._timer}`);
GLib.source_remove(this._timer);
}
});
Expand All @@ -53,10 +58,16 @@ class DeskChangerTimerHourly extends Interval {
super._init(5, callback, params);
}

__callback__() {
let date = new Date();

_timer_check(date) {
if (date.getMinutes() === 0 && date.getSeconds() < 10) {
return true;
}

return false
}

__callback__() {
if (this._timer_check(new Date())) {
if (!this._done) {
this._done = true;
deskchanger.debug('calling hourly callback');
Expand All @@ -70,3 +81,14 @@ class DeskChangerTimerHourly extends Interval {
return true;
}
});

var Daily = GObject.registerClass(
class DeskChangerTimerDaily extends Hourly {
_timer_check(date) {
if (super._timer_check(date) && date.getHours() === 0) {
return true;
}

return false;
}
});
26 changes: 23 additions & 3 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,35 @@ function enable() {
});

rotation_id = deskchanger.settings.connect('changed::rotation', function () {
let message;
let message, interval,
rotation = deskchanger.settings.rotation,
[success, iterator] = deskchanger.rotation.get_iter_first();

while (success) {
if (deskchanger.rotation.get_value(iterator, 0) === rotation) {
if (rotation === 'interval') {
interval = `${deskchanger.rotation.get_value(iterator, 2)} of ${deskchanger.settings.interval} seconds`;
} else {
interval = deskchanger.rotation.get_value(iterator, 2);
}

rotation = deskchanger.rotation.get_value(iterator, 1);
break;
}

success = deskchanger.rotation.iter_next(iterator);
}

switch (deskchanger.settings.rotation) {
switch (rotation) {
case 'interval':
message = _('Rotation will occur every %d seconds'.format(deskchanger.settings.interval));
message = _(`Rotation will occur at a ${interval}`);
break;
case 'hourly':
message = _('Rotation will occur at the beginning of every hour');
break;
case 'daily':
message = _('Rotation will occur at the beginning of every day');
break;
default:
message = _('Rotation has been disabled');
break;
Expand Down
8 changes: 4 additions & 4 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"description": "Simple wallpaper changer with multiple profile support. Supports integration into the system menu or its own panel icon. The daemon is written in Python and runs independently of the extension.",
"description": "Simple wallpaper changer with multiple profile support. Supports integration into the system menu or its own panel icon. The daemon is written using gjs and runs independently of the extension.",
"gettext-domain": "desk-changer",
"name": "Desk Changer",
"settings-schema": "org.gnome.shell.extensions.desk-changer",
"shell-version": [
"3.30",
"3.32",
"3.34",
"3.36",
"3.38"
"3.38",
"40.0"
],
"url": "https://github.com/BigE/desk-changer/",
"uuid": "[email protected]",
"version": "30"
"version": "31"
}
Loading

0 comments on commit c1af96d

Please sign in to comment.