store widescreen mode setting in preferences instead of a cookie

This commit is contained in:
Andrew Dolgov 2021-03-02 12:22:48 +03:00
parent 1a7f724bfa
commit 30b94fb194
3 changed files with 11 additions and 11 deletions

View File

@ -59,6 +59,7 @@ class Prefs {
const HEADLINES_NO_DISTINCT = "HEADLINES_NO_DISTINCT"; const HEADLINES_NO_DISTINCT = "HEADLINES_NO_DISTINCT";
const DEBUG_HEADLINE_IDS = "DEBUG_HEADLINE_IDS"; const DEBUG_HEADLINE_IDS = "DEBUG_HEADLINE_IDS";
const DISABLE_CONDITIONAL_COUNTERS = "DISABLE_CONDITIONAL_COUNTERS"; const DISABLE_CONDITIONAL_COUNTERS = "DISABLE_CONDITIONAL_COUNTERS";
const WIDESCREEN_MODE = "WIDESCREEN_MODE";
private const _DEFAULTS = [ private const _DEFAULTS = [
Prefs::PURGE_OLD_DAYS => [ 60, Config::T_INT ], Prefs::PURGE_OLD_DAYS => [ 60, Config::T_INT ],
@ -118,6 +119,7 @@ class Prefs {
Prefs::HEADLINES_NO_DISTINCT => [ false, Config::T_BOOL ], Prefs::HEADLINES_NO_DISTINCT => [ false, Config::T_BOOL ],
Prefs::DEBUG_HEADLINE_IDS => [ false, Config::T_BOOL ], Prefs::DEBUG_HEADLINE_IDS => [ false, Config::T_BOOL ],
Prefs::DISABLE_CONDITIONAL_COUNTERS => [ false, Config::T_BOOL ], Prefs::DISABLE_CONDITIONAL_COUNTERS => [ false, Config::T_BOOL ],
Prefs::WIDESCREEN_MODE => [ false, Config::T_BOOL ],
]; ];
const _PROFILE_BLACKLIST = [ const _PROFILE_BLACKLIST = [

View File

@ -235,14 +235,12 @@ class RPC extends Handler_Protected {
//print json_encode(array("message" => "UPDATE_COUNTERS")); //print json_encode(array("message" => "UPDATE_COUNTERS"));
} }
function setpanelmode() { function setWidescreen() {
$wide = (int) clean($_REQUEST["wide"]); $wide = (int) clean($_REQUEST["wide"]);
// FIXME should this use SESSION_COOKIE_LIFETIME and be renewed periodically? set_pref(Prefs::WIDESCREEN_MODE, $wide);
setcookie("ttrss_widescreen", (string)$wide,
time() + 86400*365);
print json_encode(array("wide" => $wide)); print json_encode(["wide" => $wide]);
} }
static function updaterandomfeed_real() { static function updaterandomfeed_real() {
@ -471,7 +469,7 @@ class RPC extends Handler_Protected {
$params["max_feed_id"] = (int) $max_feed_id; $params["max_feed_id"] = (int) $max_feed_id;
$params["num_feeds"] = (int) $num_feeds; $params["num_feeds"] = (int) $num_feeds;
$params["hotkeys"] = $this->get_hotkeys_map(); $params["hotkeys"] = $this->get_hotkeys_map();
$params["widescreen"] = (int) ($_COOKIE["ttrss_widescreen"] ?? 0); $params["widescreen"] = (int) get_pref(Prefs::WIDESCREEN_MODE);
$params['simple_update'] = Config::get(Config::SIMPLE_UPDATE_MODE); $params['simple_update'] = Config::get(Config::SIMPLE_UPDATE_MODE);
$params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif"); $params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif");
$params["labels"] = Labels::get_all($_SESSION["uid"]); $params["labels"] = Labels::get_all($_SESSION["uid"]);

View File

@ -779,7 +779,7 @@ const App = {
this.setLoadingProgress(50); this.setLoadingProgress(50);
this._widescreen_mode = this.getInitParam("widescreen"); this._widescreen_mode = this.getInitParam("widescreen");
this.switchPanelMode(this._widescreen_mode); this.setWidescreen(this._widescreen_mode);
Headlines.initScrollHandler(); Headlines.initScrollHandler();
@ -867,7 +867,7 @@ const App = {
} }
} }
}, },
switchPanelMode: function(wide) { setWidescreen: function(wide) {
const article_id = Article.getActive(); const article_id = Article.getActive();
if (wide) { if (wide) {
@ -908,7 +908,7 @@ const App = {
if (article_id) Article.view(article_id); if (article_id) Article.view(article_id);
xhr.post("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); xhr.post("backend.php", {op: "rpc", method: "setWidescreen", wide: wide ? 1 : 0});
}, },
initHotkeyActions: function() { initHotkeyActions: function() {
if (this.is_prefs) { if (this.is_prefs) {
@ -1168,7 +1168,7 @@ const App = {
Cookie.set("ttrss_ci_width", 0); Cookie.set("ttrss_ci_width", 0);
Cookie.set("ttrss_ci_height", 0); Cookie.set("ttrss_ci_height", 0);
this.switchPanelMode(this._widescreen_mode); this.setWidescreen(this._widescreen_mode);
} else { } else {
alert(__("Widescreen is not available in combined mode.")); alert(__("Widescreen is not available in combined mode."));
} }
@ -1258,7 +1258,7 @@ const App = {
Cookie.set("ttrss_ci_width", 0); Cookie.set("ttrss_ci_width", 0);
Cookie.set("ttrss_ci_height", 0); Cookie.set("ttrss_ci_height", 0);
this.switchPanelMode(this._widescreen_mode); this.setWidescreen(this._widescreen_mode);
} else { } else {
alert(__("Widescreen is not available in combined mode.")); alert(__("Widescreen is not available in combined mode."));
} }