Passed
Push — 6.4.12.0 ( 1333fb )
by Christian
14:12
created

window.init.ts ➔ initializeWindow   C

Complexity

Conditions 9

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 32
c 0
b 0
f 0
cc 9
rs 6.6666
1
/* Is covered by E2E tests */
2
/* istanbul ignore file */
3
import type VueRouter from 'vue-router';
4
5
export default function initializeWindow(): void {
6
    // Handle incoming window requests from the ExtensionAPI
7
    Shopware.ExtensionAPI.handle('windowReload', () => {
8
        window.location.reload();
9
    });
10
11
    Shopware.ExtensionAPI.handle('windowRedirect', ({ newTab, url }) => {
12
        if (newTab) {
13
            window.open(url, '_blank');
14
        } else {
15
            window.location.href = url;
16
        }
17
    });
18
19
    Shopware.ExtensionAPI.handle('windowRouterPush', ({
20
        name,
21
        params,
22
        path,
23
        replace,
24
    }) => {
25
        const $router = Shopware.Application.view?.root?.$router as unknown as VueRouter;
26
27
        if (!$router) {
28
            return;
29
        }
30
31
        $router.push({
32
            name: name && name.length > 0 ? name : undefined,
33
            params,
34
            path: path && path.length > 0 ? path : undefined,
35
            replace: replace ?? false,
36
        });
37
    });
38
}
39