From b9a7bd5baaa45a0395160096db299ef518912e16 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 4 Apr 2024 19:31:15 +0200 Subject: [PATCH] feat: Only show wizard on updates if the user did not seen the changelog Signed-off-by: Ferdinand Thiessen --- lib/Constants.php | 32 +++++++++++++++++++ lib/Controller/WizardController.php | 7 +++- .../BeforeTemplateRenderedListener.php | 13 +++++++- src/views/App.vue | 7 +++- tests/Controller/WizardControllerTest.php | 2 +- 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 lib/Constants.php diff --git a/lib/Constants.php b/lib/Constants.php new file mode 100644 index 00000000..b6c6c084 --- /dev/null +++ b/lib/Constants.php @@ -0,0 +1,32 @@ + + * + * @author Ferdinand Thiessen + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\FirstRunWizard; + +class Constants { + /** + * Version for which the latest changelog entries are available + * This is used to decide if we show the wizard for users on an update + */ + public const CHANGELOG_VERSION = '29.0.0'; +} diff --git a/lib/Controller/WizardController.php b/lib/Controller/WizardController.php index 1cf253e2..44e57322 100644 --- a/lib/Controller/WizardController.php +++ b/lib/Controller/WizardController.php @@ -42,7 +42,12 @@ public function __construct( * @return DataResponse */ public function disable() { - $this->config->setUserValue($this->userId, 'firstrunwizard', 'show', '0'); + // get the current Nextcloud version + $version = \OCP\Util::getVersion(); + // we only use major.minor.patch + array_splice($version, 3); + // Set "show" to current version to only show on update + $this->config->setUserValue($this->userId, 'firstrunwizard', 'show', implode('.', $version)); return new DataResponse(); } } diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index fd23274b..1050996d 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -27,6 +27,7 @@ namespace OCA\FirstRunWizard\Listener; use OCA\FirstRunWizard\AppInfo\Application; +use OCA\FirstRunWizard\Constants; use OCA\FirstRunWizard\Notification\AppHint; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Services\IAppConfig; @@ -73,9 +74,19 @@ public function handle(Event $event): void { } if ($this->appConfig->getAppValueBool('wizard_enabled', true)) { - if ($this->config->getUserValue($user->getUID(), Application::APP_ID, 'show', '1') !== '0') { + $lastSeenVersion = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'show', '0.0.0'); + + // If current is newer then last seen we activate the wizard + if (version_compare(Constants::CHANGELOG_VERSION, $lastSeenVersion, '>')) { Util::addScript(Application::APP_ID, Application::APP_ID . '-activate'); + } + // If the user was already seen before (compatibility with older wizard versions where the value was 1) + // then we only show the changelog + if (version_compare($lastSeenVersion, '1', '>')) { + $this->initialState->provideInitialState('changelogOnly', true); + } else { + // Otherwise if the user really uses Nextcloud for the very first time we create notifications for them $this->jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $this->userSession->getUser()->getUID()]); } diff --git a/src/views/App.vue b/src/views/App.vue index d0ab2e15..fcf279a1 100644 --- a/src/views/App.vue +++ b/src/views/App.vue @@ -35,7 +35,7 @@ @close="close" @next="currentPage += 1" @previous="currentPage -= 1"> - + @@ -49,8 +49,13 @@ import axios from '@nextcloud/axios' import IntroAnimation from '../components/pages/IntroAnimation.vue' import SlideShow from '../components/SlideShow.vue' import pages from '../pages' +import { loadState } from '@nextcloud/initial-state' const isMobile = useIsSmallMobile() +/** This is set to true in case the user already received the wizard but Nextcloud was updated to show the changelog only */ +const showChangelogOnly = loadState('firstrunwizard', 'changelogOnly', false) +/** The index of the changelog page for first run on updated Nextcloud Hub only */ +const changelogPage = Math.min(pages.findIndex((page) => page.id === 'hub-release'), 0) const showModal = ref(false) const currentPage = ref(null) diff --git a/tests/Controller/WizardControllerTest.php b/tests/Controller/WizardControllerTest.php index fe94a38d..e42734c0 100644 --- a/tests/Controller/WizardControllerTest.php +++ b/tests/Controller/WizardControllerTest.php @@ -74,7 +74,7 @@ public function testDisable($user) { $this->config->expects($this->once()) ->method('setUserValue') - ->with($user, 'firstrunwizard', 'show', '0'); + ->with($user, 'firstrunwizard', 'show'); $response = $controller->disable();