Skip to content

Commit

Permalink
checGetting rid of the wakeupfeature
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrajnak committed Jun 13, 2019
1 parent b056af1 commit dad8fda
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 179 deletions.
30 changes: 3 additions & 27 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const RIGHT = 2;

// remeber connect methods ids
let hChangeEventId, mChangeEventId, sChangeEventId, aChangeEventId;
let notificationsEventId, hideTimeEventId, startChangeEventId, sleepWithWakeEventId;
let notificationsEventId, hideTimeEventId, startChangeEventId;
let positionEventId, tChangeEventId, shutdownTimerButton, settings, time, h, m, s;
let notificationsEnable, hideTime;
let isRunning = false;
Expand Down Expand Up @@ -78,7 +78,7 @@ const ShutdownTimerButton = new Lang.Class({
this.menu.addMenuItem(this.popupMenu);

// First Item
let newTimer = new PopupMenu.PopupMenuItem( _("Edit Time / Settings"));
let newTimer = new PopupMenu.PopupMenuItem(_("Set Timer / Settings"));
this.popupMenu.addMenuItem(newTimer, 0);
// Second Item
let pauseTimer = new PopupMenu.PopupMenuItem(_("Pause / Resume"));
Expand Down Expand Up @@ -380,28 +380,6 @@ function changePosition(){

}

function sleepWithWakeUp(){
let pkexec = GLib.find_program_in_path('pkexec');
let rtcwake = GLib.find_program_in_path('rtcwake');
let wh = settings.get_int("wake-hours-value");
let wm = settings.get_int("wake-minutes-value");
let ws = settings.get_int("wake-seconds-value");

let wakeUpTime = new Date();
wakeUpTime.setHours(wh);
wakeUpTime.setMinutes(wm);
wakeUpTime.setSeconds(ws);

let now = new Date();
if (wakeUpTime < now.getTime()) {
wakeUpTime.setDate(wakeUpTime.getDate() + 1)
}
let t = Math.floor(wakeUpTime.getTime()/1000)
global.log("pkexec" + " rtcwake" + " -m mem -t " + t.toString());

Util.spawnCommandLine(pkexec + " " + rtcwake + " -m mem -t " + t.toString());
}

function toggleNotifications(){
notificationsEnable = settings.get_boolean("notifications");
}
Expand Down Expand Up @@ -432,7 +410,6 @@ function prepareSettings(){
positionEventId = settings.connect("changed::position", changePosition);
notificationsEventId = settings.connect("changed::notifications", toggleNotifications);
hideTimeEventId = settings.connect("changed::hide-time", toggleHideTime);
sleepWithWakeEventId = settings.connect("changed::wake-up", sleepWithWakeUp)
shutdownTimerButton._bindShortcuts();
changeIcon();
onTimeUpdate();
Expand All @@ -451,7 +428,7 @@ function init(){
*/
function enable(){
shutdownTimerButton = new ShutdownTimerButton();
Main.panel.addToStatusArea('shutdown-timer-gnome-shell-extensionr', shutdownTimerButton, 1);
changePosition();
prepareSettings();
}

Expand All @@ -469,6 +446,5 @@ function disable(){
settings.disconnect(positionEventId);
settings.disconnect(notificationsEventId);
settings.disconnect(hideTimeEventId);
settings.disconnect(sleepWithWakeEventId);
shutdownTimerButton.destroy()
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"gettext-domain": "AutomaticShutdownTimer",
"settings-schema": "org.gnome.shell.extensions.automatic-shutdown-timer",
"url": "https://github.com/mkrajnak/shutdown-timer-gnome-shell-extension/",
"shell-version": [ "3.26", "3.24", "3.22", "3.20", "3.16", "3.14"],
"shell-version": [ "3.32", "3.30", "3.28", "3.26", "3.24", "3.22", "3.20", "3.16", "3.14"],
"version": 0.9
}
122 changes: 1 addition & 121 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const LEFT = 0;
const MIDDLE = 1;
const RIGHT = 2;
const TIME_FONT_HEIGHT = "30";
const WAKE_TIME_FONT_HEIGHT = "30";
let settings, widget;

function init() {
Expand Down Expand Up @@ -61,11 +60,6 @@ const AutomaticShutdownTimerPrefs = new GObject.Class({
this.setTime.column_homogeneous = true;
this.setTime.row_spacing = this.column_spacing = 10;

this.wakeUpTime = new Gtk.Grid()
this.wakeUpTime.margin = 5;
this.wakeUpTime.column_homogeneous = true;
this.wakeUpTime.row_spacing = this.column_spacing = 10;

this.opt = new Gtk.Grid()
this.opt.margin = 5;
this.opt.column_homogeneous = true;
Expand All @@ -91,8 +85,7 @@ const AutomaticShutdownTimerPrefs = new GObject.Class({
let timeSet = settings.get_int("timer")
if (timeSet === SHUTDOWNONTIME) {
onTime.active = true;
}
else{
}else{
afterTime.active = true;
}

Expand Down Expand Up @@ -233,119 +226,6 @@ const AutomaticShutdownTimerPrefs = new GObject.Class({
this.setTime.attach(start, 2, 8, 3, 1);
stack.add_titled(this.setTime, "set-timer", _("Set Timer"));

/** WAKE UP FEATURE , SETUP same time widget as above but smaller */
this.wakeUpTime.attach(new Gtk.HSeparator(), 0, 0, 6, 1);
this.wakeUpTime.attach(new Gtk.Label({ label: _("Warning: feature requires root access and leaves your PC unlocked"),
halign: Gtk.Align.CENTER }), 0, 1, 6, 1);

this.wakeUpTime.attach(new Gtk.HSeparator(), 0, 2, 6, 1);
this.wakeUpTime.attach(new Gtk.Label({ label: _("Wake Up Time:"), halign: Gtk.Align.END}), 0, 3, 1, 1);


let wake_hour_label = new Gtk.Label({ label: _(" Hours ")});
let wake_min_label = new Gtk.Label({ label: _("Minutes")});
let wake_sec_label = new Gtk.Label({ label: _("Seconds")});
this.wakeUpTime.attach(wake_hour_label, 2, 3, 1, 1);
this.wakeUpTime.attach_next_to(wake_min_label, wake_hour_label, Gtk.PositionType.RIGHT, 1, 1);
this.wakeUpTime.attach_next_to(wake_sec_label, wake_min_label, Gtk.PositionType.RIGHT, 1, 1);

//3rd row
let wake_hours = new Gtk.SpinButton({ orientation: Gtk.Orientation.VERTICAL});
wake_hours.set_increments(1, 1);
wake_hours.modify_font(Pango.font_description_from_string(WAKE_TIME_FONT_HEIGHT))
wake_hours.set_range(0, 24);
wake_hours.set_value(settings.get_int("wake-hours-value"));
wake_hours.set_wrap(true)
wake_hours.connect("value-changed", Lang.bind(this, function(){
settings.set_int("wake-hours-value", wake_hours.get_value_as_int());
}));
wake_hours.set_value(settings.get_int("wake-hours-value"));
this.wakeUpTime.attach(wake_hours, 2, 4, 1, 1);

let wake_minutes = new Gtk.SpinButton({ orientation: Gtk.Orientation.VERTICAL});
wake_minutes.set_increments(1, 1);
wake_minutes.modify_font(Pango.font_description_from_string(WAKE_TIME_FONT_HEIGHT))
wake_minutes.set_range(-1, 60);
wake_minutes.set_value(settings.get_int("wake-minutes-value"));

let wake_tmp_min = wake_minutes.get_value_as_int()
wake_minutes.connect("value-changed", Lang.bind(this, function(){
let time = wake_minutes.get_value_as_int()
if ( time === 60) {
if (wake_tmp_min < time) {
wake_minutes.set_value(0)
let val = wake_hours.get_value_as_int() + 1
wake_hours.set_value(val)
}
}
if ( time < 0) {
if (wake_tmp_min > time) {
wake_minutes.set_value(59)
let val = wake_hours.get_value_as_int() - 1
wake_hours.set_value(val)
}
}
wake_tmp_min = time;
settings.set_int("wake-minutes-value", wake_minutes.get_value_as_int());
}));
this.wakeUpTime.attach_next_to(wake_minutes, wake_hours, Gtk.PositionType.RIGHT, 1, 1);

// init seconds
let wake_seconds = new Gtk.SpinButton({ orientation: Gtk.Orientation.VERTICAL});
wake_seconds.modify_font(Pango.font_description_from_string(WAKE_TIME_FONT_HEIGHT))
wake_seconds.set_increments(1, 1);
wake_seconds.set_range(-1, 60);
wake_seconds.set_value(settings.get_int("wake-seconds-value"));

// handle change
let wake_tmp_secs = wake_seconds.get_value_as_int()
wake_seconds.connect("value-changed", Lang.bind(this, function(){
let cs_time = wake_seconds.get_value_as_int()
if ( cs_time === 60) {
if (wake_tmp_secs < cs_time) {
wake_seconds.set_value(0)
let val = wake_minutes.get_value_as_int() + 1
if (val === 60) {
wake_hours.set_value(wake_hours.get_value_as_int() + 1)
val = 0
}
wake_minutes.set_value(val)
}
}
if ( cs_time < 0) {
if (wake_tmp_secs > cs_time) {
wake_seconds.set_value(59)
let val = wake_minutes.get_value_as_int()
val = val - 1
if (val < 0) {
let hval;
hval = wake_hours.get_value_as_int()
if (hval > 0) {
wake_hours.set_value(hval - 1)
}
val = 0
}
wake_minutes.set_value(val)
}
}
tmp_secs = cs_time;
settings.set_int("wake-seconds-value", wake_seconds.get_value_as_int());
}));
this.wakeUpTime.attach_next_to(wake_seconds, wake_minutes, Gtk.PositionType.RIGHT, 1, 1);

this.wakeUpTime.attach(new Gtk.HSeparator(), 0, 5, 6, 1);

let wakeStart = new Gtk.Button ({label: _("Good Night!")});
wakeStart.connect("clicked", Lang.bind(this, function(){
settings.set_boolean("wake-up", !settings.get_boolean("wake-up"));
let w = this.get_window()
w.destroy()
}));
this.wakeUpTime.attach(wakeStart, 2, 6, 3, 1);

stack.add_titled(this.wakeUpTime, "set-wake-up-time", _("Sleep & Wake Up"));
// end of Wake Up tab

// start of Option tab
this.opt.attach(new Gtk.HSeparator(), 0, 0, 6, 1);
this.opt.attach(new Gtk.Label({ label: _("Position in panel:"), halign: Gtk.Align.END}), 0, 1, 2, 1);
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,6 @@ sudo glib-compile-schemas schemas -->
<description>Set time value in seconds. Range 0 to 60.</description>
</key>

<key type="i" name="wake-hours-value">
<default>0</default>
<summary>Wake Hours</summary>
<description>
Set time value in hours. Range 0 to 60. Time used by Wake Up feature
</description>
</key>

<key type="i" name="wake-minutes-value">
<default>0</default>
<summary>Wake Minutes</summary>
<description>
Set time value in minutes. Range 0 to 60. Time used by Wake Up feature
</description>
</key>

<key type="i" name="wake-seconds-value">
<default>0</default>
<summary>Wake Seconds</summary>
<description>
Set time value in seconds. Range 0 to 60. Time used by Wake Up feature
</description>
</key>

<key type="i" name="action">
<default>0</default>
<summary>Action</summary>
Expand All @@ -70,12 +46,6 @@ sudo glib-compile-schemas schemas -->
<description>Start new timer</description>
</key>

<key type="b" name="wake-up">
<default>false</default>
<summary>Enable wake up feature</summary>
<description>Wake up feature provided by rtcwake</description>
</key>

<key type="b" name="notifications">
<default>true</default>
<summary>Turn notification on/off</summary>
Expand Down

0 comments on commit dad8fda

Please sign in to comment.