Passed
Push — 6.4 ( 5645ce...8ba989 )
by Christian
15:05 queued 12s
created

index.ts ➔ created   A

Complexity

Conditions 3

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
dl 0
loc 16
rs 9.7
c 0
b 0
f 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