improved chatterino native

This commit is contained in:
fourtf
2018-05-28 18:25:19 +02:00
parent cded61d28d
commit 0f8375a2f3
11 changed files with 378 additions and 142 deletions
+22 -11
View File
@@ -50,6 +50,10 @@ void NativeMessagingManager::registerHost()
{
auto app = getApp();
if (app->paths->isPortable()) {
return;
}
// create manifest
QJsonDocument document;
QJsonObject root_obj;
@@ -144,26 +148,33 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
QString _type = root.value("type").toString();
bool attach = root.value("attach").toBool();
QString name = root.value("name").toString();
QString winId = root.value("winId").toString();
int yOffset = root.value("yOffset").toInt(-1);
if (_type.isNull() || name.isNull() || winId.isNull()) {
widgets::AttachedWindow::GetArgs args;
args.winId = root.value("winId").toString();
args.yOffset = root.value("yOffset").toInt(-1);
args.width = root.value("size").toObject().value("width").toInt(-1);
args.height = root.value("size").toObject().value("height").toInt(-1);
if (_type.isNull() || args.winId.isNull()) {
qDebug() << "NM type, name or winId missing";
attach = false;
return;
}
if (_type == "twitch") {
util::postToThread([name, attach, winId, yOffset, app] {
app->twitch.server->watchingChannel.update(
app->twitch.server->getOrAddChannel(name));
util::postToThread([=] {
if (!name.isEmpty()) {
app->twitch.server->watchingChannel.update(
app->twitch.server->getOrAddChannel(name));
}
if (attach) {
#ifdef USEWINSDK
auto *window =
widgets::AttachedWindow::get(::GetForegroundWindow(), winId, yOffset);
window->setChannel(app->twitch.server->getOrAddChannel(name));
window->show();
auto *window = widgets::AttachedWindow::get(::GetForegroundWindow(), args);
if (!name.isEmpty()) {
window->setChannel(app->twitch.server->getOrAddChannel(name));
}
// window->show();
#endif
}
});
@@ -185,7 +196,7 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
} else {
qDebug() << "NM unknown action " + action;
}
}
} // namespace singletons
} // namespace singletons
} // namespace chatterino
+10 -5
View File
@@ -19,21 +19,21 @@ PathManager::PathManager(int argc, char **argv)
.replace("/", "x");
// Options
bool portable = false;
this->portable = false;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "portable") == 0) {
portable = true;
this->portable = true;
}
}
if (QFileInfo::exists(QCoreApplication::applicationDirPath() + "/portable")) {
portable = true;
if (QFileInfo::exists(QCoreApplication::applicationDirPath() + "/this->portable")) {
this->portable = true;
}
// Root path = %APPDATA%/Chatterino or the folder that the executable resides in
QString rootPath;
if (portable) {
if (this->portable) {
rootPath.append(QCoreApplication::applicationDirPath());
} else {
// Get settings path
@@ -91,5 +91,10 @@ bool PathManager::createFolder(const QString &folderPath)
return QDir().mkpath(folderPath);
}
bool PathManager::isPortable()
{
return this->portable;
}
} // namespace singletons
} // namespace chatterino
+4
View File
@@ -28,6 +28,10 @@ public:
QString appPathHash;
bool createFolder(const QString &folderPath);
bool isPortable();
private:
bool portable;
};
} // namespace singletons