mirror of
https://github.com/khairul169/honey.git
synced 2026-10-05 02:13:55 +07:00
Rebrand Settings to More
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import App from "../../../App";
|
||||
import { addOnOffTile } from "./tiles";
|
||||
import * as EVENTS from "./events"
|
||||
|
||||
|
||||
export default class Settings {
|
||||
constructor() {
|
||||
this.app = new App()
|
||||
this.config = this.app.config
|
||||
}
|
||||
|
||||
init() {
|
||||
this.checkLocalStorage()
|
||||
this.initSettings()
|
||||
}
|
||||
|
||||
initSettings() {
|
||||
let darkMode = addOnOffTile(this.config,
|
||||
"dark_mode", "Dark mode",
|
||||
"Make the colors more appropriate for low-light environments",
|
||||
"dark_mode", EVENTS.onThemeChange
|
||||
)
|
||||
|
||||
addOnOffTile(this.config,
|
||||
"open_in_new", "Open in new tab",
|
||||
"Clicking on application will open it in a new browser tab",
|
||||
"open_new_tab", EVENTS.onNewTabChange
|
||||
)
|
||||
|
||||
addOnOffTile(this.config,
|
||||
"blur_on", "Enable blur",
|
||||
"Improves UI sweetness but may have a huge impact on performance",
|
||||
"blur", EVENTS.onBlurChange
|
||||
)
|
||||
|
||||
addOnOffTile(this.config,
|
||||
"animation", "Animations",
|
||||
"Show nice and fancy page transitions for improved experience",
|
||||
"animations", EVENTS.onAnimationChange
|
||||
)
|
||||
|
||||
document.getElementById("theme-switcher").addEventListener("click", () => {
|
||||
darkMode.click()
|
||||
})
|
||||
}
|
||||
|
||||
checkLocalStorage() {
|
||||
let warn = document.getElementById("no-cookies").classList
|
||||
if (this.config.storageAvailable) warn.add("hidden")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
const CL = document.body.classList
|
||||
|
||||
export function onThemeChange(config) {
|
||||
let isDark = config.get("dark_mode")
|
||||
isDark ? CL.add("dark") : CL.remove("dark")
|
||||
}
|
||||
|
||||
export function onNewTabChange(config) {
|
||||
let openNewTab = config.get("open_new_tab")
|
||||
let appList = document.getElementById("app-list").children
|
||||
|
||||
for (let app of appList) {
|
||||
if (openNewTab) app.setAttribute("target", "_blank")
|
||||
else app.removeAttribute("target")
|
||||
}
|
||||
}
|
||||
|
||||
export function onBlurChange(config) {
|
||||
let blur = config.get("blur")
|
||||
blur ? CL.remove("noblur") : CL.add("noblur")
|
||||
}
|
||||
|
||||
export function onAnimationChange(config) {
|
||||
let animations = config.get("animations")
|
||||
animations ? CL.remove("noanim") : CL.add("noanim")
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export function addOnOffTile(conf, icon, name, desc, key, func) {
|
||||
let item = document.createElement("div")
|
||||
item.classList.add("setting")
|
||||
item.innerHTML = `
|
||||
<i>${icon}</i>
|
||||
<div class="text">
|
||||
<div class="name">${name}</div>
|
||||
<div class="desc">${desc}</div>
|
||||
</div>
|
||||
<div class="switch"></div>`
|
||||
|
||||
let handleState = () => {
|
||||
let c = item.classList
|
||||
if (conf.get(key)) c.add("checked")
|
||||
else c.remove("checked")
|
||||
}
|
||||
|
||||
let write = () => {
|
||||
let target_value = !conf.get(key)
|
||||
conf.set(key, target_value)
|
||||
}
|
||||
|
||||
let f = () => {func(conf)}
|
||||
|
||||
item.addEventListener("click", write)
|
||||
item.addEventListener("click", handleState)
|
||||
if (func) item.addEventListener("click", f)
|
||||
|
||||
handleState()
|
||||
if (func && conf.changed(key)) f()
|
||||
document.getElementById("settings").appendChild(item)
|
||||
return item
|
||||
}
|
||||
Reference in New Issue
Block a user