Начало работы над ночным режимом

This commit is contained in:
Book Pauk
2023-01-08 18:05:02 +07:00
parent 7a71db9de4
commit 230c3bb5b2
2 changed files with 47 additions and 5 deletions

View File

@@ -5,6 +5,13 @@
Режим Режим
</div> </div>
<div class="sets-item row">
<div class="sets-label label"></div>
<div class="col row">
<q-checkbox v-model="form.nightMode" size="xs" label="Ночной режим" />
</div>
</div>
<div class="sets-item row"> <div class="sets-item row">
<div class="sets-label label"></div> <div class="sets-label label"></div>
<div class="col row"> <div class="col row">

View File

@@ -157,6 +157,10 @@ const settingDefaults = {
statusBarColorAlpha: 0.4, statusBarColorAlpha: 0.4,
statusBarClickOpen: true, statusBarClickOpen: true,
nightMode: false, //ночной режим
dayColorSets: {},
nightColorSets: {},
scrollingDelay: 3000,// замедление, ms scrollingDelay: 3000,// замедление, ms
scrollingType: 'ease-in-out', //linear, ease, ease-in, ease-out, ease-in-out scrollingType: 'ease-in-out', //linear, ease, ease-in, ease-out, ease-in-out
@@ -218,6 +222,8 @@ const diffExclude = [];
for (const hotKey of hotKeys) for (const hotKey of hotKeys)
diffExclude.push(`userHotKeys/${hotKey.name}`); diffExclude.push(`userHotKeys/${hotKey.name}`);
diffExclude.push('userWallpapers'); diffExclude.push('userWallpapers');
diffExclude.push('dayColorSets');
diffExclude.push('nightColorSets');
function addDefaultsToSettings(settings) { function addDefaultsToSettings(settings) {
const diff = utils.getObjDiff(settings, settingDefaults, {exclude: diffExclude}); const diff = utils.getObjDiff(settings, settingDefaults, {exclude: diffExclude});
@@ -228,6 +234,33 @@ function addDefaultsToSettings(settings) {
return false; return false;
} }
const colorSetsList = [
'textColor',
'backgroundColor',
'wallpaper',
'statusBarColorAsText',
'statusBarColor',
'statusBarColorAlpha',
'dualDivColorAsText',
'dualDivColor',
'dualDivColorAlpha',
];
function saveColorSets(nightMode, settings) {
const target = (nightMode ? settings.nightColorSets : settings.dayColorSets);
for (const prop of colorSetsList) {
target[prop] = settings[prop];
}
}
function restoreColorSets(nightMode, settings) {
const source = (nightMode ? settings.nightColorSets : settings.dayColorSets);
for (const prop of colorSetsList) {
if (utils.hasProp(source, prop))
settings[prop] = source[prop];
}
}
function getLibsDefaults(mode = 'reader') { function getLibsDefaults(mode = 'reader') {
const result = { const result = {
startLink: '', startLink: '',
@@ -333,12 +366,14 @@ const mutations = {
}, },
setSettings(state, value) { setSettings(state, value) {
const newSettings = Object.assign({}, state.settings, value); const newSettings = Object.assign({}, state.settings, value);
const added = addDefaultsToSettings(newSettings); //переключение режима день-ночь
if (added) { const prevNightMode = state.settings.nightMode;
state.settings = added; if (utils.hasProp(value, 'nightMode') && prevNightMode != value.nightMode) {
} else { saveColorSets(prevNightMode, newSettings);
state.settings = newSettings; restoreColorSets(newSettings.nightMode, newSettings);
} }
state.settings = newSettings;
}, },
setSettingsRev(state, value) { setSettingsRev(state, value) {
state.settingsRev = Object.assign({}, state.settingsRev, value); state.settingsRev = Object.assign({}, state.settingsRev, value);