diff --git a/src/mixins/autoLogout.js b/src/mixins/autoLogout.js new file mode 100644 index 0000000000..6c207d49e0 --- /dev/null +++ b/src/mixins/autoLogout.js @@ -0,0 +1,50 @@ +/* + * @copyright Copyright (c) 2023 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * 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 . + */ + +import { loadState } from '@nextcloud/initial-state' + +export default { + + mounted() { + const config = loadState('core', 'config') + + if (!config.auto_logout) { + return + } + + window.addEventListener('mousemove', this.extendAutoLogout) + window.addEventListener('touchstart', this.extendAutoLogout) + window.addEventListener('keydown', this.extendAutoLogout) + }, + + beforeDestroy() { + window.removeEventListener('mousemove', this.extendAutoLogout) + window.removeEventListener('touchstart', this.extendAutoLogout) + window.removeEventListener('keydown', this.extendAutoLogout) + }, + + methods: { + extendAutoLogout() { + localStorage.setItem('lastActive', Date.now().toString()) + }, + }, + +} diff --git a/src/view/Office.vue b/src/view/Office.vue index ae4521be9f..4a3bfa7b7b 100644 --- a/src/view/Office.vue +++ b/src/view/Office.vue @@ -99,6 +99,7 @@ import { getUIDefaults, } from '../helpers/coolParameters.js' import Config from '../services/config.tsx' +import autoLogout from '../mixins/autoLogout.js' import openLocal from '../mixins/openLocal.js' import pickLink from '../mixins/pickLink.js' import saveAs from '../mixins/saveAs.js' @@ -124,7 +125,7 @@ export default { ZoteroHint, }, mixins: [ - openLocal, pickLink, saveAs, uiMention, version, + autoLogout, openLocal, pickLink, saveAs, uiMention, version, ], props: { filename: {