Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve WebUI settings #2243

Merged
merged 8 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/rtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ rTorrentStub.prototype.getuisettings = function()
{
this.mountPoint = theURLs.GetSettingsURL;
this.dataType = "json";
this.method = 'GET';
}

rTorrentStub.prototype.getplugins = function()
Expand Down
43 changes: 32 additions & 11 deletions js/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ var theWebUI =
sTimer: null,
updTimer: null,
configured: false,
jsonLoaded: false,
pluginsLoaded: false,
firstLoad: true,
interval: -1,
torrents: {},
Expand Down Expand Up @@ -219,6 +221,7 @@ var theWebUI =
else
{
this.catchErrors(false);
this.getUISettings();
this.getPlugins();
}
},
Expand Down Expand Up @@ -309,10 +312,15 @@ var theWebUI =

getPlugins: function()
{
this.requestWithoutTimeout("?action=getplugins", [this.getUISettings, this]);
this.requestWithoutTimeout("?action=getplugins", [this.loadPlugins, this]);
},

getUISettings: function()
{
this.requestWithoutTimeout("?action=getuisettings", [this.addSettings, this], true);
},

loadPlugins: function()
{
if(thePlugins.isInstalled("_getdir"))
{
Expand All @@ -326,21 +334,29 @@ var theWebUI =
correctContent();
this.updateServerTime();
window.setInterval( this.updateServerTime, 1000 );
this.requestWithoutTimeout("?action=getuisettings", [this.initFinish, this]);

// Mark plugins as done loading. Initialize UI if JSON file is loaded
this.pluginsLoaded = true;
this.initFinish();
},

initFinish: function(data)
initFinish: function()
{
this.config(data);
this.catchErrors(true);
this.assignEvents();
this.resize();
this.update();
// Loading JSON settings and plugins are done in an asynchronous fashion
// We must wait until both of these are completed before preceding
// Otherwise, the WebUI and plugins will not initialize properly
if (this.jsonLoaded && this.pluginsLoaded)
{
this.config();
this.catchErrors(true);
this.assignEvents();
this.resize();
this.update();
}
},

config: function(data)
config: function()
{
this.addSettings(data);
$.each(this.tables, function(ndx,table)
{
var width = theWebUI.settings["webui."+ndx+".colwidth"];
Expand Down Expand Up @@ -617,7 +633,8 @@ var theWebUI =
}
}
});
newSettings["webui.lang"] = GetActiveLanguage();
if ($type(newSettings["webui.lang"]))
stickz marked this conversation as resolved.
Show resolved Hide resolved
newSettings["webui.lang"] = GetActiveLanguage();
$.extend(this.settings,newSettings);
this.loadSettings();
},
Expand Down Expand Up @@ -650,6 +667,10 @@ var theWebUI =
});
if($type(this.settings["webui.search"]))
theSearchEngines.set(this.settings["webui.search"],true);

// Mark JSON file as done loaded. Initialize UI if plugins are loaded
this.jsonLoaded = true;
this.initFinish();
},

setSettings: function()
Expand Down
37 changes: 37 additions & 0 deletions php/WebUISettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once( 'cache.php' );

class WebUISettings
{
public $hash = "WebUISettings.dat";
private $jsonString = "{}";

public static function load()
{
$cache = new rCache();
$settings = new WebUISettings();
$cache->get($settings);
return $settings;
}

public function store()
{
$cache = new rCache();
$cache->set($this);
}

public function get()
{
return $this->jsonString;
}

public function set($json)
{
if ($this->jsonString !== $json)
{
$this->jsonString = $json;
$this->store();
}
}
}
21 changes: 4 additions & 17 deletions php/getsettings.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
<?php

require_once( 'util.php' );
require_once( 'WebUISettings.php' );

$s = '{}';
$fname = FileUtil::getSettingsPath()."/uisettings.json";
$fo = @fopen($fname, 'r');
if($fo!==false)
{
if(flock($fo, LOCK_SH))
{
$s = @file_get_contents($fname);
if($s==false)
$s = '{}';
flock($fo, LOCK_UN);
}
fclose($fo);
}

CachedEcho::send($s,"application/json",true);
$settings = WebUISettings::load();
$json = $settings->get();
CachedEcho::send($json,"application/json",true);
33 changes: 5 additions & 28 deletions php/setsettings.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
<?php

require_once( 'util.php' );
require_once( 'WebUISettings.php' );

