Skip to content

Commit

Permalink
Merge branch 'release/version-29'
Browse files Browse the repository at this point in the history
  • Loading branch information
BigE committed Mar 19, 2020
2 parents 87da66c + a862650 commit 474865b
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 94 deletions.
28 changes: 28 additions & 0 deletions [email protected]/convenience.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,31 @@ function getStack() {

return stack
}

function checkShellVersion(version, comparison) {
let shell_version = Config.PACKAGE_VERSION,
shell_version_major = shell_version.split('.')[0],
shell_version_minor = shell_version.split('.')[1],
compare_version_major = version.split('.')[0],
compare_version_minor = version.split('.')[1];

switch (comparison) {
case '>':
return shell_version_major > compare_version_major && shell_version_minor > compare_version_minor;
case '<':
return shell_version_major < compare_version_major && shell_version_minor < compare_version_minor;
case '<=':
return shell_version_major <= compare_version_major && shell_version_minor <= compare_version_minor;
case '>=':
return shell_version_major >= compare_version_major && shell_version_minor >= compare_version_minor;
case '!=':
return shell_version_major != compare_version_major && shell_version_minor != compare_version_minor;
case '!==':
return shell_version_major !== compare_version_major && shell_version_minor !== compare_version_minor;
case '===':
return shell_version_major === compare_version_major && shell_version_minor === compare_version_minor;
case '==':
default:
return shell_version_major == compare_version_major && shell_version_minor == compare_version_minor;
}
}
2 changes: 0 additions & 2 deletions [email protected]/daemon/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ class DeskChangerProfile extends GObject.Object {
}
);

Signals.addSignalMethods(Profile.prototype);

