mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup boot.js and fix rllayout cookie
This commit is contained in:
parent
827421e116
commit
f3717815e1
3 changed files with 37 additions and 41 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
const
|
const
|
||||||
|
win = window,
|
||||||
CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc',
|
CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc',
|
||||||
|
sName = 'localStorage',
|
||||||
getStorage = () => {
|
getStorage = () => {
|
||||||
try {
|
try {
|
||||||
const value = localStorage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME);
|
const value = localStorage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME);
|
||||||
|
|
@ -9,6 +11,28 @@ getStorage = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Storage
|
||||||
|
try {
|
||||||
|
win[sName].setItem(sName, '');
|
||||||
|
win[sName].getItem(sName);
|
||||||
|
win[sName].removeItem(sName);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
// initialise if there's already data
|
||||||
|
let data = document.cookie.match(/(^|;) ?localStorage=([^;]+)/);
|
||||||
|
data = data ? decodeURIComponent(data[2]) : null;
|
||||||
|
data = data ? JSON.parse(data) : {};
|
||||||
|
win[sName] = {
|
||||||
|
getItem: key => data[key] == null ? null : data[key],
|
||||||
|
setItem: (key, value) => {
|
||||||
|
data[key] = ''+value; // forces the value to a string
|
||||||
|
document.cookie = sName+'='+encodeURIComponent(JSON.stringify(data))
|
||||||
|
+"; expires="+((new Date(Date.now()+(365*24*60*60*1000))).toGMTString())
|
||||||
|
+"; path=/; samesite=strict";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @param {*} data
|
* @param {*} data
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
|
||||||
toggleLayout()
|
toggleLayout()
|
||||||
{
|
{
|
||||||
const mobile = !ThemeStore.isMobile();
|
const mobile = !ThemeStore.isMobile();
|
||||||
doc.cookie = 'rllayout=' + (mobile ? 'mobile' : 'desktop');
|
doc.cookie = 'rllayout=' + (mobile ? 'mobile' : 'desktop') + '; samesite=strict';
|
||||||
ThemeStore.isMobile(mobile);
|
ThemeStore.isMobile(mobile);
|
||||||
leftPanelDisabled(mobile);
|
leftPanelDisabled(mobile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
dev/boot.js
34
dev/boot.js
|
|
@ -9,11 +9,6 @@ const
|
||||||
css = eId('css'),
|
css = eId('css'),
|
||||||
admin = app && '1' == app.dataset.admin,
|
admin = app && '1' == app.dataset.admin,
|
||||||
|
|
||||||
getCookie = name => {
|
|
||||||
let data = doc.cookie.match('(^|;) ?'+name+'=([^;]*)(;|$)');
|
|
||||||
return data ? decodeURIComponent(data[2]) : null;
|
|
||||||
},
|
|
||||||
|
|
||||||
showError = msg => {
|
showError = msg => {
|
||||||
let div = eId('loading-error');
|
let div = eId('loading-error');
|
||||||
div.append(' ' + msg);
|
div.append(' ' + msg);
|
||||||
|
|
@ -33,16 +28,14 @@ const
|
||||||
// script.async = true;
|
// script.async = true;
|
||||||
doc.head.append(script);
|
doc.head.append(script);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
layout = getCookie('rllayout'),
|
|
||||||
sName = 'localStorage';
|
|
||||||
|
|
||||||
if (!navigator || !navigator.cookieEnabled) {
|
if (!navigator || !navigator.cookieEnabled) {
|
||||||
doc.location.href = './?/NoCookie';
|
doc.location.href = './?/NoCookie';
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.documentElement.classList.toggle('rl-mobile', 'mobile' === layout || (!layout && 1000 > innerWidth));
|
let layout = doc.cookie.match(/(^|;) ?rllayout=([^;]+)/) || '';
|
||||||
|
doc.documentElement.classList.toggle('rl-mobile', 'mobile' === layout[2] || (!layout && 1000 > innerWidth));
|
||||||
|
|
||||||
let RL_APP_DATA = {};
|
let RL_APP_DATA = {};
|
||||||
|
|
||||||
|
|
@ -76,27 +69,6 @@ win.rl = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Storage
|
|
||||||
try {
|
|
||||||
win[sName].setItem(sName, '');
|
|
||||||
win[sName].getItem(sName);
|
|
||||||
win[sName].removeItem(sName);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
// initialise if there's already data
|
|
||||||
let data = getCookie(sName);
|
|
||||||
data = data ? JSON.parse(data) : {};
|
|
||||||
win[sName] = {
|
|
||||||
getItem: key => data[key] == null ? null : data[key],
|
|
||||||
setItem: (key, value) => {
|
|
||||||
data[key] = ''+value; // forces the value to a string
|
|
||||||
doc.cookie = sName+'='+encodeURIComponent(JSON.stringify(data))
|
|
||||||
+"; expires="+((new Date(Date.now()+(365*24*60*60*1000))).toGMTString())
|
|
||||||
+"; path=/; samesite=strict";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
css.href = css.dataset.href;
|
css.href = css.dataset.href;
|
||||||
|
|
||||||
loadScript(`./?/${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().slice(2)}/`)
|
loadScript(`./?/${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().slice(2)}/`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue