summaryrefslogtreecommitdiffstats
path: root/src/js/apps.js
blob: d7b120180c007d7a2acfa570d112aa7c71d6e85c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { load as load_template } from './templates';
import Mustache from 'mustache';

var configjson = require('../config.json');
var template;
var root;
var page = {
    apps: []
};

function show() {
    root.innerHTML = Mustache.render(template, page);
}

function locateApp(appId, appList) {
    return appList.find(function(app){
        return app[0].split('@')[0] === appId
    });
}

function load_application_list() {
    navigator.appService.getApplications(true, result => {
        configjson.apps.forEach(function(app) {
            var internalApp = locateApp(app.id, result);

            if( internalApp ) {
                page.apps.push({
                    id: internalApp[0],
                    name: internalApp[1],
                    icon: app.icon
                });

                if( app.id === configjson.launch ) {
                    setTimeout(function() {
                        navigator.appService.start(internalApp[0]);
                    }, 1000);
                }
            }

        });

        show();
    });
}

export function start(appId) {
    navigator.appService.start(appId.split('@')[0]);
}

export function init(node) {
    load_template('apps.template.html').then(function(result) {
        template = result;
        root = node;
        Mustache.parse(template);
        load_application_list();
    }, function(error) {
        console.error('ERRROR loading main template', error);
    });
}