let ProfileQueue = GObject.registerClass({
Properties: {
'length': GObject.ParamSpec.uint('length', 'Length', 'The length of the current queue',
Expand Down
20 changes: 19 additions & 1 deletion [email protected]/daemon/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ class DeskChangerDaemon extends DaemonDBusServer {
this.desktop_profile.load();
this.lockscreen_profile.load();
super.start();
this._timer = new Timer.Timer(this._settings.get_int('interval'), this.next.bind(this));
this._check_timer(this._settings);

this._settings.connect('changed::rotation', (settings, key) => {
this._check_timer(settings);
});
}

stop() {
Expand All @@ -218,6 +222,20 @@ class DeskChangerDaemon extends DaemonDBusServer {
super.stop();
}

_check_timer(settings) {
if (this._timer) {
// no matter the change, destroy the current timer
this._timer.destroy();
this._timer = null;
}

if (settings.rotation == 'interval') {
this._timer = new Timer.Interval(settings.get_int('interval'), this.next.bind(this));
} else if (settings.rotation == 'hourly') {
this._timer = new Timer.Hourly(this.next.bind(this));
}
}

_dbus_handle_call(connection, sender, object_path, interface_name, method_name, parameters, invocation) {
switch (method_name.toLowerCase()) {
case 'loadprofile':
Expand Down
18 changes: 7 additions & 11 deletions [email protected]/daemon/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const GObject = imports.gi.GObject;
const Signals = imports.signals;


var Timer = GObject.registerClass({
var Interval = GObject.registerClass({
Properties: {
'interval': GObject.ParamSpec.uint('interval', 'Interval', 'The interval that the callback is called.',
interval: GObject.ParamSpec.uint('interval', 'Interval', 'The interval that the callback is called.',
GObject.ParamFlags.READABLE, 0, GLib.MAXUINT32, 300),
},
},
class DeskChangerTimer extends GObject.Object {
class DeskChangerTimerInterval extends GObject.Object {
_init(interval = 300, callback = null, params = {}) {
if (callback && typeof callback !== 'function') {
throw 'callback must be function';
Expand All @@ -34,9 +34,8 @@ class DeskChangerTimer extends GObject.Object {
}

__callback__() {
this.emit('callback', this._callback, this._interval);

if (this._callback) {
Utils.debug(`calling callback ${this._callback}`);
return Boolean(this._callback());
}

Expand All @@ -45,15 +44,12 @@ class DeskChangerTimer extends GObject.Object {

destroy() {
Utils.debug(`removing timer ${this._timer}`);
GLib.remove_source(this._timer);
GLib.source_remove(this._timer);
}
});

Signals.addSignalMethods(Timer.prototype);


var TimerHourly = GObject.registerClass(
class DeskChangerTimerHourly extends Timer {
var Hourly = GObject.registerClass(
class DeskChangerTimerHourly extends Interval {
_init(callback, params = {}) {
this._done = false;
super._init(5, callback, params);
Expand Down
7 changes: 3 additions & 4 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"name": "Desk Changer",
"settings-schema": "org.gnome.shell.extensions.desk-changer",
"shell-version": [
"3.26",
"3.28",
"3.30",
"3.32",
"3.34"
"3.34",
"3.36"
],
"url": "https://github.com/BigE/desk-changer/",
"uuid": "[email protected]",
"version": "28"
"version": "29"
}
68 changes: 40 additions & 28 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DeskChangerPrefs extends GObject.Object {

this.box.pack_start(notebook, true, true, 0);
this.box.show_all();
super._init();
}

_init_daemon(notebook, settings, daemon) {
Expand Down Expand Up @@ -181,6 +182,7 @@ class DeskChangerPrefs extends GObject.Object {
lockscreen_profile = new Gtk.ComboBoxText(),
switch_icon_preview = new Gtk.Switch(),
switch_notifications = new Gtk.Switch();

// Profiles
box.pack_start(label, false, false, 5);
label = new Gtk.Label({label: ' '});
Expand All @@ -195,39 +197,48 @@ class DeskChangerPrefs extends GObject.Object {
});
box.pack_start(current_profile, false, false, 5);
frame_box.pack_start(box, false, false, 10);
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Update LockScreen Background')});
box.pack_start(label, false, false, 5);
label = new Gtk.Label({label: ' '});
box.pack_start(label, true, true, 5);
update_lockscreen.set_active(settings.update_lockscreen);
update_lockscreen.connect('notify::active', () => {
settings.update_lockscreen = update_lockscreen.get_state();
});
box.pack_start(update_lockscreen, false, false, 5);
frame_box.pack_start(box, false, false, 10);
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Lockscreen Profile')});
box.pack_start(label, false, false, 5);
label = new Gtk.Label({label: ' '});
box.pack_start(label, true, true, 5);
lockscreen_profile.connect('key-press-event', (widget, event) => {
let keyval = event.get_keyval();
if (keyval[0] && keyval[1] === Gdk.KEY_BackSpace) {

if (Convenience.checkShellVersion('3.35', '<')) {
// Update Lockscreen Background
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Update LockScreen Background')});
box.pack_start(label, false, false, 5);
label = new Gtk.Label({label: ' '});
box.pack_start(label, true, true, 5);
update_lockscreen.set_active(settings.update_lockscreen);
update_lockscreen.connect('notify::active', () => {
settings.update_lockscreen = update_lockscreen.get_state();
});

// Lockscreen Profile
box.pack_start(update_lockscreen, false, false, 5);
frame_box.pack_start(box, false, false, 10);
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Lockscreen Profile')});
box.pack_start(label, false, false, 5);
label = new Gtk.Label({label: ' '});
box.pack_start(label, true, true, 5);
lockscreen_profile.connect('key-press-event', (widget, event) => {
let keyval = event.get_keyval();
if (keyval[0] && keyval[1] === Gdk.KEY_BackSpace) {
lockscreen_profile.set_active(-1);
}
});

this._load_profiles(lockscreen_profile, settings, settings.lockscreen_profile);
if (!settings.lockscreen_profile) {
lockscreen_profile.set_active(-1);
}
});
this._load_profiles(lockscreen_profile, settings, settings.lockscreen_profile);
if (!settings.lockscreen_profile) {
lockscreen_profile.set_active(-1);
lockscreen_profile.connect('changed', (object) => {
settings.lockscreen_profile = object.get_active_text();
});
box.pack_start(lockscreen_profile, false, false, 5);
frame_box.pack_start(box, false, false, 5);
}
lockscreen_profile.connect('changed', (object) => {
settings.lockscreen_profile = object.get_active_text();
});
box.pack_start(lockscreen_profile, false, false, 5);
frame_box.pack_start(box, false, false, 5);

frame.add(frame_box);
extension_box.pack_start(frame, false, false, 10);

// Preview as Icon
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Show Preview as Icon')});
Expand All @@ -240,6 +251,7 @@ class DeskChangerPrefs extends GObject.Object {
});
box.pack_start(switch_icon_preview, false, false, 5);
extension_box.pack_start(box, false, false, 5);

// Notifications
box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
label = new Gtk.Label({label: _('Show Notifications')});
Expand Down
11 changes: 8 additions & 3 deletions [email protected]/ui/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var ButtonControl = GObject.registerClass(
class DeskChangerControlButtonControl extends St.Button {
_init(icon, callback) {
this._icon = new St.Icon({icon_name: `${icon}-symbolic`, icon_size: 20});
super._init({child: this._icon, style_class: 'system-menu-action'});
super._init({child: this._icon, style_class: 'button'});
this._clicked_id = this.connect('clicked', callback);
Utils.debug(`connect clicked (${this._clicked_id})`);
}
Expand All @@ -27,6 +27,10 @@ class DeskChangerControlButtonControl extends St.Button {
this._icon.destroy();
super.destroy();
}

set_icon(icon) {
this._icon.icon_name = `${icon}-symbolic`;
}
}
);

Expand Down Expand Up @@ -139,8 +143,9 @@ class DeskChangerControlStateButtonControl extends ButtonControl {
state = 0;
}

state = this._states[state].name;
this.set_icon(this._states[state].icon);
this._state = state;
state = this._states[this._state].name;
this.set_icon(this._states[this._state].icon);

if (typeof callback === 'function') {
callback(state);
Expand Down
42 changes: 26 additions & 16 deletions [email protected]/ui/panelMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const DeskChangerPopupMenu = Me.imports.ui.popupMenu;
const DeskChangerControl = Me.imports.ui.control;

Expand All @@ -15,21 +16,24 @@ class DeskChangerPanelMenuButton extends PanelMenu.Button {
super._init(0.0, 'DeskChanger');
this._daemon = daemon;
this._settings = settings;
this._has_lockscreen = Convenience.checkShellVersion('3.35', '<');

this._icon = new Icon(daemon, settings);
this.add_child(this._icon);
this.menu.addMenuItem(new DeskChangerPopupMenu.ProfileDesktopMenuItem(settings));
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(new DeskChangerPopupMenu.SwitchMenuItem(_('Notifications'), 'notifications', settings));
this.menu.addMenuItem(new DeskChangerPopupMenu.SwitchMenuItem(_('Remember profile state'), 'remember_profile_state', settings));
this.menu.addMenuItem(new DeskChangerPopupMenu.SwitchMenuItem(_('Update lock screen'), 'update_lockscreen', settings));
// it looks like the lockscreen background is removed in 3.36
if (this._has_lockscreen) {
this.menu.addMenuItem(new DeskChangerPopupMenu.SwitchMenuItem(_('Update lock screen'), 'update_lockscreen', settings));
}
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(new DeskChangerPopupMenu.PreviewMenuItem(daemon));
this.menu.addMenuItem(new DeskChangerPopupMenu.ControlsMenuItem(daemon, settings));
this.menu.addMenuItem(new DeskChangerPopupMenu.OpenCurrentMenuItem());
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(new DeskChangerPopupMenu.RotationMenuItem(settings));
this.menu.addMenuItem(new DeskChangerPopupMenu.ControlsMenuItem(daemon, settings));
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(new DeskChangerPopupMenu.DaemonMenuItem(daemon));

let menu_item = new PopupMenu.PopupMenuItem(_('DeskChanger Settings'));
Expand All @@ -38,26 +42,32 @@ class DeskChangerPanelMenuButton extends PanelMenu.Button {
});
this.menu.addMenuItem(menu_item);

if (settings.update_lockscreen) {
this.menu.addMenuItem(new DeskChangerPopupMenu.ProfileLockScreenMenuItem(settings), 1);
}

this._update_lockscreen_id = settings.connect('changed::update-lockscreen', (settings, key) => {
if (this._has_lockscreen) {
if (settings.update_lockscreen) {
this.menu.addMenuItem(new DeskChangerPopupMenu.ProfileLockScreenMenuItem(settings), 1);
} else {
this.menu.box.get_children().map((actor) => {
return actor._delegate;
}).filter((item) => {
item instanceof DeskChangerPopupMenu.ProfileLockScreenMenuItem && item.destroy();
});
}
});

this._update_lockscreen_id = settings.connect('changed::update-lockscreen', (settings, key) => {
if (settings.update_lockscreen) {
this.menu.addMenuItem(new DeskChangerPopupMenu.ProfileLockScreenMenuItem(settings), 1);
} else {
this.menu.box.get_children().map((actor) => {
return actor._delegate;
}).filter((item) => {
item instanceof DeskChangerPopupMenu.ProfileLockScreenMenuItem && item.destroy();
});
}
});
}
}

destroy() {
this._icon.destroy();
this._settings.disconnect(this._update_lockscreen_id);

if (this._update_lockscreen_id) {
this._settings.disconnect(this._update_lockscreen_id);
}

super.destroy();
}
}
Expand Down
9 changes: 3 additions & 6 deletions [email protected]/ui/popupMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ class DeskChangerPopupMenuControlsMenuItem extends PopupMenu.PopupBaseMenuItem {
var DaemonMenuItem = GObject.registerClass(
class DeskChangerPopupMenuDaemonMenuItem extends PopupMenu.PopupSwitchMenuItem {
_init(daemon) {
super._init(_('DeskChanger Daemon'));
super._init(_('DeskChanger Daemon'), daemon.running);
this._daemon = daemon;
this.setToggleState(daemon.running);
this._toggled_id = this.connect('toggled', () => {
(daemon.running)? daemon.stop() : daemon.start();
});
Expand Down Expand Up @@ -180,13 +179,12 @@ class DeskChangerPopupMenuItem extends PopupMenu.PopupMenuItem {
let PopupSubMenuMenuItem = GObject.registerClass(
class DeskChangerPopupSubMenuMenuItem extends PopupMenu.PopupSubMenuMenuItem {
_init(prefix, key, settings, sensitive=true) {
super._init('');
super._init(`${prefix}: ${settings[key]}`);
this._prefix = prefix;
this._settings = settings;
this._changed_id = settings.connect(`changed::${key.replace('_', '-')}`, () => {
this.setLabel(settings[key]);
});
this.setLabel(settings[key]);
this.setSensitive(sensitive);
}

Expand Down Expand Up @@ -310,11 +308,10 @@ class DeskChangerPopupMenuRotationMenuItem extends PopupSubMenuMenuItem {
var SwitchMenuItem = GObject.registerClass(
class DeskChangerPopupSwitchMenuItem extends PopupMenu.PopupSwitchMenuItem {
_init(label, key, settings) {
super._init(label);
super._init(label, settings[key]);
this._settings = settings;
this._key = key;
this._key_normalized = key.replace('_', '-');
this.setToggleState(settings[key]);
this._handler_changed = settings.connect(`changed::${this._key_normalized}`, (settings, key) => {
this.setToggleState(settings.get_boolean(key));
});
Expand Down
Loading

0 comments on commit 474865b

Please sign in to comment.