Skip to content

Commit

Permalink
Merge branch 'release/version-20'
Browse files Browse the repository at this point in the history
  • Loading branch information
BigE committed Feb 19, 2017
2 parents 6a76f42 + fb702ae commit 89c8d26
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 76 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ on the fly without reloading the daemon.

### Install

Just simply copy the desk-changer@eric.gach.gmail.com folder to your `~/.local/share/gnome-shell/extensions/` folder or the
system `/usr/share/gnome-shell/extensions/` folder.
Just simply copy the desk-changer@eric.gach.gmail.com folder to your `~/.local/share/gnome-shell/extensions/`
folder or the system `/usr/share/gnome-shell/extensions/` folder.

`cp -r [email protected]/ ~/.local/share/gnome-shell/extensions/`
>$ cp -r [email protected]/ ~/.local/share/gnome-shell/extensions/
or

`cp -r [email protected]/ /usr/share/gnome-shell/extensions/`
>\# cp -r [email protected]/ /usr/share/gnome-shell/extensions/
Then restart gnome-shell and enable the extension. Once it is enabled, you can use the extension to start the daemon
with the built in toggle switch.
Expand All @@ -35,7 +35,8 @@ with the built in toggle switch.

### Daemon

The daemon is simply a Gio.Application running as a service. To view more information about the daemon, run it from the command line with the `-h` or `--help` option.
The daemon is simply a Gio.Application running as a service. To view more information about the daemon, run it from the
command line with the `-h` or `--help` option.

>$ ./desk-changer-daemon.py -h
>Usage:
Expand All @@ -45,3 +46,17 @@ The daemon is simply a Gio.Application running as a service. To view more inform
> -h, --help Show help options
> --help-all Show all help options
>
---

