mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
LootState object is no longer global.
g_app_state has been replaced by a member variable in LootApp. For #450.
This commit is contained in:
+89
-89
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -25,6 +25,7 @@
|
||||
#ifndef __LOOT_GUI_HANDLER__
|
||||
#define __LOOT_GUI_HANDLER__
|
||||
|
||||
#include "loot_state.h"
|
||||
#include "../backend/plugin.h"
|
||||
|
||||
#include <include/wrapper/cef_message_router.h>
|
||||
@@ -34,7 +35,7 @@
|
||||
namespace loot {
|
||||
class Handler : public CefMessageRouterBrowserSide::Handler {
|
||||
public:
|
||||
Handler();
|
||||
Handler(LootState& lootState);
|
||||
|
||||
// Called due to cefQuery execution in binding.html.
|
||||
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
|
||||
@@ -72,6 +73,8 @@ namespace loot {
|
||||
|
||||
void CopyToClipboard(const std::string& text);
|
||||
void SendProgressUpdate(CefRefPtr<CefFrame> frame, const std::string& message);
|
||||
|
||||
LootState& _lootState;
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(Handler);
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include "loot_app.h"
|
||||
#include "loot_state.h"
|
||||
#include "loot_handler.h"
|
||||
#include "scheme.h"
|
||||
|
||||
@@ -86,7 +85,7 @@ namespace loot {
|
||||
#endif
|
||||
|
||||
// Set the handler for browser-level callbacks.
|
||||
CefRefPtr<LootHandler> handler(new LootHandler());
|
||||
CefRefPtr<LootHandler> handler(new LootHandler(lootState));
|
||||
|
||||
// Register the custom "loot" scheme handlers.
|
||||
CefRegisterSchemeHandlerFactory("loot", "l10n", new LootSchemeHandlerFactory());
|
||||
@@ -97,7 +96,7 @@ namespace loot {
|
||||
// Need to set the global locale for this process so that messages will
|
||||
// be translated.
|
||||
BOOST_LOG_TRIVIAL(debug) << "Initialising language settings in UI thread.";
|
||||
const YAML::Node& settings = g_app_state.GetSettings();
|
||||
const YAML::Node& settings = lootState.GetSettings();
|
||||
if (settings["language"] && settings["language"].as<string>() != Language(Language::english).Locale()) {
|
||||
boost::locale::generator gen;
|
||||
gen.add_messages_path(g_path_l10n.string());
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef __LOOT_GUI_LOOT_APP__
|
||||
#define __LOOT_GUI_LOOT_APP__
|
||||
|
||||
#include "loot_state.h"
|
||||
|
||||
#include <include/cef_app.h>
|
||||
#include <include/wrapper/cef_message_router.h>
|
||||
#include <include/base/cef_lock.h>
|
||||
@@ -51,6 +53,8 @@ namespace loot {
|
||||
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
LootState lootState;
|
||||
private:
|
||||
CefRefPtr<CefMessageRouterRendererSide> message_router_;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "handler.h"
|
||||
#include "resource.h"
|
||||
#include "loot_app.h"
|
||||
#include "loot_state.h"
|
||||
|
||||
#include "../backend/error.h"
|
||||
#include "../backend/globals.h"
|
||||
@@ -56,7 +55,7 @@ namespace fs = boost::filesystem;
|
||||
namespace loc = boost::locale;
|
||||
|
||||
namespace loot {
|
||||
LootHandler::LootHandler() : is_closing_(false) {}
|
||||
LootHandler::LootHandler(LootState& lootState) : is_closing_(false), _lootState(lootState) {}
|
||||
|
||||
// CefClient methods
|
||||
//------------------
|
||||
@@ -98,7 +97,7 @@ namespace loot {
|
||||
#endif
|
||||
|
||||
// Set window size & position.
|
||||
YAML::Node settings = g_app_state.GetSettings();
|
||||
YAML::Node settings = _lootState.GetSettings();
|
||||
|
||||
if (settings["window"]["left"] && settings["window"]["top"] && settings["window"]["right"] && settings["window"]["bottom"]) {
|
||||
#ifdef _WIN32
|
||||
@@ -148,14 +147,14 @@ namespace loot {
|
||||
CefMessageRouterConfig config;
|
||||
browser_side_router_ = CefMessageRouterBrowserSide::Create(config);
|
||||
|
||||
browser_side_router_->AddHandler(new Handler(), false);
|
||||
browser_side_router_->AddHandler(new Handler(_lootState), false);
|
||||
}
|
||||
|
||||
bool LootHandler::DoClose(CefRefPtr<CefBrowser> browser) {
|
||||
assert(CefCurrentlyOn(TID_UI));
|
||||
|
||||
// Check if unapplied changes exist.
|
||||
if (g_app_state.numUnappliedChanges > 0) {
|
||||
if (_lootState.numUnappliedChanges > 0) {
|
||||
browser->GetMainFrame()->ExecuteJavaScript("onQuit();", browser->GetMainFrame()->GetURL(), 0);
|
||||
return true;
|
||||
}
|
||||
@@ -177,7 +176,7 @@ namespace loot {
|
||||
assert(CefCurrentlyOn(TID_UI));
|
||||
|
||||
// Save window size & position.
|
||||
YAML::Node settings = g_app_state.GetSettings();
|
||||
YAML::Node settings = _lootState.GetSettings();
|
||||
|
||||
#ifdef _WIN32
|
||||
RECT rc;
|
||||
@@ -189,8 +188,8 @@ namespace loot {
|
||||
settings["window"]["bottom"] = rc.bottom;
|
||||
#endif
|
||||
|
||||
g_app_state.UpdateSettings(settings);
|
||||
g_app_state.SaveSettings();
|
||||
_lootState.UpdateSettings(settings);
|
||||
_lootState.SaveSettings();
|
||||
|
||||
// Cancel any javascript callbacks.
|
||||
browser_side_router_->OnBeforeClose(browser);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef __LOOT_GUI_LOOT_HANDLER__
|
||||
#define __LOOT_GUI_LOOT_HANDLER__
|
||||
|
||||
#include "loot_state.h"
|
||||
|
||||
#include <include/cef_client.h>
|
||||
#include <include/wrapper/cef_message_router.h>
|
||||
|
||||
@@ -37,7 +39,7 @@ namespace loot {
|
||||
public CefLoadHandler,
|
||||
public CefRequestHandler {
|
||||
public:
|
||||
LootHandler();
|
||||
LootHandler(LootState& lootState);
|
||||
|
||||
// CefClient methods
|
||||
//------------------
|
||||
@@ -80,6 +82,8 @@ namespace loot {
|
||||
|
||||
bool IsClosing() const { return is_closing_; }
|
||||
|
||||
LootState& _lootState;
|
||||
|
||||
private:
|
||||
// List of existing browser windows. Only accessed on the CEF UI thread.
|
||||
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
|
||||
|
||||
@@ -46,8 +46,6 @@ using boost::format;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace loot {
|
||||
LootState g_app_state = LootState();
|
||||
|
||||
LootState::LootState() : numUnappliedChanges(0), _currentGame(_games.end()) {}
|
||||
|
||||
void LootState::Init(const std::string& cmdLineGame) {
|
||||
|
||||
@@ -69,8 +69,6 @@ namespace loot {
|
||||
base::Lock _lock;
|
||||
IMPLEMENT_REFCOUNTING(LootState);
|
||||
};
|
||||
|
||||
extern LootState g_app_state;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -115,7 +115,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd
|
||||
gameStr = command_line->GetSwitchValue("game");
|
||||
}
|
||||
|
||||
loot::g_app_state.Init(gameStr);
|
||||
app.get()->lootState.Init(gameStr);
|
||||
|
||||
// Back to CEF
|
||||
//------------
|
||||
|
||||
Reference in New Issue
Block a user