From 2ff579b0014194c49207b1089b2b88f4ff167f68 Mon Sep 17 00:00:00 2001 From: maxkadushkin Date: Thu, 3 Aug 2023 17:05:18 +0300 Subject: [PATCH 01/89] [win-nix] handle portal login event --- .../src/cascapplicationmanagerwrapper.cpp | 4 ++++ win-linux/src/windows/cmainwindow.cpp | 18 ++++++++++++++++++ win-linux/src/windows/cmainwindow.h | 1 + 3 files changed, 23 insertions(+) diff --git a/win-linux/src/cascapplicationmanagerwrapper.cpp b/win-linux/src/cascapplicationmanagerwrapper.cpp index e09f2b8eb..569f33602 100644 --- a/win-linux/src/cascapplicationmanagerwrapper.cpp +++ b/win-linux/src/cascapplicationmanagerwrapper.cpp @@ -248,6 +248,10 @@ bool CAscApplicationManagerWrapper::processCommonEvent(NSEditorApi::CAscCefMenuE } else if ( cmd.compare(L"portal:login") == 0 ) { AscAppManager::sendCommandTo(SEND_TO_ALL_START_PAGE, L"portal:login", pData->get_Param()); + if ( m_pMainWindow ) { + m_pMainWindow->onPortalLogin(event->get_SenderId(), pData->get_Param()); + } + return true; } else if ( cmd.compare(L"portal:logout") == 0 ) { diff --git a/win-linux/src/windows/cmainwindow.cpp b/win-linux/src/windows/cmainwindow.cpp index f8a0ea3e7..6e159479b 100644 --- a/win-linux/src/windows/cmainwindow.cpp +++ b/win-linux/src/windows/cmainwindow.cpp @@ -691,6 +691,24 @@ void CMainWindow::onPortalLogout(std::wstring wjson) } } +void CMainWindow::onPortalLogin(int viewid, const std::wstring &json) +{ + if ( !(json.find(L"uiTheme") == std::wstring::npos) ) { + QJsonParseError jerror; + QJsonDocument jdoc = QJsonDocument::fromJson(QString::fromStdWString(json).toLatin1(), &jerror); + + if( jerror.error == QJsonParseError::NoError ) { + QJsonObject objRoot = jdoc.object(); + QString _ui_theme = objRoot["uiTheme"].toString(); + if ( !_ui_theme.isEmpty() ) { +// onFileLocation(vid, _url); + } + } + + m_pTabs->tabIndexByView(viewid); + } +} + void CMainWindow::doOpenLocalFile(COpenOptions& opts) { QFileInfo info(opts.url); diff --git a/win-linux/src/windows/cmainwindow.h b/win-linux/src/windows/cmainwindow.h index 1a8969351..0f826a69b 100644 --- a/win-linux/src/windows/cmainwindow.h +++ b/win-linux/src/windows/cmainwindow.h @@ -136,6 +136,7 @@ public slots: void onFileLocation(int, QString); void onPortalOpen(QString); void onPortalLogout(std::wstring portal); + void onPortalLogin(int viewid, const std::wstring& json); void onPortalNew(QString); void onPortalCreate(); void onOutsideAuth(QString); From 5367efb3a4f4281785f6975be2997dae6cc99e6b Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Thu, 31 Aug 2023 19:59:20 +0300 Subject: [PATCH 02/89] [win-linux] update manager: small refactoring --- .../update-daemon/src/classes/csvcmanager.cpp | 3 +++ .../update-daemon/src/platform_win/main.cpp | 2 +- .../src/platform_win/svccontrol.cpp | 1 + .../src/platform_win/svccontrol.h | 1 - .../update-daemon/src/platform_win/utils.cpp | 4 ++-- .../src/cascapplicationmanagerwrapper.cpp | 12 ---------- win-linux/src/chelp.cpp | 2 +- win-linux/src/cupdatemanager.cpp | 23 ++++--------------- win-linux/src/cupdatemanager.h | 4 ---- 9 files changed, 13 insertions(+), 39 deletions(-) diff --git a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp index 140a09f74..27ece90ff 100644 --- a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp +++ b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp @@ -40,6 +40,9 @@ #include "../../src/defines.h" #include "../../src/prop/defines_p.h" #ifdef _WIN32 +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include "platform_win/utils.h" # include # include diff --git a/win-linux/extras/update-daemon/src/platform_win/main.cpp b/win-linux/extras/update-daemon/src/platform_win/main.cpp index de86204fa..21852e682 100644 --- a/win-linux/extras/update-daemon/src/platform_win/main.cpp +++ b/win-linux/extras/update-daemon/src/platform_win/main.cpp @@ -95,7 +95,7 @@ int __cdecl _tmain (int argc, TCHAR *argv[]) CApplication app; CSvcManager upd; - socket.onMessageReceived([&app](void *buff, size_t bufsize) { + socket.onMessageReceived([&app](void *buff, size_t) { if (strcmp((const char*)buff, "stop") == 0) app.exit(0); }); diff --git a/win-linux/extras/update-daemon/src/platform_win/svccontrol.cpp b/win-linux/extras/update-daemon/src/platform_win/svccontrol.cpp index 21fe343a8..e6863fca9 100644 --- a/win-linux/extras/update-daemon/src/platform_win/svccontrol.cpp +++ b/win-linux/extras/update-daemon/src/platform_win/svccontrol.cpp @@ -33,6 +33,7 @@ #include "svccontrol.h" #include "platform_win/utils.h" #include +#include #define SVC_ERROR ((DWORD)0xC0020001L) diff --git a/win-linux/extras/update-daemon/src/platform_win/svccontrol.h b/win-linux/extras/update-daemon/src/platform_win/svccontrol.h index 70a5845ce..6efe381da 100644 --- a/win-linux/extras/update-daemon/src/platform_win/svccontrol.h +++ b/win-linux/extras/update-daemon/src/platform_win/svccontrol.h @@ -35,7 +35,6 @@ #include "version.h" #include -#include #include #define SERVICE_NAME TEXT(VER_PRODUCTNAME_STR) diff --git a/win-linux/extras/update-daemon/src/platform_win/utils.cpp b/win-linux/extras/update-daemon/src/platform_win/utils.cpp index 3f8fc9535..d7ecff139 100644 --- a/win-linux/extras/update-daemon/src/platform_win/utils.cpp +++ b/win-linux/extras/update-daemon/src/platform_win/utils.cpp @@ -78,11 +78,11 @@ namespace NS_Utils if (showError) str += L" " + GetLastErrorAsString(); wchar_t *title = const_cast(TEXT(VER_PRODUCTNAME_STR)); - size_t title_size = wcslen(title) * sizeof(wchar_t); + DWORD title_size = (DWORD)wcslen(title) * sizeof(wchar_t); DWORD res; DWORD session_id = WTSGetActiveConsoleSessionId(); WTSSendMessageW(WTS_CURRENT_SERVER_HANDLE, session_id, title, title_size, - const_cast(str.c_str()), str.size() * sizeof(wchar_t), + const_cast(str.c_str()), (DWORD)str.size() * sizeof(wchar_t), MB_OK | MB_ICONERROR | MB_SERVICE_NOTIFICATION_NT3X | MB_SETFOREGROUND, 8, &res, TRUE); return res; } diff --git a/win-linux/src/cascapplicationmanagerwrapper.cpp b/win-linux/src/cascapplicationmanagerwrapper.cpp index 3a01ec300..22c4efe7e 100644 --- a/win-linux/src/cascapplicationmanagerwrapper.cpp +++ b/win-linux/src/cascapplicationmanagerwrapper.cpp @@ -84,9 +84,6 @@ CAscApplicationManagerWrapper::CAscApplicationManagerWrapper(CAscApplicationMana #ifdef _UPDMODULE m_pUpdateManager = new CUpdateManager(this); - connect(m_pUpdateManager, &CUpdateManager::progresChanged, this, [=](const int &percent) { - AscAppManager::sendCommandTo(0, "updates:download", QString("{\"progress\":\"%1\"}").arg(QString::number(percent))); - }); #endif } @@ -375,9 +372,6 @@ bool CAscApplicationManagerWrapper::processCommonEvent(NSEditorApi::CAscCefMenuE } return true; - } else - if ( !(cmd.find(L"updates:action") == std::wstring::npos) ) { - // qDebug() << "updates action" << pData->get_Param(); } break; } @@ -1636,15 +1630,9 @@ bool CAscApplicationManagerWrapper::applySettings(const wstring& wstrjson) _reg_user.setValue("editorWindowMode", m_private->m_openEditorWindow); } #ifdef _UPDMODULE -#ifdef Q_OS_WIN if ( objRoot.contains("autoupdatemode") ) { m_pUpdateManager->setNewUpdateSetting(objRoot["autoupdatemode"].toString()); } -#else - if ( objRoot.contains("checkupdatesinterval") ) { - m_pUpdateManager->setNewUpdateSetting(objRoot["checkupdatesinterval"].toString()); - } -#endif #endif } else { /* parse settings error */ diff --git a/win-linux/src/chelp.cpp b/win-linux/src/chelp.cpp index 57872a1da..4d7382133 100644 --- a/win-linux/src/chelp.cpp +++ b/win-linux/src/chelp.cpp @@ -62,7 +62,7 @@ void CHelp::out() " --xdg-desktop-portal use portals instead of gtk file chooser (the flag is saved for subsequent sessions)\n" " --xdg-desktop-portal=default use portals instead of gtk file chooser for current session\n" " --native-file-dialog use non Qt dialog\n" - " --updates-appcast-url=\"\" set URL for updates\n" + " --updates-appcast-channel=dev set development URL for updates\n" " --updates-reset reset all update options\n"; #ifdef _WIN32 diff --git a/win-linux/src/cupdatemanager.cpp b/win-linux/src/cupdatemanager.cpp index b65c3f781..f08d8aa2d 100644 --- a/win-linux/src/cupdatemanager.cpp +++ b/win-linux/src/cupdatemanager.cpp @@ -54,6 +54,7 @@ # define DAEMON_NAME "/updatesvc" #endif +#define modeToEnum(mod) ((mod == "silent") ? UpdateMode::SILENT : (mod == "ask") ? UpdateMode::ASK : UpdateMode::DISABLE) #define WStrToTStr(str) QStrToTStr(QString::fromStdWString(str)) #define CHECK_ON_STARTUP_MS 9000 #define CMD_ARGUMENT_UPDATES_CHANNEL L"--updates-appcast-channel" @@ -384,7 +385,7 @@ void CUpdateManager::updateNeededCheking() void CUpdateManager::onProgressSlot(const int percent) { - emit progresChanged(percent); + AscAppManager::sendCommandTo(0, "updates:download", QString("{\"progress\":\"%1\"}").arg(QString::number(percent))); } void CUpdateManager::onError(const QString &error) @@ -536,19 +537,11 @@ void CUpdateManager::handleAppClose() sendMessage(MSG_StopDownload); } -void CUpdateManager::scheduleRestartForUpdate() -{ - m_restartForUpdate = true; -} - void CUpdateManager::setNewUpdateSetting(const QString& _rate) { GET_REGISTRY_USER(reg_user); reg_user.setValue("autoUpdateMode", _rate); - int mode = (_rate == "silent") ? - UpdateMode::SILENT : (_rate == "ask") ? - UpdateMode::ASK : UpdateMode::DISABLE; - if (mode == UpdateMode::DISABLE) + if (modeToEnum(_rate) == UpdateMode::DISABLE) { destroyStartupTimer(m_pCheckOnStartupTimer); // QTimer::singleShot(3000, this, &CUpdateManager::updateNeededCheking); } @@ -572,16 +565,11 @@ void CUpdateManager::skipVersion() int CUpdateManager::getUpdateMode() { GET_REGISTRY_USER(reg_user); - const QString mode = reg_user.value("autoUpdateMode", "ask").toString(); - return (mode == "silent") ? - UpdateMode::SILENT : (mode == "ask") ? - UpdateMode::ASK : UpdateMode::DISABLE; + return modeToEnum(reg_user.value("autoUpdateMode", "ask").toString()); } void CUpdateManager::onLoadCheckFinished(const QString &filePath) { -// if (m_lock) -// return; m_manualCheck = true; QFile jsonFile(filePath); if ( jsonFile.open(QIODevice::ReadOnly) ) { @@ -661,7 +649,6 @@ void CUpdateManager::onCheckFinished(bool error, bool updateExist, const QString } else { QString args = QString("{\"version\":\"%1\"}").arg(version); AscAppManager::sendCommandTo(0, "updates:checking", args); - AscAppManager::sendCommandToAllEditors(L"updates:checking", args.toStdWString()); m_dialogSchedule->addToSchedule("showUpdateMessage"); } break; @@ -711,7 +698,7 @@ void CUpdateManager::showStartInstallMessage(QWidget *parent) m_lock = false; switch (result) { case WinDlg::DLG_RESULT_INSTALL: { - scheduleRestartForUpdate(); + m_restartForUpdate = true; AscAppManager::closeAppWindows(); break; } diff --git a/win-linux/src/cupdatemanager.h b/win-linux/src/cupdatemanager.h index b042614f3..d7c331b88 100644 --- a/win-linux/src/cupdatemanager.h +++ b/win-linux/src/cupdatemanager.h @@ -74,7 +74,6 @@ public: void skipVersion(); int getUpdateMode(); QString getVersion() const; - void scheduleRestartForUpdate(); void handleAppClose(); void loadUpdates(); void installUpdates(); @@ -82,9 +81,6 @@ public: public slots: void checkUpdates(bool manualCheck = false); -signals: - void progresChanged(const int percent); - private: void init(); void clearTempFiles(const QString &except = QString()); From ce202ff83e4e6c1454f2838c4efc18efb30cf36a Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Thu, 31 Aug 2023 20:42:12 +0300 Subject: [PATCH 03/89] [win-linux] update manager: set a timer to check for updates once a day --- win-linux/src/cupdatemanager.cpp | 89 +++++++++++++++----------------- win-linux/src/cupdatemanager.h | 8 +-- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/win-linux/src/cupdatemanager.cpp b/win-linux/src/cupdatemanager.cpp index f08d8aa2d..78daea188 100644 --- a/win-linux/src/cupdatemanager.cpp +++ b/win-linux/src/cupdatemanager.cpp @@ -56,6 +56,7 @@ #define modeToEnum(mod) ((mod == "silent") ? UpdateMode::SILENT : (mod == "ask") ? UpdateMode::ASK : UpdateMode::DISABLE) #define WStrToTStr(str) QStrToTStr(QString::fromStdWString(str)) +#define DAY_TO_SEC 24*3600 #define CHECK_ON_STARTUP_MS 9000 #define CMD_ARGUMENT_UPDATES_CHANNEL L"--updates-appcast-channel" #ifndef URL_APPCAST_UPDATES @@ -130,16 +131,6 @@ auto currentArch()->QString #endif } -auto destroyStartupTimer(QTimer* &timer)->void -{ - if (timer) { - if (timer->isActive()) - timer->stop(); - timer->deleteLater(); - timer = nullptr; - } -} - auto getFileHash(const QString &fileName)->QString { QFile file(fileName); @@ -227,9 +218,13 @@ CUpdateManager::CUpdateManager(QObject *parent): if ( !m_checkUrl.empty()) { CLogger::log("Updates is on, URL: " + QString::fromStdWString(m_checkUrl)); -// m_pTimer = new QTimer(this); -// m_pTimer->setSingleShot(false); -// connect(m_pTimer, SIGNAL(timeout()), this, SLOT(checkUpdates())); + m_pIntervalTimer = new QTimer(this); + m_pIntervalTimer->setSingleShot(false); + connect(m_pIntervalTimer, SIGNAL(timeout()), this, SLOT(checkUpdates())); + m_pIntervalStartTimer = new QTimer(this); + m_pIntervalStartTimer->setSingleShot(true); + m_pIntervalStartTimer->setInterval(CHECK_ON_STARTUP_MS); + connect(m_pIntervalStartTimer, &QTimer::timeout, this, &CUpdateManager::updateNeededCheking); if (IsPackage(Portable)) runProcess(QStrToTStr(qApp->applicationDirPath()) + DAEMON_NAME, TEXT("--run-as-app")); init(); @@ -257,15 +252,9 @@ void CUpdateManager::init() m_savedPackageData->fileName = reg_user.value("file", QString()).toString(); m_savedPackageData->fileType = reg_user.value("type", QString()).toString(); m_savedPackageData->version = reg_user.value("version", QString()).toString(); -// m_lastCheck = time_t(reg_user.value("last_check", 0).toLongLong()); + m_lastCheck = time_t(reg_user.value("last_check", 0).toLongLong()); + m_interval = reg_user.value("interval", DAY_TO_SEC).toInt(); reg_user.endGroup(); - if (getUpdateMode() != UpdateMode::DISABLE) { - m_pCheckOnStartupTimer = new QTimer(this); - m_pCheckOnStartupTimer->setSingleShot(true); - m_pCheckOnStartupTimer->setInterval(CHECK_ON_STARTUP_MS); - connect(m_pCheckOnStartupTimer, &QTimer::timeout, this, &CUpdateManager::updateNeededCheking); - m_pCheckOnStartupTimer->start(); - } m_socket->onMessageReceived([this](void *data, size_t) { tstring str((const tchar*)data), tmp; @@ -334,12 +323,20 @@ void CUpdateManager::clearTempFiles(const QString &except) void CUpdateManager::checkUpdates(bool manualCheck) { + m_pIntervalStartTimer->stop(); + m_lastCheck = time(nullptr); + GET_REGISTRY_USER(reg_user); + reg_user.beginGroup("Updates"); + reg_user.setValue("last_check", static_cast(m_lastCheck)); + reg_user.endGroup(); + if (getUpdateMode() != UpdateMode::DISABLE) + m_pIntervalStartTimer->start(); + if (m_lock) return; m_lock = true; AscAppManager::sendCommandTo(0, "updates:link", "lock"); m_manualCheck = manualCheck; - destroyStartupTimer(m_pCheckOnStartupTimer); m_packageData->clear(); #ifdef CHECK_DIRECTORY @@ -350,37 +347,24 @@ void CUpdateManager::checkUpdates(bool manualCheck) } #endif -// m_lastCheck = time(nullptr); -// GET_REGISTRY_USER(reg_user); -// reg_user.beginGroup("Updates"); -// reg_user.setValue("last_check", static_cast(m_lastCheck)); -// reg_user.endGroup(); - if (!sendMessage(MSG_CheckUpdates, WStrToTStr(m_checkUrl))) { m_dialogSchedule->addToSchedule("criticalMsg", QObject::tr("An error occurred while check updates: Update Service not found!")); } -// QTimer::singleShot(3000, this, [=]() { -// updateNeededCheking(); -// }); } void CUpdateManager::updateNeededCheking() { - checkUpdates(); -// if (m_pTimer) { -// m_pTimer->stop(); -// int interval = 0; -// const time_t DAY_TO_SEC = 24*3600; -// const time_t curr_time = time(nullptr); -// const time_t elapsed_time = curr_time - m_lastCheck; -// if (elapsed_time > DAY_TO_SEC) { -// checkUpdates(); -// } else { -// interval = static_cast(DAY_TO_SEC - elapsed_time); -// m_pTimer->setInterval(interval*1000); -// m_pTimer->start(); -// } -// } + if (m_pIntervalTimer) { + m_pIntervalTimer->stop(); + int elapsed_time = int(time(nullptr) - m_lastCheck); + if (elapsed_time > m_interval) { + checkUpdates(); + } else { + int remaining_time = 1000 * (m_interval - elapsed_time); + m_pIntervalTimer->setInterval(remaining_time < CHECK_ON_STARTUP_MS + 1000 ? CHECK_ON_STARTUP_MS + 1000 : remaining_time); + m_pIntervalTimer->start(); + } + } } void CUpdateManager::onProgressSlot(const int percent) @@ -476,6 +460,12 @@ void CUpdateManager::installUpdates() } } +void CUpdateManager::launchIntervalStartTimer() +{ + if (getUpdateMode() != UpdateMode::DISABLE) + m_pIntervalStartTimer->start(); +} + QString CUpdateManager::getVersion() const { return m_packageData->version; @@ -542,8 +532,11 @@ void CUpdateManager::setNewUpdateSetting(const QString& _rate) GET_REGISTRY_USER(reg_user); reg_user.setValue("autoUpdateMode", _rate); if (modeToEnum(_rate) == UpdateMode::DISABLE) { - destroyStartupTimer(m_pCheckOnStartupTimer); -// QTimer::singleShot(3000, this, &CUpdateManager::updateNeededCheking); + m_pIntervalStartTimer->stop(); + m_pIntervalTimer->stop(); + } else { + m_pIntervalStartTimer->start(); + } } void CUpdateManager::cancelLoading() diff --git a/win-linux/src/cupdatemanager.h b/win-linux/src/cupdatemanager.h index d7c331b88..5941de98b 100644 --- a/win-linux/src/cupdatemanager.h +++ b/win-linux/src/cupdatemanager.h @@ -77,6 +77,7 @@ public: void handleAppClose(); void loadUpdates(); void installUpdates(); + void launchIntervalStartTimer(); public slots: void checkUpdates(bool manualCheck = false); @@ -103,10 +104,11 @@ private: m_manualCheck = false, m_lock = false; -// QTimer *m_pTimer = nullptr; -// time_t m_lastCheck; + time_t m_lastCheck = 0; + int m_interval = 0; - QTimer *m_pCheckOnStartupTimer = nullptr; + QTimer *m_pIntervalStartTimer = nullptr, + *m_pIntervalTimer = nullptr; wstring m_checkUrl; class DialogSchedule; From 4f38e4207bb9d322f615774cbc929869f1174abb Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Thu, 31 Aug 2023 20:44:05 +0300 Subject: [PATCH 04/89] [win-linux] update manager: ability to change the update interval --- win-linux/src/chelp.cpp | 1 + win-linux/src/cupdatemanager.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/win-linux/src/chelp.cpp b/win-linux/src/chelp.cpp index 4d7382133..b585f5340 100644 --- a/win-linux/src/chelp.cpp +++ b/win-linux/src/chelp.cpp @@ -63,6 +63,7 @@ void CHelp::out() " --xdg-desktop-portal=default use portals instead of gtk file chooser for current session\n" " --native-file-dialog use non Qt dialog\n" " --updates-appcast-channel=dev set development URL for updates\n" + " --updates-interval=