A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.
C++
feat(linux): AppImage auto-update via R2 JSON feed (#33)
haidang18103b6683a43524
diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txtindex ae9b926..1710d51 100644--- a/linux/CMakeLists.txt+++ b/linux/CMakeLists.txt@@ -49,6 +49,10 @@ target_link_libraries(gridex PRIVATEQt6::Widgets)+target_compile_definitions(gridex PRIVATE+ GRIDEX_VERSION="${PROJECT_VERSION}"+)+set_target_properties(gridex PROPERTIESWIN32_EXECUTABLE OFFMACOSX_BUNDLE OFFdiff --git a/linux/packaging/appimage/build-appimage.sh b/linux/packaging/appimage/build-appimage.shindex 3f7ae22..9f30b85 100755--- a/linux/packaging/appimage/build-appimage.sh+++ b/linux/packaging/appimage/build-appimage.sh@@ -1,5 +1,12 @@#!/usr/bin/env bash# Build AppImage for Gridex Linux.+#+# Skips `cmake --install` deliberately — the FetchContent'd mongo-c-driver /+# mongo-cxx-driver / nlohmann-json projects register install rules that dump+# ~100MB of headers + static libs into the AppDir and contribute nothing to+# the runtime. We copy the `gridex` binary directly; linuxdeploy then bundles+# Qt + the shared libs it actually links against.+## Requires: linuxdeploy + linuxdeploy-plugin-qt in PATH.set -euo pipefail@@ -16,23 +23,36 @@ command -v linuxdeploy-plugin-qt >/dev/null || { echo "linuxdeploy-plugin-qt notmkdir -p "${BUILD_DIR}" "${OUT_DIR}"rm -rf "${APPDIR}"+echo "==> Configuring"cmake -S "${LINUX_ROOT}" -B "${BUILD_DIR}" -G Ninja -DCMAKE_BUILD_TYPE=Release-cmake --build "${BUILD_DIR}" --parallel-DESTDIR="${APPDIR}" cmake --install "${BUILD_DIR}" --prefix /usr-install -Dm644 "${SCRIPT_DIR}/gridex.desktop" "${APPDIR}/usr/share/applications/gridex.desktop"-install -Dm755 "${SCRIPT_DIR}/AppRun" "${APPDIR}/AppRun"+echo "==> Building gridex"+cmake --build "${BUILD_DIR}" --parallel --target gridex-# Icon: use placeholder if bundled icon absent.+echo "==> Staging AppDir"+install -Dm755 "${BUILD_DIR}/gridex" "${APPDIR}/usr/bin/gridex"+install -Dm644 "${SCRIPT_DIR}/gridex.desktop" "${APPDIR}/usr/share/applications/gridex.desktop"+install -Dm755 "${SCRIPT_DIR}/AppRun" "${APPDIR}/AppRun"++# Icon — fall back to repo root logo if packaging/ doesn't ship a dedicated one.ICON_SRC="${SCRIPT_DIR}/gridex.png"-if [ ! -f "${ICON_SRC}" ]; then- ICON_SRC="${LINUX_ROOT}/../logo.png"-fi+[ -f "${ICON_SRC}" ] || ICON_SRC="${LINUX_ROOT}/../logo.png"install -Dm644 "${ICON_SRC}" "${APPDIR}/usr/share/icons/hicolor/512x512/apps/gridex.png"+echo "==> Bundling Qt + dependencies"+# linuxdeploy wants to copy resolved .so files next to the binary. Make sure+# Qt can be found via QMAKE so the qt plugin picks the right version.+export QMAKE="${QMAKE:-${CMAKE_PREFIX_PATH:+${CMAKE_PREFIX_PATH}/bin/qmake}}"+export QMAKE="${QMAKE:-/home/$USER/Qt/6.7.3/gcc_64/bin/qmake}"+cd "${OUT_DIR}"linuxdeploy --appdir "${APPDIR}" --plugin qt --output appimage \--desktop-file "${APPDIR}/usr/share/applications/gridex.desktop" \--icon-file "${APPDIR}/usr/share/icons/hicolor/512x512/apps/gridex.png"-echo "AppImage produced under: ${OUT_DIR}"+echo+echo "==> Done"+ls -lh "${OUT_DIR}"/Gridex*.AppImage 2>/dev/null || {+ echo "linuxdeploy finished but no AppImage produced in ${OUT_DIR}" >&2+ exit 1+}diff --git a/linux/packaging/appimage/gridex.png b/linux/packaging/appimage/gridex.pngnew file mode 100644index 0000000..efc6632Binary files /dev/null and b/linux/packaging/appimage/gridex.png differdiff --git a/linux/src/Presentation/Windows/Main/MainWindow.cpp b/linux/src/Presentation/Windows/Main/MainWindow.cppindex 2714622..71cb1b4 100644--- a/linux/src/Presentation/Windows/Main/MainWindow.cpp+++ b/linux/src/Presentation/Windows/Main/MainWindow.cpp@@ -15,8 +15,10 @@#include <QAbstractButton>#include <QMessageBox>#include <QPushButton>+#include <QProgressDialog>#include <QSettings>#include <QStackedWidget>+#include <QTimer>#include <QStandardPaths>#include <QStatusBar>#include <QString>@@ -47,6 +49,7 @@#include "Presentation/Views/TabBar/WorkspaceTabBar.h"#include "Services/MCP/MCPServer.h"#include "Services/MCP/Security/ApprovalGate.h"+#include "Services/Update/UpdateService.h"namespace gridex {@@ -127,6 +130,32 @@ void MainWindow::wireBackend() {mcpServer_->auditLogger().setMaxFileSize(static_cast<qint64>(s.value("mcp.audit.maxSizeMB", 100).toInt()) * 1024 * 1024);}++ // Auto-update: silent background check 3s after launch. Notifies via+ // message box only when a new version is available; failures are+ // swallowed so offline users aren't nagged.+ updateService_ = std::make_unique<UpdateService>();+ connect(updateService_.get(), &UpdateService::updateChecked, this,+ [this](const UpdateCheckResult& r) {+ if (r.errorMessage.isEmpty() && r.hasUpdate) {+ QMessageBox box(this);+ box.setIcon(QMessageBox::Information);+ box.setWindowTitle(tr("Update available"));+ box.setText(tr("Gridex %1 is available (you have %2).").arg(r.newVersion, r.currentVersion));+ if (!r.notes.isEmpty()) box.setInformativeText(r.notes);+ auto* install = box.addButton(tr("Install"), QMessageBox::AcceptRole);+ box.addButton(tr("Later"), QMessageBox::RejectRole);+ box.exec();+ if (box.clickedButton() == install) {+ updateService_->downloadAndApply(r.downloadUrl, r.sha256);+ }+ }+ });+ connect(updateService_.get(), &UpdateService::errorOccurred, this,+ [this](const QString& msg) {+ QMessageBox::warning(this, tr("Update failed"), msg);+ });+ QTimer::singleShot(3000, this, [this] { updateService_->checkForUpdate(); });}void MainWindow::setupMenuBar() {@@ -190,6 +219,9 @@ void MainWindow::setupMenuBar() {shortcuts->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash));connect(shortcuts, &QAction::triggered, this, &MainWindow::onShowShortcuts);helpMenu->addSeparator();+ auto* checkUpdatesAction = helpMenu->addAction(tr("Check for &Updates…"));+ connect(checkUpdatesAction, &QAction::triggered, this, &MainWindow::onCheckForUpdates);+ helpMenu->addSeparator();auto* about = helpMenu->addAction(tr("&About Gridex"));connect(about, &QAction::triggered, this, &MainWindow::onShowAbout);}@@ -473,11 +505,62 @@ void MainWindow::onOpenMCPServer() {mcpWindow_->activateWindow();}+void MainWindow::onCheckForUpdates() {+ if (!updateService_) return;+ auto* progress = new QProgressDialog(tr("Checking for updates…"), QString(), 0, 0, this);+ progress->setWindowTitle(tr("Gridex Update"));+ progress->setModal(true);+ progress->setMinimumWidth(360);+ progress->show();++ auto conn = std::make_shared<QMetaObject::Connection>();+ *conn = connect(updateService_.get(), &UpdateService::updateChecked, this,+ [this, progress, conn](const UpdateCheckResult& r) {+ QObject::disconnect(*conn);+ progress->close();+ progress->deleteLater();++ if (!r.errorMessage.isEmpty()) {+ QMessageBox::warning(this, tr("Update check failed"), r.errorMessage);+ return;+ }+ if (!r.hasUpdate) {+ QMessageBox::information(this, tr("You're up to date"),+ tr("Gridex %1 is the latest version.").arg(r.currentVersion));+ return;+ }+ QMessageBox box(this);+ box.setIcon(QMessageBox::Information);+ box.setWindowTitle(tr("Update available"));+ box.setText(tr("Gridex %1 is available (you have %2).").arg(r.newVersion, r.currentVersion));+ if (!r.notes.isEmpty()) box.setInformativeText(r.notes);+ auto* install = box.addButton(tr("Install"), QMessageBox::AcceptRole);+ box.addButton(tr("Later"), QMessageBox::RejectRole);+ box.exec();+ if (box.clickedButton() == install) {+ auto* dlProgress = new QProgressDialog(tr("Downloading…"), tr("Cancel"), 0, 0, this);+ dlProgress->setWindowTitle(tr("Gridex Update"));+ dlProgress->setMinimumWidth(360);+ dlProgress->setModal(true);+ connect(updateService_.get(), &UpdateService::statusChanged,+ dlProgress, &QProgressDialog::setLabelText);+ connect(updateService_.get(), &UpdateService::errorOccurred, this,+ [this, dlProgress](const QString& msg) {+ dlProgress->close();+ QMessageBox::warning(this, tr("Update failed"), msg);+ });+ dlProgress->show();+ updateService_->downloadAndApply(r.downloadUrl, r.sha256);+ }+ });+ updateService_->checkForUpdate();+}+void MainWindow::onShowAbout() {QMessageBox::about(this, tr("About Gridex"), tr("<h2>Gridex</h2>""<p><b>AI-Native Database IDE</b> (Linux build)</p>"- "<p>Version 0.1 — 2026</p>"+ "<p>Version %1 — 2026</p>").arg(UpdateService::currentVersion()) + tr("<p>Connects to PostgreSQL, MySQL, SQLite, Redis, MongoDB, MSSQL with ""SSH tunnel support. Ships an AI chat assistant that speaks your ""schema.</p>"diff --git a/linux/src/Presentation/Windows/Main/MainWindow.h b/linux/src/Presentation/Windows/Main/MainWindow.hindex 718cb85..79956bc 100644--- a/linux/src/Presentation/Windows/Main/MainWindow.h+++ b/linux/src/Presentation/Windows/Main/MainWindow.h@@ -17,6 +17,7 @@ class HomeBrandingPanel;class MCPConnectionProvider;class MCPWindow;class SecretStore;+class UpdateService;class WorkspaceState;class WorkspaceView;namespace mcp { class MCPServer; }@@ -44,6 +45,7 @@ private slots:void onImportConnections();void onExportConnections();void onOpenMCPServer();+ void onCheckForUpdates();private:void setupMenuBar();@@ -64,6 +66,9 @@ private:std::unique_ptr<mcp::MCPServer> mcpServer_;MCPWindow* mcpWindow_ = nullptr; // owned by Qt parent when shown+ // Auto-update (AppImage self-replace; no-op for other distros).+ std::unique_ptr<UpdateService> updateService_;+// Menu actions that toggle enabled state with connectionQAction* newQueryAction_ = nullptr;QAction* disconnectAction_ = nullptr;diff --git a/linux/src/Services/CMakeLists.txt b/linux/src/Services/CMakeLists.txtindex 142e25b..a7b1b9e 100644--- a/linux/src/Services/CMakeLists.txt+++ b/linux/src/Services/CMakeLists.txt@@ -42,6 +42,11 @@ add_library(gridex-services STATICMCP/Tools/Tier3/UpdateRowsTool.cppMCP/Tools/Tier3/DeleteRowsTool.cppMCP/Tools/Tier3/ExecuteWriteQueryTool.cpp+ Update/UpdateService.cpp+)++target_compile_definitions(gridex-services PUBLIC+ GRIDEX_VERSION="${PROJECT_VERSION}")target_include_directories(gridex-services PUBLICdiff --git a/linux/src/Services/Update/UpdateService.cpp b/linux/src/Services/Update/UpdateService.cppnew file mode 100644index 0000000..288955b--- /dev/null+++ b/linux/src/Services/Update/UpdateService.cpp@@ -0,0 +1,197 @@+#include "Services/Update/UpdateService.h"++#include <QByteArray>+#include <QCoreApplication>+#include <QCryptographicHash>+#include <QFile>+#include <QFileInfo>+#include <QNetworkAccessManager>+#include <QNetworkReply>+#include <QNetworkRequest>+#include <QProcess>+#include <QStandardPaths>+#include <QUrl>++#include <nlohmann/json.hpp>++#ifndef GRIDEX_VERSION+# define GRIDEX_VERSION "0.0.0-dev"+#endif++namespace gridex {++const char* const kUpdateFeedUrl = "https://cdn.gridex.app/linux/releases.stable.json";++namespace {++// Split "0.1.2-rc1" into ([0,1,2], "rc1").+std::pair<std::vector<int>, QString> parseVersion(const QString& v) {+ QString s = v.trimmed();+ if (s.startsWith('v') || s.startsWith('V')) s = s.mid(1);+ QString suffix;+ int dash = s.indexOf('-');+ if (dash >= 0) { suffix = s.mid(dash + 1); s = s.left(dash); }+ std::vector<int> parts;+ for (const auto& p : s.split('.')) parts.push_back(p.toInt());+ while (parts.size() < 3) parts.push_back(0);+ return {std::move(parts), std::move(suffix)};+}++} // namespace++bool isNewerVersion(const QString& remote, const QString& local) {+ auto [r, rs] = parseVersion(remote);+ auto [l, ls] = parseVersion(local);+ for (std::size_t i = 0; i < std::min(r.size(), l.size()); ++i) {+ if (r[i] != l[i]) return r[i] > l[i];+ }+ // Same numeric parts → a present suffix is treated as a pre-release,+ // so 0.1.0 > 0.1.0-rc1. Both-present: lexicographic.+ if (rs.isEmpty() && !ls.isEmpty()) return true;+ if (!rs.isEmpty() && ls.isEmpty()) return false;+ return rs > ls;+}++UpdateService::UpdateService(QObject* parent)+ : QObject(parent), nam_(new QNetworkAccessManager(this)) {}++QString UpdateService::currentVersion() { return QStringLiteral(GRIDEX_VERSION); }++bool UpdateService::isAppImage() {+ const QByteArray env = qgetenv("APPIMAGE");+ return !env.isEmpty() && QFileInfo::exists(QString::fromLocal8Bit(env));+}++void UpdateService::checkForUpdate() {+ QNetworkRequest req{QUrl(QString::fromUtf8(kUpdateFeedUrl))};+ req.setRawHeader("User-Agent", QByteArrayLiteral("Gridex-Updater/") + GRIDEX_VERSION);+ req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);++ auto* reply = nam_->get(req);+ connect(reply, &QNetworkReply::finished, this, [this, reply]() {+ reply->deleteLater();+ UpdateCheckResult r;+ r.currentVersion = currentVersion();++ if (reply->error() != QNetworkReply::NoError) {+ r.errorMessage = reply->errorString();+ emit updateChecked(r);+ return;+ }+ try {+ auto raw = reply->readAll().toStdString();+ auto j = nlohmann::json::parse(raw);+ QString remoteVer = QString::fromStdString(j.value("version", ""));+ if (remoteVer.isEmpty()) {+ r.errorMessage = tr("Update feed missing 'version' field");+ emit updateChecked(r);+ return;+ }+ if (isNewerVersion(remoteVer, r.currentVersion)) {+ r.hasUpdate = true;+ r.newVersion = remoteVer;+ r.downloadUrl = QString::fromStdString(j.value("url", ""));+ r.sha256 = QString::fromStdString(j.value("sha256", ""));+ r.notes = QString::fromStdString(j.value("notes", ""));+ }+ } catch (const std::exception& e) {+ r.errorMessage = QString::fromUtf8(e.what());+ }+ emit updateChecked(r);+ });+}++void UpdateService::downloadAndApply(const QString& url, const QString& expectedSha256) {+ if (url.isEmpty()) {+ emit errorOccurred(tr("Download URL is empty."));+ return;+ }++ emit statusChanged(tr("Downloading update…"));++ QNetworkRequest req{QUrl(url)};+ req.setRawHeader("User-Agent", QByteArrayLiteral("Gridex-Updater/") + GRIDEX_VERSION);+ req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);++ auto* reply = nam_->get(req);++ // Write as we receive, to a temp file alongside the target AppImage so+ // the final rename stays atomic (same filesystem).+ const QString appImagePath = QString::fromLocal8Bit(qgetenv("APPIMAGE"));+ const QString tempPath = (isAppImage() ? appImagePath : QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/Gridex.AppImage")+ + QStringLiteral(".download");++ auto* file = new QFile(tempPath, this);+ if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) {+ reply->abort();+ reply->deleteLater();+ file->deleteLater();+ emit errorOccurred(tr("Cannot open %1 for writing.").arg(tempPath));+ return;+ }++ connect(reply, &QNetworkReply::readyRead, this, [reply, file]() {+ file->write(reply->readAll());+ });+ connect(reply, &QNetworkReply::downloadProgress, this,+ [this](qint64 bytesReceived, qint64 bytesTotal) {+ if (bytesTotal > 0) {+ int pct = static_cast<int>((bytesReceived * 100) / bytesTotal);+ emit statusChanged(tr("Downloading update… %1%").arg(pct));+ }+ });+ connect(reply, &QNetworkReply::finished, this,+ [this, reply, file, tempPath, appImagePath, expectedSha256]() {+ reply->deleteLater();+ file->write(reply->readAll());+ file->close();+ file->deleteLater();++ if (reply->error() != QNetworkReply::NoError) {+ QFile::remove(tempPath);+ emit errorOccurred(reply->errorString());+ return;+ }++ // Verify SHA256 before touching anything.+ emit statusChanged(tr("Verifying download…"));+ QFile verify(tempPath);+ if (!verify.open(QIODevice::ReadOnly)) {+ QFile::remove(tempPath);+ emit errorOccurred(tr("Cannot reopen downloaded file for verification."));+ return;+ }+ QCryptographicHash hash(QCryptographicHash::Sha256);+ hash.addData(&verify);+ verify.close();+ const QString gotSha = QString::fromLatin1(hash.result().toHex());+ if (!expectedSha256.isEmpty() && gotSha.compare(expectedSha256, Qt::CaseInsensitive) != 0) {+ QFile::remove(tempPath);+ emit errorOccurred(tr("Checksum mismatch.\nExpected: %1\nGot: %2").arg(expectedSha256, gotSha));+ return;+ }++ if (!isAppImage()) {+ emit statusChanged(tr("Downloaded to %1. Install manually — this build was not launched from an AppImage.").arg(tempPath));+ return;+ }++ // Atomic swap: rename temp → AppImage path, chmod +x, relaunch.+ emit statusChanged(tr("Installing update…"));+ QFile::remove(appImagePath);+ if (!QFile::rename(tempPath, appImagePath)) {+ emit errorOccurred(tr("Could not replace %1.").arg(appImagePath));+ return;+ }+ QFile(appImagePath).setPermissions(+ QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |+ QFile::ReadGroup | QFile::ExeGroup |+ QFile::ReadOther | QFile::ExeOther);++ emit statusChanged(tr("Restarting…"));+ QProcess::startDetached(appImagePath, {});+ QCoreApplication::quit();+ });+}++} // namespace gridexdiff --git a/linux/src/Services/Update/UpdateService.h b/linux/src/Services/Update/UpdateService.hnew file mode 100644index 0000000..fdee737--- /dev/null+++ b/linux/src/Services/Update/UpdateService.h@@ -0,0 +1,84 @@+#pragma once++// UpdateService — lightweight AppImage auto-updater for Linux.+//+// Mirrors the Windows UpdateService API shape (Velopack-based). The Linux+// implementation is custom-built to avoid vendoring native libs:+// 1. Fetch a JSON feed at kUpdateFeedUrl via QNetworkAccessManager.+// 2. Compare `version` in the feed against `GRIDEX_VERSION` (set at build+// time from the CMake PROJECT_VERSION).+// 3. If newer, caller can invoke downloadAndApply() — that downloads the+// AppImage to a temp path, verifies SHA256, swaps it over the file+// pointed at by the $APPIMAGE env var (set by the AppRun wrapper),+// chmod +x, and restarts the process via QProcess::startDetached.+//+// If the app is not running from an AppImage (dev builds, packaged .deb),+// downloadAndApply() still downloads + verifies but reports an error+// instead of self-replacing — the user can install the downloaded file+// via their package manager.+//+// Feed JSON format (served from R2 bucket, matches Windows pattern):+// {+// "version": "0.2.0",+// "published": "2026-05-01T00:00:00Z",+// "url": "https://cdn.gridex.app/linux/Gridex-0.2.0-x86_64.AppImage",+// "sha256": "abc123...",+// "notes": "release notes markdown"+// }++#include <QObject>+#include <QString>++class QNetworkAccessManager;++namespace gridex {++// Feed URL — single source of truth. Trailing filename included (not a+// directory). The feed is plain JSON, no signature yet (TODO: minisign).+extern const char* const kUpdateFeedUrl;++struct UpdateCheckResult {+ bool hasUpdate = false;+ QString currentVersion; // always filled+ QString newVersion; // set iff hasUpdate+ QString downloadUrl; // set iff hasUpdate+ QString sha256; // set iff hasUpdate+ QString notes; // set iff hasUpdate+ QString errorMessage; // set on network / parse error+};++class UpdateService : public QObject {+ Q_OBJECT+public:+ explicit UpdateService(QObject* parent = nullptr);++ // Returns the current app version (build-time constant).+ static QString currentVersion();++ // True when $APPIMAGE env var points at an existing file — i.e. the app+ // was launched via the AppImage AppRun wrapper and self-update is+ // possible. Otherwise downloadAndApply() will only verify + notify.+ static bool isAppImage();++ // Fire-and-forget check. Emits updateChecked() on completion.+ void checkForUpdate();++ // Download the file at `url`, verify `expectedSha256`, swap over the+ // current AppImage and restart. Emits statusChanged() for progress,+ // errorOccurred() on failure.+ void downloadAndApply(const QString& url, const QString& expectedSha256);++signals:+ void updateChecked(const UpdateCheckResult& result);+ void statusChanged(const QString& message);+ void errorOccurred(const QString& message);++private:+ QNetworkAccessManager* nam_;+};++// Semver-ish comparator: returns true if `remote` > `local`. Accepts+// `X.Y.Z[-suffix]`; suffix breaks ties alphabetically.+bool isNewerVersion(const QString& remote, const QString& local);++} // namespace gridex