From d0a9b8675f73fc607cc2594950871f33d7668ddd Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Fri, 1 Nov 2024 18:50:16 +0300 Subject: [PATCH] [feature] Add check version Aurora Toolbox. --- README.md | 2 +- data/ui/dialogs/AboutDialog.ui | 2 +- .../pages/welcome/elements/WelcomeLoading.ui | 2 +- docs/install.md | 2 +- meson.build | 2 +- po/com.keygenqt.aurora-toolbox.pot | 2 +- po/ru.po | 4 +- scripts/deb.sh | 2 +- src/base/constants/AppConstants.js | 2 + src/base/utils/Helper.js | 40 ++++++++++++++++ src/feature/pages/welcome/WelcomePage.js | 47 ++++++++++++++----- 11 files changed, 85 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 596fc34..64a2fc2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Subscribe and like! -[![Version](https://img.shields.io/badge/deb_package-0.0.7-blue)](https://github.com/keygenqt/aurora-toolbox/releases) +[![Version](https://img.shields.io/badge/deb_package-0.0.8-blue)](https://github.com/keygenqt/aurora-toolbox/releases) ![Preview](https://raw.githubusercontent.com/keygenqt/aurora-toolbox/refs/heads/main/files/images/preview_telegram.png) diff --git a/data/ui/dialogs/AboutDialog.ui b/data/ui/dialogs/AboutDialog.ui index 587829c..b99d1e9 100644 --- a/data/ui/dialogs/AboutDialog.ui +++ b/data/ui/dialogs/AboutDialog.ui @@ -4,7 +4,7 @@ floating com.keygenqt.aurora-toolbox Aurora Toolbox - 0.0.7 + 0.0.8 © 2024 KeyGenQt https://github.com/keygenqt/aurora-toolbox/issues Vitaliy Zarubin diff --git a/data/ui/pages/welcome/elements/WelcomeLoading.ui b/data/ui/pages/welcome/elements/WelcomeLoading.ui index 1bd4491..e9c3574 100644 --- a/data/ui/pages/welcome/elements/WelcomeLoading.ui +++ b/data/ui/pages/welcome/elements/WelcomeLoading.ui @@ -7,7 +7,7 @@ 24 - Search Aurora CLI... + Connection... true center diff --git a/docs/install.md b/docs/install.md index cd4bc3b..2159692 100644 --- a/docs/install.md +++ b/docs/install.md @@ -13,7 +13,7 @@ hide: #### Install ```shell -sudo dpkg -i aurora-toolbox_0.0.7-1_amd64.deb +sudo dpkg -i aurora-toolbox_0.0.8-1_amd64.deb ``` #### Update/Install dependency diff --git a/meson.build b/meson.build index 4040850..72a0957 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ # Define our project project( 'aurora-toolbox', - version: '0.0.7', + version: '0.0.8', license: ['Apache 2.0'], meson_version: '>= 0.59.0', default_options: ['cpp_std=c++17', 'cpp_rtti=false', 'cpp_eh=none', diff --git a/po/com.keygenqt.aurora-toolbox.pot b/po/com.keygenqt.aurora-toolbox.pot index 85663ac..1c7ac17 100644 --- a/po/com.keygenqt.aurora-toolbox.pot +++ b/po/com.keygenqt.aurora-toolbox.pot @@ -212,7 +212,7 @@ msgid "Welcome to application Aurora Toolbox!" msgstr "" #: data/ui/pages/welcome/elements/WelcomeLoading.ui:10 -msgid "Search Aurora CLI..." +msgid "Connection..." msgstr "" #: data/ui/pages/welcome/elements/WelcomeUpdate.ui:9 diff --git a/po/ru.po b/po/ru.po index 52fa847..4447d93 100644 --- a/po/ru.po +++ b/po/ru.po @@ -211,8 +211,8 @@ msgid "Welcome to application Aurora Toolbox!" msgstr "Добро пожаловать в приложение Aurora Toolbox!" #: data/ui/pages/welcome/elements/WelcomeLoading.ui:10 -msgid "Search Aurora CLI..." -msgstr "Поиск Aurora CLI..." +msgid "Connection..." +msgstr "Подключение..." #: data/ui/pages/welcome/elements/WelcomeUpdate.ui:9 msgid "Update available!" diff --git a/scripts/deb.sh b/scripts/deb.sh index 2f9a5ae..664f46b 100755 --- a/scripts/deb.sh +++ b/scripts/deb.sh @@ -81,4 +81,4 @@ dpkg -x $FOLDER/$DEB_FOLDER.deb $FOLDER/$DEB_FOLDER # Install / Remove sudo dpkg -r com.keygenqt.aurora-toolbox -sudo dpkg -i release/aurora-toolbox_0.0.7-1_amd64.deb +sudo dpkg -i release/aurora-toolbox_0.0.8-1_amd64.deb diff --git a/src/base/constants/AppConstants.js b/src/base/constants/AppConstants.js index 497073b..770bf46 100644 --- a/src/base/constants/AppConstants.js +++ b/src/base/constants/AppConstants.js @@ -17,8 +17,10 @@ import GLib from 'gi://GLib'; export const AppConstants = Object.freeze({ App: { + version: '0.0.8', doc: 'https://keygenqt.github.io/aurora-toolbox/', docInstall: 'https://keygenqt.github.io/aurora-toolbox/install/', + latestRelease: 'https://api.github.com/repos/keygenqt/aurora-toolbox/releases/latest', }, AppCLI: { doc: 'https://keygenqt.github.io/aurora-cli/', diff --git a/src/base/utils/Helper.js b/src/base/utils/Helper.js index 56237b5..c052309 100644 --- a/src/base/utils/Helper.js +++ b/src/base/utils/Helper.js @@ -16,6 +16,7 @@ import GObject from 'gi://GObject'; import Gtk from 'gi://Gtk'; import GLib from 'gi://GLib'; +import Soup from 'gi://Soup'; import { Log } from './Log.js'; import { AuroraAPI } from '../connectors/AuroraAPI.js'; @@ -194,5 +195,44 @@ export const Helper = { await new Promise(r => setTimeout(r, time)); dialog.close(); } + }, + /** + * Http query + */ + httpRequest(url) { + return new Promise((resolve, reject) => { + + if (Soup.MAJOR_VERSION === 3) { + let session = new Soup.Session(); + session.set_timeout(5); + session.set_user_agent('aurora-toolbox'); + let message = Soup.Message.new('GET', url); + session.send_and_read_async( + message, + GLib.PRIORITY_DEFAULT, + null, + function (session, result) { + try { + if (message.get_status() === Soup.Status.OK) { + let bytes = session.send_and_read_finish(result); + let decoder = new TextDecoder('utf-8'); + let response = decoder.decode(bytes.get_data()); + resolve({ + code: result.status_code, + body: response, + }); + } else { + resolve({ + code: message.get_status() === 0 ? 500 : message.get_status(), + }) + } + } catch (e) { + resolve({ code: 500 }) + } + }); + } else { + resolve({ code: 500 }) + } + }); } } diff --git a/src/feature/pages/welcome/WelcomePage.js b/src/feature/pages/welcome/WelcomePage.js index 7bc9e8c..d508bfb 100644 --- a/src/feature/pages/welcome/WelcomePage.js +++ b/src/feature/pages/welcome/WelcomePage.js @@ -54,32 +54,53 @@ export const WelcomePage = GObject.registerClass({ #loadingConnect() { this.#statePage(WelcomePageStates.LOADING); this.utils.helper.getPromisePage(async () => { - return this.utils.helper.getLastObject( + const auroraCLI = this.utils.helper.getLastObject( await this.connectors.exec.communicateAsync(this.connectors.aurora.appVersions()) ); + const auroraToolbox = (await this.utils.helper.httpRequest( + this.utils.constants.App.latestRelease + ))?.body?.parseMultipleJson(); + return { + code: 200, + cliLatest: String(auroraCLI?.value?.LATEST) !== 'undefined' ? auroraCLI?.value?.LATEST : undefined, + cliInstalled: String(auroraCLI?.value?.INSTALLED) !== 'undefined' ? auroraCLI?.value?.INSTALLED : undefined, + toolboxLatest: auroraToolbox?.tag_name ?? undefined, + toolboxInstalled: this.utils.constants.App.version + } }).then((response) => { try { if (response && response.code === 200) { // Failed to retrieve data - if (response.value.LATEST === 'undefined') { - response.value.LATEST = response.value.INSTALLED; + if (response.cliLatest === undefined) { + response.cliLatest = response.cliInstalled; + } + if (response.toolboxLatest === undefined) { + response.toolboxLatest = response.toolboxInstalled; } - // Check new version Aurora CLI - const hasNewVersion = response.value.INSTALLED !== response.value.LATEST; + // Check new version + const hasNewVersionCLI = response.cliInstalled !== response.cliLatest; + const hasNewVersionToolbox = response.toolboxInstalled !== response.toolboxLatest; // If has new version - if (hasNewVersion) { - this.#setStateUpdate(response.value.LATEST, false /*@todo Now only aurora-cli check*/ ); + if (hasNewVersionToolbox) { + this.#setStateUpdate(response.toolboxLatest, true); this.#statePage(WelcomePageStates.UPDATE); return } - // If first app open - if (settings.get_boolean('first-open')) { - this._IdConnect.version = `${response.value.INSTALLED}`; - this.#statePage(WelcomePageStates.CONNECT); + else if (hasNewVersionCLI) { + this.#setStateUpdate(response.cliLatest, false); + this.#statePage(WelcomePageStates.UPDATE); return } - // Open tools - this.#window.navigation().push(this.utils.constants.Pages.ToolsPage); + else { + // If first app open + if (settings.get_boolean('first-open')) { + this._IdConnect.version = `${response.cliInstalled}`; + this.#statePage(WelcomePageStates.CONNECT); + return + } + // Open tools + this.#window.navigation().push(this.utils.constants.Pages.ToolsPage); + } } else { this.#statePage(WelcomePageStates.NOT_FOUND); }