| Total Complexity | 9 |
| Complexity/F | 1.5 |
| Lines of Code | 63 |
| Function Count | 6 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import template from './sw-admin.html.twig'; |
||
| 2 | |||
| 3 | const { Component } = Shopware; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * @package admin |
||
| 7 | * |
||
| 8 | * @private |
||
| 9 | */ |
||
| 10 | Component.register('sw-admin', { |
||
| 11 | template, |
||
| 12 | |||
| 13 | inject: ['userActivityService', 'loginService'], |
||
| 14 | |||
| 15 | metaInfo() { |
||
| 16 | return { |
||
| 17 | title: this.$tc('global.sw-admin-menu.textShopwareAdmin'), |
||
| 18 | }; |
||
| 19 | }, |
||
| 20 | |||
| 21 | data(): { |
||
| 22 | channel: BroadcastChannel | null, |
||
| 23 | } { |
||
| 24 | return { |
||
| 25 | channel: null, |
||
| 26 | }; |
||
| 27 | }, |
||
| 28 | |||
| 29 | computed: { |
||
| 30 | isLoggedIn() { |
||
| 31 | return this.loginService.isLoggedIn(); |
||
| 32 | }, |
||
| 33 | }, |
||
| 34 | |||
| 35 | created() { |
||
| 36 | this.channel = new BroadcastChannel('session_channel'); |
||
| 37 | this.channel.onmessage = (event) => { |
||
| 38 | const data = event.data as { inactive?: boolean }; |
||
| 39 | |||
| 40 | if (!data || !Shopware.Utils.object.hasOwnProperty(data, 'inactive')) { |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | const routeBlocklist = ['sw.inactivity.login.index', 'sw.login.index.login']; |
||
| 45 | if (!data.inactive || routeBlocklist.includes(this.$router.currentRoute.name || '')) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | this.loginService.forwardLogout(true, true); |
||
| 50 | }; |
||
| 51 | }, |
||
| 52 | |||
| 53 | beforeDestroy() { |
||
| 54 | this.channel?.close(); |
||
| 55 | }, |
||
| 56 | |||
| 57 | methods: { |
||
| 58 | onUserActivity() { |
||
| 59 | this.userActivityService.updateLastUserActivity(); |
||
| 60 | }, |
||
| 61 | }, |
||
| 62 | }); |
||
| 63 |