Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #16 from TimurKiyivinski/always-on
Browse files Browse the repository at this point in the history
fix(always on): change schedule at an interval
  • Loading branch information
kiyui authored Feb 19, 2018
2 parents b606d24 + dea392d commit 0d2036d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Gio = imports.gi.Gio
const Lang = imports.lang
const Main = imports.ui.main
const Slider = imports.ui.slider
const Mainloop = imports.mainloop
const PanelMenu = imports.ui.panelMenu
const PopupMenu = imports.ui.popupMenu
const Me = imports.misc.extensionUtils.getCurrentExtension()
Expand Down Expand Up @@ -110,10 +111,27 @@ function Extension () {

// Set enabled 24 hours if set in settings
if (settings.get_boolean('enable-always')) {
log('Setting night light schedule from 0 to 48')
schema.set_boolean('night-light-schedule-automatic', false)
schema.set_double('night-light-schedule-from', 0)
schema.set_double('night-light-schedule-to', 24.0)
function updateSchedule () {
const date = new Date()
const hours = date.getHours()
date.setHours(hours - 6)
const from = date.getHours()
date.setHours(hours + 6)
const to = date.getHours()

print(`Setting night light schedule from ${from} to ${to}`)
schema.set_boolean('night-light-schedule-automatic', false)
schema.set_double('night-light-schedule-from', from)
schema.set_double('night-light-schedule-to', to)
}

updateSchedule()

let id = Mainloop.timeout_add(1000 * 60 * 60, () => {
updateSchedule()
return true;
}, null);
// TODO: Ability to disable this loop
}
}

Expand Down

0 comments on commit 0d2036d

Please sign in to comment.