JezerM
4 years ago
7 changed files with 257 additions and 107 deletions
After Width: | Height: | Size: 294 KiB |
@ -0,0 +1,70 @@
|
||||
class Backgrounds { |
||||
constructor() { |
||||
this._localStorage = window.localStorage |
||||
this._defaultBackgroundArr = ["assets/dracula.png", "assets/window-blurred.png"] |
||||
this._sidebar = document.querySelector("#sidebar") |
||||
this._backgroundsList = document.querySelector("#background-selector") |
||||
this._background = document.querySelector("#background") |
||||
this._backgroundImages = null |
||||
this._backgroundImagesDir = null |
||||
this._backgroundPath = "" |
||||
} |
||||
|
||||
_createImage(path) { |
||||
let image = document.createElement("img") |
||||
let button = document.createElement("button") |
||||
let imageName = path.replace(/^.*[\\\/]/, '') |
||||
button.classList.add("image") |
||||
image.src = path |
||||
image.alt = imageName |
||||
button.appendChild(image) |
||||
return button |
||||
} |
||||
|
||||
async _createBackgroundArray() { |
||||
let images = await this._getImages() |
||||
this._backgroundImages = this._defaultBackgroundArr.concat(images) |
||||
this._setBackgroundImages() |
||||
return new Promise((resolve) => resolve()) |
||||
} |
||||
|
||||
_updateOnStartup() { |
||||
this._backgroundPath = this._localStorage.getItem("defaultBackgroundImage") || this._backgroundImages[0] |
||||
this._updateBackgroundImages() |
||||
} |
||||
|
||||
_updateBackgroundImages() { |
||||
let img = this._background.querySelector("img") |
||||
img.src = this._backgroundPath |
||||
this._localStorage.setItem("defaultBackgroundImage", String(this._backgroundPath)) |
||||
} |
||||
|
||||
_setBackgroundImages() { |
||||
this._backgroundsList.innerHTML = "" |
||||
for (let i = 0; i < this._backgroundImages.length; i++) { |
||||
const path = this._backgroundImages[i] |
||||
let button = this._createImage(path) |
||||
button.addEventListener("click", () => { |
||||
this._backgroundPath = path |
||||
this._updateBackgroundImages() |
||||
}) |
||||
this._backgroundsList.appendChild(button) |
||||
} |
||||
} |
||||
|
||||
_getImages(path) { |
||||
this._backgroundImagesDir = greeter_config.branding.background_images_dir || '/usr/share/backgrounds' |
||||
return new Promise( (resolve) => { |
||||
theme_utils.dirlist(path ? path : this._backgroundImagesDir, true, result => { |
||||
resolve(result) |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
async _init() {
|
||||
await this._createBackgroundArray() |
||||
this._updateOnStartup() |
||||
|
||||
return new Promise( resolve => resolve() ) |
||||
} |
||||
} |
@ -0,0 +1,83 @@
|
||||
class Power { |
||||
constructor() { |
||||
this._shutdown = document.querySelector("#shutdown-button") |
||||
this._restart = document.querySelector("#restart-button") |
||||
this._hibernate = document.querySelector("#hibernate-button") |
||||
this._suspend = document.querySelector("#suspend-button") |
||||
this._cover = document.querySelector("#cover") |
||||
this._covermsg = document.querySelector("#cover > #message") |
||||
this._init() |
||||
} |
||||
|
||||
_show_message(text) { |
||||
this._covermsg.innerHTML = text |
||||
this._cover.classList.remove("hide") |
||||
} |
||||
|
||||
async _do_shutdown() { |
||||
this._show_message("Shutting down") |
||||
await wait(1000) |
||||
lightdm.shutdown() |
||||
} |
||||
async _do_restart() { |
||||
this._show_message("Restarting") |
||||
await wait(1000) |
||||
lightdm.restart() |
||||
} |
||||
async _do_hibernate() { |
||||
this._show_message("Hibernating") |
||||
await wait(1000) |
||||
lightdm.hibernate() |
||||
} |
||||
async _do_suspend() { |
||||
this._show_message("Suspending") |
||||
await wait(1000) |
||||
lightdm.suspend() |
||||
} |
||||
|
||||
_setShutdown() { |
||||
if (!lightdm.can_shutdown) return |
||||
this._shutdown.addEventListener("click", () => { |
||||
this._do_shutdown() |
||||
}) |
||||
this._shutdown.classList.remove("hide") |
||||
} |
||||
_setRestart() { |
||||
if (!lightdm.can_restart) return |
||||
this._restart.addEventListener("click", () => { |
||||
this._do_restart() |
||||
}) |
||||
this._restart.classList.remove("hide") |
||||
} |
||||
_setHibernate() { |
||||
if (!lightdm.can_hibernate) return |
||||
this._hibernate.addEventListener("click", () => { |
||||
this._do_hibernate() |
||||
}) |
||||
this._hibernate.classList.remove("hide") |
||||
} |
||||
_setSuspend() { |
||||
if (!lightdm.can_suspend) return |
||||
this._suspend.addEventListener("click", () => { |
||||
this._do_suspend() |
||||
}) |
||||
this._suspend.classList.remove("hide") |
||||
} |
||||
_setCover() { |
||||
this._cover.addEventListener("click", () => { |
||||
this._cover.classList.add("hide") |
||||
}) |
||||
} |
||||
|
||||
_setButtons() { |
||||
this._setShutdown() |
||||
this._setRestart() |
||||
this._setHibernate() |
||||
this._setSuspend() |
||||
this._setCover() |
||||
} |
||||
|
||||
_init() { |
||||
this._setButtons() |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
class TimeDate { |
||||
constructor() { |
||||
this._timeDateButton = document.querySelector("#time-date") |
||||
this._timeLabel = document.querySelector("#time-date #time-label") |
||||
this._dateLabel = document.querySelector("#time-date #date-label") |
||||
this._passForm = document.querySelector("#pass-form") |
||||
this._init() |
||||
} |
||||
|
||||
_updateTimeDate() { |
||||
let date = theme_utils.get_current_localized_date() |
||||
let time = theme_utils.get_current_localized_time() |
||||
|
||||
this._dateLabel.innerText = date |
||||
this._timeLabel.innerText = time |
||||
} |
||||
|
||||
_setTimer() { |
||||
this._updateTimeDate() |
||||
setInterval(() => { |
||||
this._updateTimeDate() |
||||
}, 1000) |
||||
} |
||||
|
||||
_setButtons() { |
||||
this._timeDateButton.addEventListener("click", (ev) => { |
||||
this.toggleTimeDate() |
||||
}) |
||||
this._passForm.addEventListener("keydown", (ev) => { |
||||
if (ev.keyCode == 27) { |
||||
this.toggleTimeDate() |
||||
} |
||||
}) |
||||
} |
||||
|
||||
async toggleTimeDate() { |
||||
this._timeDateButton.blur() |
||||
this._passForm.blur() |
||||
if (this._timeDateButton.classList.contains("hide")) { |
||||
this._passForm.classList.add("hide") |
||||
await wait(300) |
||||
this._timeDateButton.classList.remove("hide") |
||||
await wait(100) |
||||
this._timeDateButton.focus() |
||||
} else { |
||||
this._timeDateButton.classList.add("hide") |
||||
await wait(300) |
||||
this._passForm.classList.remove("hide") |
||||
} |
||||
} |
||||
|
||||
_init() { |
||||
this._setTimer() |
||||
this._setButtons() |
||||
} |
||||
} |
Loading…
Reference in new issue