### dconf-editor

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`
Then navigate to `org.gnome.shell.extensions.desk-changer` and you will see all of the available settings for the
extension and daemon.

---
33 changes: 26 additions & 7 deletions [email protected]/desk-changer-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import os.path
import random
import sys
from datetime import datetime
from gi import require_version
from gi.repository import GLib, Gio, GObject
from gi._gi import variant_type_from_string

require_version('Gio', '2.0')

__daemon_path__ = os.path.abspath(os.curdir)
__version__ = '2.0.2'
__version__ = '2.1.0'

DeskChangerDaemonDBusInterface = Gio.DBusNodeInfo.new_for_xml('''<node>
<interface name="org.gnome.Shell.Extensions.DeskChanger.Daemon">
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self, **kwargs):
# internal stuffs
self._accepted = ['application/xml', 'image/jpeg', 'image/png']
self._dbus_id = None
self._did_hourly = False
self._history = []
self._monitors = []
self._position = 0
Expand Down Expand Up @@ -146,7 +148,7 @@ def do_startup(self):
except ValueError as e:
self._emit_signal('error', str(e))
# Connect the settings signals
self._connect_settings_signal('changed::timer-enabled', lambda s, k: self._toggle_timer())
self._connect_settings_signal('changed::rotation', lambda s, k: self._toggle_timer())
self._connect_settings_signal('changed::interval', lambda s, k: self._toggle_timer())
self._connect_settings_signal('changed::current-profile', self._changed_current_profile)
self._connect_settings_signal('changed::random', lambda s, k: self._toggle_random())
Expand Down Expand Up @@ -337,6 +339,18 @@ def _handle_dbus_call(self, connection, sender, object_path, interface_name, met
'Method %s in %s does not exist' % (method_name, interface_name))
return

def _hourly(self):
d = datetime.utcnow()
if d.minute == 0 and d.second < 10:
if not self._did_hourly:
# This should trigger once per hour, right around the beginning of the hour... I hope... I tried to
# account for it not being accurately 5 second intervals
self._did_hourly = True
return self._timeout()
return True
self._did_hourly = False
return True

def _info(self, message, *args):
self._log(GLib.LogLevelFlags.LEVEL_INFO, message, *args)

Expand Down Expand Up @@ -440,14 +454,19 @@ def _toggle_random(self):
self._emit_signal('preview', self._queue[0])

def _toggle_timer(self):
if self._settings.get_boolean('timer-enabled'):
rotation = self._settings.get_string('rotation')
if rotation != 'disabled':
if self._timer is not None:
self._debug('removing old timer')
GLib.source_remove(self._timer)
interval = self._settings.get_int('interval')
self._timer = GLib.timeout_add_seconds(interval, self._timeout)
self._info('automatic timer enabled for %d seconds', interval)
elif self._settings.get_boolean('timer-enabled') is False and self._timer is not None:
if rotation == 'interval':
interval = self._settings.get_int('interval')
self._timer = GLib.timeout_add_seconds(interval, self._timeout)
self._info('automatic timer enabled for %d seconds', interval)
elif rotation == 'hourly':
self._timer = GLib.timeout_add_seconds(5, self._hourly)
self._info('timer enabled for every 5 seconds, wallpaper will change as close to the hour as possible')
elif self._settings.get_string('rotation') == 'disabled' and self._timer is not None:
GLib.source_remove(self._timer)
self._timer = None
self._info('removed automatic timer')
Expand Down
8 changes: 7 additions & 1 deletion [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const DeskChangerSystemIndicator = new Lang.Class({
}
});

let daemon, indicator, settings;
let daemon, indicator, settings, shellSettings;
let changed_id, current_profile_id, error_id, notifications_id;

function disable() {
Expand Down Expand Up @@ -146,6 +146,11 @@ function disable() {
error_id = null;
notifications_id = null;
indicator = null;

if (shellSettings.get_strv('enabled-extensions').indexOf(Me.uuid) === -1 && daemon.is_running) {
debug('Extension disabled, stopping daemon');
daemon.toggle();
}
}

function enable() {
Expand Down Expand Up @@ -186,6 +191,7 @@ function enable() {
function init() {
debug('initalizing extension version: ' + DeskChangerVersion);
settings = new DeskChangerSettings();
shellSettings = new Gio.Settings({'schema': 'org.gnome.shell'});
daemon = new DeskChangerDaemon(settings);

settings.connect('changed::integrate-system-menu', function () {
Expand Down
26 changes: 15 additions & 11 deletions [email protected]/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,33 @@ const DeskChangerControls = new Lang.Class({
}
], Lang.bind(this, this._toggle_random));
this._random.set_state((this._settings.random) ? 'random' : 'ordered');
this._timer = new Ui.DeskChangerStateButton([
this._rotation = new Ui.DeskChangerStateButton([
{
icon: 'media-playback-stop',
name: 'enable'
name: 'interval'
},
{
icon: 'media-playback-start',
name: 'disable'
name: 'disabled'
},
{
icon: 'appointment-new',
name: 'hourly'
}
], Lang.bind(this, this._toggle_timer));
this._timer.set_state((this._settings.timer_enabled) ? 'enable' : 'disable');
], Lang.bind(this, this._toggle_rotation));
this._rotation.set_state(this._settings.rotation);

if (this.addActor) {
this._box = new St.BoxLayout({style: 'spacing: 20px;'});
this.addActor(this._box, {align: St.Align.MIDDLE, span: -1});
this._box.add_actor(this._prev, {expand: true});
this._box.add_actor(this._random, {expand: true});
this._box.add_actor(this._timer, {expand: true});
this._box.add_actor(this._rotation, {expand: true});
this._box.add_actor(this._next, {expand: true});
} else {
this.actor.add_actor(this._prev, {expand: true, x_fill: false});
this.actor.add_actor(this._random, {expand: true, x_fill: false});
this.actor.add_actor(this._timer, {expand: true, x_fill: false});
this.actor.add_actor(this._rotation, {expand: true, x_fill: false});
this.actor.add_actor(this._next, {expand: true, x_fill: false});
}
},
Expand All @@ -97,7 +101,7 @@ const DeskChangerControls = new Lang.Class({
this._next.destroy();
this._prev.destroy();
this._random.destroy();
this._timer.destroy();
this._rotation.destroy();
this.parent();
},

Expand Down Expand Up @@ -158,9 +162,9 @@ const DeskChangerControls = new Lang.Class({
this._settings.random = (state == 'random');
},

_toggle_timer: function (state) {
debug(state + 'ing timer');
this._settings.timer_enabled = (state == 'enable');
_toggle_rotation: function (state) {
debug('setting rotation to ' + state);
this._settings.rotation = state;
}
});

Expand Down
4 changes: 2 additions & 2 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Simple wallpaper changer with multiple profile support.",
"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.",
"name": "Desk Changer",
"shell-version": [
"3.8",
Expand All @@ -16,5 +16,5 @@
],
"url": "https://github.com/BigE/desk-changer/",
"uuid": "[email protected]",
"version": "19"
"version": "20"
}
Loading

0 comments on commit 89c8d26

Please sign in to comment.