Skip to content

Commit

Permalink
feat: Only show wizard on updates if the user did not seen the changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Apr 8, 2024
1 parent 1daa1bf commit b9a7bd5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
32 changes: 32 additions & 0 deletions lib/Constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]>
*
* @author Ferdinand Thiessen <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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';
}
7 changes: 6 additions & 1 deletion lib/Controller/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
13 changes: 12 additions & 1 deletion lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()]);
}

Expand Down
7 changes: 6 additions & 1 deletion src/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@close="close"
@next="currentPage += 1"
@previous="currentPage -= 1">
<IntroAnimation v-if="currentPage === null" @next="currentPage = 0" />
<IntroAnimation v-if="currentPage === null" @next="currentPage = showChangelogOnly ? changelogPage : 0" />
<SlideShow v-else :pages="pages" :current-index.sync="currentPage" />
</NcModal>
</template>
Expand All @@ -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<boolean>('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<number|null>(null)
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/WizardControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit b9a7bd5

Please sign in to comment.