

// globalThis.cslog = //console.log
console.log = function () {

 }
 console.trace = function () {

 }
console.debug = function (text) {
    var date = new Date()
    text = `========= [${date}] ${text}`
    print(text)
}

function initEventLister() {
    var EventEmitter = require('@system.events');
    globalThis.eventEmitter = new EventEmitter();
}
function onCreate(uri) {

    var re860_router = require("router-re860.js").router;
    re860_router.onClick = function (node, topNode, x, y) {
        var systemCtrl = require("systemCtrl.js");
        systemCtrl.executeSystemCommand("/mnt/app/quicknode/shell/eAplay.sh /mnt/app/voice_click.wav");
    }
    initEventLister();
    globalThis.Simu = {
        "En": 0,
    }
    globalThis.test = {
        "En": 0,
    }
    var process = require("@system.process")
    if (process.platform == "win32") {
        //console.log("its win32.")
        globalThis.Simu.En = 1
    }
    globalThis.DEV = {
        "tpLog": 1,
    }
    initEventLister();
    gc();
    //console.log(showMemInfo());
    var dom = require("dom.js");  //要放在router后面，router会创建document
    var router = re860_router;
    var times = [];
    if (startUrl() == undefined) {
        times.push(clock());
        gc();
        router.push({ 'path': uri });
        times.push(clock());
        gc();
    } else {
        times.push(clock());
        var uriObj = JSON.parse(globalThat.$uri);
        console.log(uriObj);
        router.push(uriObj);
        times.push(clock());
        console.log(times);
        gc();
    }

     require("autoFactoryTest.js").autoFactoryTestTimer();
}

// function onKeyEvent(code) {
//     var router = require("@system.router");
//     var keypad = require("keypadCode.js")
//     keypad.triggerByCode(code)
//     //console.log("++++ CodeNum:" + code)
//     return
//     if (code == 62) {
//         router.pageDebug(!router.debugOn);
//     }
// }

function onDestroy() {
    // 应用退出时会被触发
    var router = require("@system.router");
    router.quit();
}

function onGestureEvent(dir, x, y) {
    var router = require("@system.router");
    var indexObj = router.currentPage.$indexObj;
    if (indexObj.hasOwnProperty('onGestureEvent')) {
        indexObj.onGestureEvent(dir, x, y);
    }
}
function onMoveEvent(globalX, globalY, topObj, x, y) {
    if (this.currentPage) {
        var indexObj = this.currentPage.$indexObj;
        if (indexObj && (indexObj.hasOwnProperty('onmousemove') ||
            indexObj.hasOwnProperty('touchmove'))) {
            if (indexObj.$onmousemove == undefined) {
                if (indexObj.hasOwnProperty('onmousemove')) {
                    indexObj.$onmousemove = indexObj.onmousemove;
                } else if (indexObj.hasOwnProperty('touchmove')) {
                    indexObj.$onmousemove = indexObj.touchmove;
                }
            }
            if (typeof indexObj.$onmousemove == "function") {
                var node = __getElementByObj(indexObj, topObj)
                if (node) {
                    if (indexObj.$onmousemove.length == 1) {
                        var e = router.toH5Event(node, node, x, y);
                        indexObj.$onmousemove(e);
                        return;
                    }
                }
                indexObj.$onmousemove(globalX, globalY, topObj, x, y);
            }
        }
    }
}

EvueApp({
    // "font": "MideaType-Regular.ttf",
    "font": "SimHei_GB2312_80_t.ttf",
    // "font": "Metropolis-Medium.ttf",
    'onCreate': onCreate,
    'onDestroy': onDestroy,
    'onMoveEvent': onMoveEvent,
    'onGestureEvent': onGestureEvent,
    'paths': ["../RD190/", "../../enode_modules/", "./../RE860A/logicJS/", "./../RE860A/common/", "./../RE860A/", "./../re860a-v1.0/", "./../re860a-v1.0/logicJS/", "./../re860a-v1.0/common/", "./factoryTest_plugin/", "./factoryTest_plugin/ref/", "./factoryTestItem/"],
    'uri': 'factory_testList',
    // 'uri': 'testLongTimeList',
    'minFreeJSHeapSize': 200
});

