diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5fd7f6f5..0ec7b398 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,8 +26,13 @@ namespace OCA\RiotChat\AppInfo; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\IRequest; +use OCP\Util; -class Application extends App { +class Application extends App implements IBootstrap { public const APP_ID = 'riotchat'; public const AvailableSettings = [ @@ -54,4 +59,15 @@ public static function AvailableLabs() { // TODO: Remove the labs feature fully return []; } + + public function boot(IBootContext $context): void { + $request = $this->getContainer()->get(IRequest::class); + // The user is redirected to '/login?clear=1' + if ($request->getPathInfo() === '/login') { + Util::addScript(self::APP_ID, 'logout'); + } + } + + public function register(IRegistrationContext $context): void { + } } diff --git a/src/logout.js b/src/logout.js new file mode 100644 index 00000000..da85f5b3 --- /dev/null +++ b/src/logout.js @@ -0,0 +1,25 @@ +/* + * @copyright Copyright (c) 2021 Gary Kim + * + * @author Gary Kim + * + * 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 . + */ + +const url = new URL(window.location); +if (url.searchParams.get('clear') === "1") { + window.indexedDB.deleteDatabase('matrix-react-sdk'); + window.indexedDB.deleteDatabase('matrix-js-sdk:riot-web-sync'); + window.indexedDB.deleteDatabase('matrix-js-sdk:crypto'); +} diff --git a/webpack.config.js b/webpack.config.js index 7c4fb7d3..a3c4e305 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,7 +6,8 @@ const webpack = require('webpack'); module.exports = { entry: { adminSettings: path.join(__dirname, 'src', 'adminSettings.js'), - main: path.join(__dirname, 'src', 'main.js'), + main: path.join(__dirname, 'src', 'main.js'), + logout: path.join(__dirname, 'src', 'logout.js'), }, output: { path: path.join(__dirname, 'js'), @@ -37,10 +38,10 @@ module.exports = { }, plugins: [ new VueLoaderPlugin(), - new webpack.DefinePlugin({ + new webpack.DefinePlugin({ RIOT_WEB_HASH: JSON.stringify(execSync('git rev-parse HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()), RIOT_WEB_VERSION: JSON.stringify(execSync('git describe --exact-match HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()), - }), + }), ], resolve: { extensions: ['.js', '.vue'],