if(isset($_REQUEST['v']))
$json = $_POST['v'];
if(isset($json))
{
$name = FileUtil::getSettingsPath()."/uisettings.json";
$fp = fopen( $name.'.tmp', "a" );
if($fp!==false)
{
if(flock( $fp, LOCK_EX ))
{
ftruncate( $fp, 0 );
$str = $_REQUEST['v'];
if( (fputs( $fp, $str ) == strlen($str)) && fflush( $fp ) )
{
flock( $fp, LOCK_UN );
if( fclose( $fp ) !== false )
@rename( $name.'.tmp', $name );
else
@unlink( $name.'.tmp' );
}
else
{
flock( $fp, LOCK_UN );
fclose( $fp );
@unlink( $name.'.tmp' );
}
}
else
fclose( $fp );
}
$settings = WebUISettings::load();
$settings->set($json);
}
4 changes: 2 additions & 2 deletions plugins/data/init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugin.loadLang();

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
plugin.config.call(this,data);
plugin.config.call(this);
var oldDblClick = this.getTable("fls").ondblclick;
this.getTable("fls").ondblclick = function(obj)
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/extsearch/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ theWebUI.resizeTop = function( w, h )
}

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
$("#List").after($("<div>").attr("id","TegList").css("display","none"));
this.tables["teg"] =
Expand All @@ -640,7 +640,7 @@ theWebUI.config = function(data)
ondblclick: function(obj) { theWebUI.tegItemDblClick(obj); return(false); },
ondelete: function() { theWebUI.tegItemRemove(); }
};
plugin.config.call(this,data);
plugin.config.call(this);
theSearchEngines.checkForIncorrectCurrent(true);
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/geoip/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var thePeersCache =
};

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
if(plugin.canChangeColumns())
{
Expand Down Expand Up @@ -90,7 +90,7 @@ theWebUI.config = function(data)
if(plugin.retrieveComments)
this.tables.prs.columns.push({text : 'Comment', width : '200px', id: 'comment', type : TYPE_STRING});
}
plugin.config.call(this,data);
plugin.config.call(this);
if((plugin.retrieveCountry || plugin.retrieveComments) && plugin.canChangeColumns())
plugin.done();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/history/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if(plugin.canChangeOptions())
if(plugin.canChangeTabs() || plugin.canChangeColumns())
{
plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
if(plugin.canChangeTabs())
{
Expand Down Expand Up @@ -202,7 +202,7 @@ if(plugin.canChangeTabs() || plugin.canChangeColumns())
}
}

plugin.config.call(theWebUI,data);
plugin.config.call(theWebUI);

if(plugin.canChangeColumns())
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/ratio/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugin.allDone = function()
}

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
if(plugin.canChangeColumns())
{
Expand All @@ -40,7 +40,7 @@ theWebUI.config = function(data)
return(plugin.trtFormat(table,arr));
};
}
plugin.config.call(this,data);
plugin.config.call(this);
plugin.reqId = theRequestManager.addRequest("trt", theRequestManager.map("cat=")+'$'+theRequestManager.map("d.views="),function(hash,torrent,value)
{
torrent.ratiogroup = value;
Expand Down
4 changes: 2 additions & 2 deletions plugins/rss/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ theWebUI.switchRSSLabel = function(el)
}

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
this.rssLabels = {};
this.rssItems = {};
Expand All @@ -151,7 +151,7 @@ theWebUI.config = function(data)
ondblclick: function(obj) { theWebUI.rssDblClick(obj); return(false); },
ondelete: function() { theWebUI.remove(); }
};
plugin.config.call(this,data);
plugin.config.call(this);
plugin.start();
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/rutracker_check/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if(plugin.canChangeMenu())
}

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
plugin.reqId1 = theRequestManager.addRequest("trt", theRequestManager.map("d.get_custom=")+"chk-state",function(hash,torrent,value)
{
Expand All @@ -42,7 +42,7 @@ theWebUI.config = function(data)
{
torrent.chktime = value;
});
plugin.config.call(this,data);
plugin.config.call(this);
}

plugin.isTorrentCommandEnabled = theWebUI.isTorrentCommandEnabled;
Expand Down
4 changes: 2 additions & 2 deletions plugins/scheduler/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ plugin.loadLang();
if(plugin.canChangeMenu() && (theWebUI.systemInfo.rTorrent.iVersion >= 0x805))
{
plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
plugin.config.call(this,data);
plugin.config.call(this);
plugin.reqId = theRequestManager.addRequest("trt", theRequestManager.map("d.get_custom=")+"sch_ignore",function(hash,torrent,value)
{
torrent.sch_ignore = iv(value);
Expand Down
4 changes: 2 additions & 2 deletions plugins/seedingtime/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugin.loadLang();
if(plugin.canChangeColumns())
{
plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
this.tables.trt.columns.push({text: 'SeedingTime', width: '100px', id: 'seedingtime', type: TYPE_NUMBER});
this.tables.trt.columns.push({text: 'AddTime', width: '110px', id: 'addtime', type: TYPE_NUMBER});
Expand All @@ -21,7 +21,7 @@ if(plugin.canChangeColumns())
}
return(plugin.trtFormat(table,arr));
}
plugin.config.call(this,data);
plugin.config.call(this);
plugin.reqId1 = theRequestManager.addRequest("trt", theRequestManager.map("d.get_custom=")+"seedingtime",function(hash,torrent,value)
{
torrent.seedingtime = value;
Expand Down
4 changes: 2 additions & 2 deletions plugins/show_peers_like_wtorrent/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
plugin.config.call(this,data);
plugin.config.call(this);
plugin.reqId1 = theRequestManager.addRequest("trt",
theRequestManager.map('cat=')+
'"$'+theRequestManager.map("t.multicall=")+
Expand Down
4 changes: 2 additions & 2 deletions plugins/theme/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ if(theWebUI.theme)
}

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
this.getTable("trt").setPaletteByURL("plugins/theme/themes/"+theWebUI.theme);
plugin.loadCSS("plugins");
plugin.config.call(this,data);
plugin.config.call(this);
thePlugins.waitLoad( "thePlugins.get('theme').allDone" );
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/throttle/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugin.loadLang();
plugin.loadMainCSS();

plugin.config = theWebUI.config;
theWebUI.config = function(data)
theWebUI.config = function()
{
if(plugin.canChangeColumns())
{
Expand All @@ -26,7 +26,7 @@ theWebUI.config = function(data)
{
torrent.throttle = value;
});
plugin.config.call(this,data);
plugin.config.call(this);
if(plugin.canChangeColumns())
plugin.trtRenameColumn();
}
Expand Down
Loading