aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp5
-rw-r--r--src/main.cpp61
2 files changed, 36 insertions, 30 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index d7834f4..aad80bb 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -13,8 +13,6 @@
#include "mainwindow.h"
#include <QDir>
-#include <QWebEngineDownloadItem>
-
Browser::Browser(int &argc, char *argv[]) :
SingleApplication(argc, argv)
{
@@ -26,6 +24,9 @@ Browser::Browser(int &argc, char *argv[]) :
Browser::~Browser()
{
+ if(m_config) {
+ m_config->writeIfNeeded();
+ }
if(m_bookmarksManager) {
m_bookmarksManager->save();
}
diff --git a/src/main.cpp b/src/main.cpp
index ffb7a4d..fb9eeba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,7 +22,7 @@
#endif
// read config into std::string, supports qrc
-inline std::string readConfig(QString path)
+inline std::string readConfig(const QString &path)
{
QFile conf(path);
std::string ret;
@@ -33,7 +33,7 @@ inline std::string readConfig(QString path)
return ret;
}
-bool writeUserConfig(const std::string &path, Configuration &config)
+void bootstrapUserConfig(const std::string &path, Configuration &config)
{
// set firstRun to false so we don't re-init on every run
config.setValue<bool>("browser.firstRun", false);
@@ -56,8 +56,6 @@ bool writeUserConfig(const std::string &path, Configuration &config)
// downloads.path
std::string downloadsPath = config.value<std::string>("downloads.path").value();
config.setValue<std::string>("downloads.path", patchHome(downloadsPath, home.toStdString()));
-
- return config.writeUserConfiguration(path);
}
int main(int argc, char *argv[])
@@ -116,6 +114,8 @@ int main(int argc, char *argv[])
#ifdef QT_DEBUG
qDebug("config=%s", qUtf8Printable(parser.value(configOption)));
qDebug("default-config=%s", qUtf8Printable(parser.value(defaultConfigOption)));
+ qDebug("socket=%s", qUtf8Printable(parser.value(socketOption)));
+ qDebug("profile=%s", qUtf8Printable(parser.value(profileOption)));
#endif
if(parser.isSet(printDefaultConfigOption)) {
@@ -124,50 +124,55 @@ int main(int argc, char *argv[])
return 0;
}
- // TODO: check for other instances
- // if we socket hasn't been disabled (socket is not none)
- if(parser.value(socketOption) != "none") {
- bool bindOk = instance.bindLocalSocket(parser.value(socketOption));
- if(bindOk) {
- qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName()));
- } else {
- // pass arguments to new instance
- return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
- }
- }
-
std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
- config->readDefaultConfiguration(readConfig(parser.value(defaultConfigOption)));
config->readUserConfiguration(parser.value(configOption).toStdString());
+ config->parseDefaultConfiguration(readConfig(parser.value(defaultConfigOption)));
// check if first run
- if(config->value<bool>("browser.firstRun").value() || parser.isSet(generateUserConfigOption)) {
+ if(config->value<bool>("browser.firstRun").value_or(true) || parser.isSet(generateUserConfigOption)) {
// create a user config file
+
QString path = parser.value(configOption);
- // there may be no smolbote.cfg
+ // make sure we have a path
if(path.isEmpty()) {
path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/smolbote.cfg";
}
-
+ // make sure the directory exists
QDir configDir = QFileInfo(path).absoluteDir();
if(!configDir.exists()) {
- bool mkpathSuccess = configDir.mkpath(".");
-#ifdef QT_DEBUG
- qDebug("mkpath %s: %s", qUtf8Printable(configDir.absolutePath()), mkpathSuccess ? "ok" : "failed");
-#endif
+ configDir.mkpath(".");
}
-#ifdef QT_DEBUG
- qDebug("Generating user config on first run to %s", qUtf8Printable(path));
-#endif
+ // remove any existing config
+ if(QFile::exists(path)) {
+ QFile::remove(path);
+ }
+
+ config->parse(readConfig(parser.value(defaultConfigOption)));
- qDebug("Saving config to: %s - %s", qUtf8Printable(path), writeUserConfig(path.toStdString(), *config) ? "ok" : "failed");
+ // patch paths
+ bootstrapUserConfig(path.toStdString(), *config);
+ std::cout << "Generating config to: " << qUtf8Printable(path) << (config->writeUserConfiguration(path.toStdString()) ? " ok" : " failed") << std::endl;
+
+ // exit if this is the only thing we needed to do
if(parser.isSet(generateUserConfigOption)) {
return 0;
}
}
+ // check for other instances
+ // if we socket hasn't been disabled (socket is not none)
+ if(parser.value(socketOption) != "none") {
+ bool bindOk = instance.bindLocalSocket(parser.value(socketOption));
+ if(bindOk) {
+ qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName()));
+ } else {
+ // pass arguments to new instance
+ return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
+ }
+ }
+
instance.setConfiguration(config);
instance.createSession(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());