PATH="file:///usr/local/apps_nv/apps/home/";
COMMON_PATH=PATH+"common/";
PROTOTYPE_PATH=PATH+"prototype/";
IMG_PATH=PATH+"img/";
RESIDENT_IMG_PATH="file:///usr/local/png/";
LANG_PATH=PATH+"lang/";
APPLI_PATH="file:///usr/local/apps_nv/apps/";
SOUND_PATH=PATH+"sound/";
VOICE_CONTROL_PATH="file:///usr/local/apps_nv/voice_ctrl/";
VOICE_CONTROL_PREFIX="usrprof_"
APPS_DATA_PATH="file:///usr/local/apps_nv/data/";
CAMERA_POS=-1661.036724459;
SCREEN_PATH="file:///usr/local/apps_nv/screen/";
SCREEN_PREFIX="myscreen_";
SCREEN_DL_SUFFIX="downloaded";
SCREEN_INST_SUFFIX="install";
SCREEN_INST_AUTO_SUFFIX="install_auto";
SCREEN_DELETE_AUTO_SUFFIX="delete_auto";
try{
boot_screen;}catch(e){
boot_screen=null;}
var cache_wallpaper=null;
function fast_boot(){
try{
var tmp=getPowerOnScreen();
if(isScreenKey(boot_screen))tmp=boot_screen;
var url=getScreenInfo(tmp).wallpaper||DEFAULT_SCREEN_WALLPAPER;
cache_wallpaper=new gimage({src:url});}catch(e){
console.log(e.message);
cache_wallpaper=null;};};
const MY_SCREEN=0;
const SWITCH_SCREEN=1;
const EDIT_SCREEN=2;
const VOICE_CONTROL_SCREEN=3;
var SCREEN_FIXED_NUM;
var SCREEN_PARTNER_ADD_NUM;
var SCREEN_USER_ADD_NUM;
var SCREEN_USER_MAX_NUM;
function initNumOfScreen(){
SCREEN_FIXED_NUM=1;SCREEN_PARTNER_ADD_NUM=2;SCREEN_USER_ADD_NUM=7;if(system.product.match("(PRO4|LD6|PRO5)"))
SCREEN_USER_ADD_NUM=27;
if(!SU_SUPPORT_MYHOMESCREEN){
SCREEN_FIXED_NUM=1;
SCREEN_PARTNER_ADD_NUM=0;
SCREEN_USER_ADD_NUM=0;}
}
var UI_MODE=MY_SCREEN;
var test_load=function (file){
load(file);}
NULL_FUNCTION=function(){return null;};
SU_COUNTRY=system.locale.country;
SU_LANGUAGE=system.locale.language.substr(0,5);
SU_IS_PRO4TV=(function (){return (system.product.indexOf("PRO4")!=-1);})();
SU_IS_PRO5TV=(function (){return (system.product.indexOf("PRO5")!=-1);})();
SU_IS_13MT5590=false;
SU_IS_4K=(function (){return (system.product.indexOf("_4K")!=-1);})();
SU_IS_PRO4_4K=(function (){
return (system.product.indexOf("PRO4")!=-1&&system.product.indexOf("_4K")!=-1);})();
SU_SUPPORT_MYHOMESCREEN=(function (){
return (system.mdl_cfg.support_myhomescreen!==false)
})();
initNumOfScreen();
try{
system.write_iptv_req(0);}catch(e){};
add_package_load_path("kbd",COMMON_PATH+"keyboard/pkg_keyboard.js");
add_package_load_path("filer",COMMON_PATH+"filer/filer.js");
add_package_load_path("json2",COMMON_PATH+"json/json2.js");
add_package_load_path("sax-js",COMMON_PATH+"sax-js/lib/sax.js");
add_package_load_path("textarea",COMMON_PATH+"keyboard/pkg_textarea.js");
add_package_load_path("pkg_browser",APPLI_PATH+"0077777700140002/gadget/pkg_browser.js");
add_package_load_path("pkg_password",PROTOTYPE_PATH+"password.js");
add_package_load_path("pkg_confirmpanel",PROTOTYPE_PATH+"confirmpanel.js");
add_package_load_path("screen",PROTOTYPE_PATH+"screen.js");
add_package_load_path("startup_selection",PATH+"startup_selection.js");
add_package_load_path("startup_voice_control",PATH+"startup_voice_control.js");
add_package_load_path("startup_voice_control_util",PATH+"startup_voice_control_util.js");
add_package_load_path("startup_screen",PATH+"startup_screen.js");
add_package_load_path("apps_plate",PATH+"apps_prototype/apps_plate.js");
add_package_load_path("initial_data",PATH+"initial_data.js");
add_package_load_path("initial_bookmark",PATH+"initial_bookmark.js");
add_package_load_path(SCREEN_PREFIX+"tv",PROTOTYPE_PATH+"full_screen.js");
add_package_load_path(SCREEN_PREFIX+"life",PROTOTYPE_PATH+"lifestyle_screen.js");
add_package_load_path(SCREEN_PREFIX+"zapping",PROTOTYPE_PATH+"tv_centric_screen.js");
add_package_load_path(SCREEN_PREFIX+"info",PROTOTYPE_PATH+"info_screen.js");
add_package_load_path(SCREEN_PREFIX+"play0",PROTOTYPE_PATH+"play0.js");
add_package_load_path(SCREEN_PREFIX+"inst",PROTOTYPE_PATH+"inst_screen.js");
add_package_load_path(SCREEN_PREFIX+"freetime",PROTOTYPE_PATH+"freetime_screen.js");
add_package_load_path(SCREEN_PREFIX+"food",PROTOTYPE_PATH+"food_screen.js");
add_package_load_path(SCREEN_PREFIX+"football",PROTOTYPE_PATH+"football_screen.js");
add_package_load_path(SCREEN_PREFIX+"cn_food",PROTOTYPE_PATH+"cn_food_screen.js");
add_package_load_path(SCREEN_PREFIX+"cn_game",PROTOTYPE_PATH+"cn_game_screen.js");
add_package_load_path(SCREEN_PREFIX+"infobar",PROTOTYPE_PATH+"infobar_screen.js");
add_package_load_path(SCREEN_PREFIX+"signage",PROTOTYPE_PATH+"signage_screen.js");
add_package_load_path(SCREEN_PREFIX+"xumo",PROTOTYPE_PATH+"xumo_screen.js");
add_stage_load_path("search",PATH+"search.js");
add_stage_load_path("message",APPLI_PATH+"0387878700140065/gadget/message.js");
add_stage_load_path("platinum_main",APPLI_PATH+"0077777700140002/gadget/platinum_main.js");
add_stage_load_path("signage",APPLI_PATH+"0377777700000018/gadget/signage.js");
system.effect_sound.set_sound(0,SOUND_PATH+"move_focus.aiff");
system.effect_sound.set_sound(1,SOUND_PATH+"move_focus_tv.aiff");
system.effect_sound.set_sound(2,SOUND_PATH+"home_select.aiff");
system.effect_sound.set_sound(3,SOUND_PATH+"switch_home.aiff");
system.effect_sound.set_sound(4,SOUND_PATH+"my_home.aiff");
system.effect_sound.set_sound(5,SOUND_PATH+"enter.aiff");
system.effect_sound.set_sound(7,SOUND_PATH+"cancel.aiff");
if(system.mdl_cfg.with_mystream){
add_stage_load_path("mystream",APPLI_PATH+"0387878700000056/gadget/mystream.js");}
var screen_name_list=[
"LT_HOME_FULL_TV",
"LT_HOME_TV",
"LT_HOME_LIFESTYLE",
"LT_HOME_INFO",
"LT_HOME_MY_HOME_SCREEN",
"LT_SCREEN_NAME_CN_BESTCITY",
"LT_SCREEN_NAME_CN_FOOD",
"LT_SCREEN_NAME_CN_GAME",
"LT_SCREEN_NAME_FOOTBALL",
"LT_SCREEN_NAME_FREETIME",
"LT_SCREEN_NAME_INFOBAR",
"LT_SCREEN_NAME_MALAYSIA",
];
var HOME_SOUND_MUTE=null;
function HomeSoundPlay(id){
try{
if(HOME_SOUND_MUTE==false){
if(id=="enter"){
system.effect_sound.play(5);}else if(id=="cancel"){
system.effect_sound.play(7);}else {
system.effect_sound.play(id);}
}
}catch(e){};}
HOME_SOUND_PLAY=HomeSoundPlay;
if(!SU_SUPPORT_MYHOMESCREEN){
var ret=getSoundMute();
if(ret!==true){
storeSoundMute(true);}
HOME_SOUND_MUTE=true;}
PLATINUM_CONNECTED_EV=0;
try{
test_load(PATH+"util.js");
fast_boot();
test_load(PROTOTYPE_PATH+"my_lib.js");
test_load(PROTOTYPE_PATH+"focus.js");
test_load(PROTOTYPE_PATH+"toolbar.js");
require("screen");
test_load(PROTOTYPE_PATH+"operator.js");
test_load(PROTOTYPE_PATH+"gadget.js");
test_load(PATH+"guidance/guidance_lite.js");
require("json2");
provide("json2");
require("sax-js");
provide("sax-js");
require("startup_screen");}catch(e){console.log("Error = "+e.message);};
gcHome();
initNumOfScreen();
try{
test_load(APPLI_PATH+MARKETTOP_APPS+"/gadget/smad.js");}catch(e){};
try{
isDisclaimerNeeded();}catch(e){
console.log(e.message);}
var is_power_on_netflix=(function(){
try{
return system.is_power_on_netflix();}catch(e){
return false;}
})();

LockPasswordPanel=function(action_func,cancel_func,focus_moveto){
require("pkg_password");
LockPasswordPanel=pkg_password.LockPasswordPanel;
return new LockPasswordPanel(action_func,cancel_func,focus_moveto);};
Confirmpanel=function(type,action_func,focus_moveto){
require("pkg_confirmpanel");
Confirmpanel=pkg_confirmpanel.Confirmpanel;
return new Confirmpanel(type,action_func,focus_moveto);};
Confirmpanel.prototype.OPTION_TYPE_OK=0;
Confirmpanel.prototype.OPTION_TYPE_YES_NO=1;
Confirmpanel.prototype.OPTION_TYPE_YES_NO_CANCEL=2;

var lang=SU_LANGUAGE;
LANG=load_pkg_lang(PATH+"lang","home");
VOICE=load_pkg_voice(PATH+"lang","home");
var HOME_KEY_LAYOUT="UPPER";
switch(SU_COUNTRY){
case "JP":
var HOME_KEY=IMG_PATH+"home_jp_g.png";
var APPS_KEY=IMG_PATH+"apps_jp_bk.png";
break;
case "TW":
if(SU_IS_PRO4TV==true||SU_IS_PRO5TV==true){
var HOME_KEY=IMG_PATH+"home_tw_g.png";
var APPS_KEY=IMG_PATH+"apps_en_gr.png";}else {var HOME_KEY=IMG_PATH+"home_tw_bk.png";
var APPS_KEY=IMG_PATH+"apps_en_bk.png";}
break;
case "CN":
if(SU_IS_PRO4TV==true||SU_IS_PRO5TV==true){
var HOME_KEY=IMG_PATH+"home_china_g.png";
var APPS_KEY=IMG_PATH+"apps_china_w.png";}else {var HOME_KEY=IMG_PATH+"home_china_bk.png";
var APPS_KEY=IMG_PATH+"apps_china_bk.png";}
break;
case "DE":
case "AT":
case "FR":
case "IT":
case "ES":
case "PT":
case "NL":
case "DK":
case "SE":
case "NO":
case "FI":
case "BE":
case "CH":
case "GR":
case "PL":
case "CZ":
case "HU":
case "EEU":
case "UK":
case "IE":
case "SK":
case "HR":
case "SI":
case "EE":
case "LT":
case "MT":
case "AD":
case "LU":
case "TR":
case "IS":
case "OTH":
case "RU":
case "UA":
case "KZ":
case "CIS":
case "RO":
case "MK":
var HOME_KEY=IMG_PATH+"home_en_bk.png";
var APPS_KEY=IMG_PATH+"apps_en_bk.png";

try{
if(SU_IS_PRO4TV==true||SU_IS_PRO5TV==true){
if(SU_IS_PRO4_4K==true||SU_IS_PRO5TV==true){
var HOME_KEY=IMG_PATH+"home_silver.png";
var APPS_KEY=IMG_PATH+"apps_silver.png";
HOME_KEY_LAYOUT="LOWER";}else{
var HOME_KEY=IMG_PATH+"home_en_g.png";
var APPS_KEY=IMG_PATH+"apps_en_gr.png";}
}
if(SU_IS_GBL15){
HOME_KEY_LAYOUT="SIDE";}
}catch(e){};
break;
default:
if(SU_IS_PRO4TV==true||SU_IS_PRO5TV==true){
var HOME_KEY=IMG_PATH+"home_en_g.png";
var APPS_KEY=IMG_PATH+"apps_en_gr.png";}else {var HOME_KEY=IMG_PATH+"home_en_bk.png";
var APPS_KEY=IMG_PATH+"apps_en_bk.png";
if(SU_IS_GBL15){
if(SU_COUNTRY.match("^(US|CA|MX|US-NA|CA-NA|MX-NA|AU|NZ|BR|CL|PE|CO|PA|01)$")){
HOME_KEY_LAYOUT="SIDE";}
}
}
break;}
var GADGET_TEMPLATE={"tv":[TV_GADGET],
"zapping":[TV_GADGET,ZAPPING_GADGET,APPS_GADGET],
"life":[TV_GADGET,"","","",APPS_GADGET],
"info":[TV_GADGET,BOOKMARK_GADGET,APPS_GADGET],
"play0":[TV_GADGET,"","","","","","","","",
APPS_GADGET,],
};
var SCREEN_INFO=[];
var SCREEN_ORDER=[];
var POWERON_SCREEN=null;
var LAST_VIEW_SCREEN=null;
try{
storePONCheck();
POWERON=getPowerOnScreen();
if(isScreenKey(boot_screen))POWERON=boot_screen;
LAST_VIEW_SCREEN=POWERON;
SCREEN_ORDER=getScreenOrder();
for(var i=0;i<SCREEN_ORDER.length;i++){
SCREEN_INFO[i]=getScreenInfo(SCREEN_ORDER[i]);}
system.apps.set_cur_screen(getFaceScreenKey(POWERON));}catch(e){
console.log("Cannot read first time screen infomation: Error = "+e.message);
require("initial_data");
initial_data.init_order();}
for(var i=0;i<INIT_FILE.length;i++){
try{
load_init_file(INIT_FILE[i]);}catch(e){console.log("Error = "+e.message);};}
function makeUniqIDs(screen_info,product_ids){
var p_len=screen_info.product_id_list.length;
screen_info.uniq_id_list=[];
for(var j=0;j<p_len;j++){
if(screen_info.product_id_list[j]==""){
screen_info.uniq_id_list[j]="";}else if(screen_info.product_id_list[j]&&screen_info.product_id_list[j].length==16){
var my_product_id=screen_info.product_id_list[j].toString();
if(product_ids[my_product_id]==undefined){
product_ids[my_product_id]=0;}else {
product_ids[my_product_id]=parseInt(product_ids[my_product_id])+1;}
var ziro_num=4-product_ids[my_product_id].toString().length;
screen_info.uniq_id_list[j]=screen_info.product_id_list[j];
for(var k=0;k<ziro_num;k++){
screen_info.uniq_id_list[j]=screen_info.uniq_id_list[j]+"0";}
screen_info.uniq_id_list[j]=screen_info.uniq_id_list[j]+product_ids[screen_info.product_id_list[j].toString()].toString();

}
}
}
for(var i=0;i<SCREEN_ORDER.length;i++){
if(SCREEN_INFO[i].install_type===undefined||
SCREEN_INFO[i].uniq_id_list==undefined||!SCREEN_INFO[i].uniq_id_list){
require("initial_data");
initial_data.storeFirstTimeScreenInfo();
break;}
}
function storeExceptionInformation(str,ex){
try{
var nvram_file_list=apps_nvram_file.list({product_id:"home"});
var err_info="";
if((nvram_file_list)&&(nvram_file_list.indexOf("modify_uniqID_exception")!=-1)){
err_info=apps_nvram_file.read({filename:"modify_uniqID_exception",async:false,finished:function(){},product_id:"home"});
err_info=sysutil.tconv.binary_to_string(err_info);}
var err_str=err_info.toString()+str+" Error:"+ex.message+"\n";
var ret=apps_nvram_file.write({"filename":"modify_uniqID_exception","data":err_str.toString(),
async:false,finished:function(){},product_id:"home"});
if(ret!=1)throw "modify_uniqID_exception write error";}catch(e){
console.log("storeExceptionInformation :Error = "+e.message);}
}
var name_info=getDefaultScreenName();
if(name_info.lang){
if(name_info.lang!=lang){
var default_name_list=name_info.lt_name.map(function(lt){return LANG(lt);});
var name_chg_flg=false;
for(var i=0;i<SCREEN_ORDER.length;i++){
for(var j=0;j<name_info.name.length;j++){
if(SCREEN_INFO[i].screen_name.indexOf(name_info.name[j])>=0){
if(!isString(name_info.name[j])||name_info.name[j].length==0)continue;
if(!isString(default_name_list[j])||default_name_list[j].length==0)continue;
var name_str=
SCREEN_INFO[i].screen_name.replace(name_info.name[j],default_name_list[j].toString());
SCREEN_INFO[i].screen_name=name_str;
name_chg_flg=true;
break;}
}
if(name_chg_flg){
storeScreenInfo(SCREEN_INFO[i],SCREEN_ORDER[i]);
name_chg_flg=false;}
}
storeDefaultScreenName();}
}else{
storeDefaultScreenName();}
try{
var INIT_STYLE=getInitStyle();}catch(e){
console.log("Error = "+e.message);}
var _operator=new container({});
var startup=new container({
visible_p:false,
components:[
new gbox({width:1920*4,height:1080*4,color:COL_BASE}),
new gimage({width:1920*4,height:1080*4,color:COL_TEXT_SUB_ONBASE,
src:IMG_PATH+"apps_back_gradation.png",draw_type:DIRECT,blend:true}),
]});
pre_videobox=new container({});
pre_videobox.components=[
new videobox({width:1920,height:1080,translate:[0,0,-9999],overscan:true,color:[255,0,0,0],draw_type:DIRECT})
];
pre_videobox_sub=new container({});
pre_videobox_sub.visible_p=false;
pre_videobox_sub.components=[
new videobox({width:16*21,height:9*21,translate:[0,0,-9999],source:1,overscan:true,color:[255,0,0,0],draw_type:DIRECT})
];
function get_operator(obj){return this.myscreen_op;}
var focus=new Focus();
focus.setSize(1920*2,1080*2);
TOOLBAR_Y=1080*0.5-32+3;
var toolbar=new Toolbar(function(translate,size,alpha,speed,func){
var my_translate=[translate[0],translate[1]+TOOLBAR_Y,translate[2]];
focus.moveTo(my_translate,size,alpha,speed,func);});
AnimationGraphics.apply(toolbar);
function loading_circle_item(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.width=param.width?param.width:100;
this.height=param.height?param.height:100;
this.visible_p=false;
this.loading=new gimage({rotation:[0,0,0,1],
width:this.width,height:this.height,
src:IMG_PATH+"loading_circle.png",});
this.components.push(this.loading);}
loading_circle_item.prototype.init=function(param){
this.translate=param.translate?param.translate:this.translate;
this.width=param.width?param.width:this.width;
this.height=param.height?param.height:this.height;
this.loading.width=this.width;
this.loading.height=this.height;
delete_timer(this);
this.visible_p=false;
this.loading.rotation=[0,0,0,1];}
loading_circle_item.prototype.destroy=function(){
this.loading.src="";
this.components.splice(0,this.components.length);}
loading_circle_item.prototype.setShow=function(bool){
var obj=this;
if(bool==true){
delete_timer(obj);
obj.visible_p=true;
append_timer(obj,100,function(obj,count){
obj.loading.rotation[0]=-(30*count)%360;
force_redraw();});}else{
delete_timer(obj);
obj.visible_p=false;
obj.loading.rotation=[0,0,0,1];}
}
function createPowerOnScreen(){
var first_screen=null;
try{
SCREEN_ORDER=getScreenOrder();
POWERON_SCREEN=getPowerOnScreen();
if(isScreenKey(boot_screen))POWERON_SCREEN=boot_screen;
if(SCREEN_ORDER.indexOf(POWERON_SCREEN)==-1){
POWERON_SCREEN=checkPowerOnScreen(SCREEN_ORDER);}
SCREEN_INFO[POWERON_SCREEN]=getScreenInfo(POWERON_SCREEN);
SCREEN_USER_MAX_NUM=SCREEN_FIXED_NUM+SCREEN_USER_ADD_NUM;
HOME_SOUND_MUTE=getSoundMute();}catch(e){
console.log("Screen Info Init Error : Error = "+e.message);}
var screen_obj=SCREEN_INFO[POWERON_SCREEN];

first_screen=getNewScreen(screen_obj,POWERON_SCREEN,true);
if(!is_power_on_netflix){
first_screen.createGadgets();}

setCurProfId(SCREEN_INFO[POWERON_SCREEN].usrprof_id);
return first_screen;}
function init_stage(){
if(this._operator.components.length==0){

this.myscreen_op=null;
this.editscreen_op=null;
this.switchscreen_op=null;
this.voicecontrol_op=null;

initMyScreenOperator(focus,toolbar);

this.operator=get_operator();
this.operator.init();
uninstallGadgets();
this.focus_status="normal";
createInitialBookmark();
this._active_screen=createPowerOnScreen();
var enable_screen=[null,this._active_screen,null];
this.operator.in_hook(enable_screen);

setHomeEventStatus(false);}else {
var active_screen=this.operator.getActiveScreen();
this._active_screen=active_screen[1];
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
active_screen[i].createGadgets(null,true);}
}
if(isActiveStatus()){
if(!loader.visible_p)
HomeSoundPlay("cancel");}
}
this.cursor=this.operator;
if(isActiveStatus()){
if(this._active_screen instanceof Screen)this._active_screen.activate(true);}
}
function createInitialBookmark(){
try{

apps_nvram_file.read({"filename":"Bookmark",async:false,
finished:function(){},product_id:"home"});}catch(e){


require("initial_bookmark");
initial_bookmark.createInitialBookmark();};}
function initMyScreenOperator(focus,toolbar){
if(this.myscree_op)return;
this.myscreen_op=new Operator(focus,toolbar,function(_active_screen,pos){
return getScreen(_active_screen,pos);},function(){},function(operator,next_ui){
switchUI(operator,next_ui);},
null,null,null,null,null,
function(screen_id){
storePowerOnScreen(screen_id);},
function(){
return getPowerOnSelect();},
function(select){
storePowerOnSelect(select);},
null,
function(bool){
setHomeEventStatus(bool);});
_operator.components.push(this.myscreen_op);
HOME.components.unshift(this.myscreen_op);
this.myscreen_op.cursor=null;
var me=this.myscreen_op;
me.screen=[{},{},{}];me._active_screen=[null,null,null];
me._margin=0;
me._angle=46;
me._side_x_pos=1920*1.4;
me._size_z_pos=-1920*1.4;
me.focus_timer={};
me.is_move=false;
me._point=null;
me.init=function (){
me.toolbar.setTranslate(0,TOOLBAR_Y,0);}
me.in_hook=function (enable_screen){
if(!enable_screen)return;
me.is_move=true;
var zbuf=[1,0,2];
for(var i=0;i<3;i++){
if(enable_screen[zbuf[i]]&&(me.components.indexOf(enable_screen[zbuf[i]])==-1)){
me._active_screen[zbuf[i]]=enable_screen[zbuf[i]];
me.screen[zbuf[i]]=enable_screen[zbuf[i]];
me.components.unshift(me.screen[zbuf[i]]);}else {
if(!enable_screen[zbuf[i]])me.screen[zbuf[i]]=null;}
}
me.toolbar.setTranslate(0,TOOLBAR_Y,0);

me.visible_p=true;
me.toolbar.visible_p=true;

if(me.screen[0] instanceof Screen){
me.screen[0].moveTo([-me._side_x_pos,0,0],
[0,0],me._angle,20,function(){
me.screen[0].activate(false);
me.screen[0].setShow(false);
me.screen[0].setEdgeMask(false);});}
if((me.screen[2] instanceof Screen)){
me.screen[2].moveTo([me._side_x_pos,0,0],
[0,0],-me._angle,20,function(){
me.screen[2].activate(false);
me.screen[2].setShow(false);
me.screen[2].setEdgeMask(false);});}

me.screen[1].setShow(true);
me.screen[1].activate(false);
me.screen[1].setEdgeMask(false);
me.screen[1].moveTo([0,0,0],[1920,1080],0,20,function(){
me.screen[1].setFullscreen(true);
var screen_key=me.screen[1].getScreenKey();
var info=HOME.getScreenInfo(screen_key);
if(info)setCurProfId(info.usrprof_id);
me.screen[1].setEditMode(false);
me.cursor=me.screen[1];
me.toolbar.setShowButtons(true);
me.focus.setTranslate(0,0,0);
me.focus.setSize(1920*1.5,1080*1.5);
startup_ui.focus_status="slow";
startup_ui.startup.visible_p=false;
VoiceReserve(me.cursor.getScreenName());
me.cursor.onFocus(true);
VoiceCancelReservation();
me.focus.setShow(true);
me._setFocusHide(true,me.focus_timer);
me.toolbar.setSolid(me.screen[1].getTemplateName()=="tv"?true:false);
me.screen[1].activate(true);

append_timer(me,1000,function (obj){
delete_timer(obj);
if(me.screen[0]==null){
me.screen[0]=me.getScreen(me._active_screen,-1);
me._active_screen[0]=me.screen[0];}
if(me.screen[2]==null){
me.screen[2]=me.getScreen(me._active_screen,1);
me._active_screen[2]=me.screen[2];}

if(me.screen[1]){
me.screen[1].activate(true);var screen_key=me.screen[1].getScreenKey();
var current_index=SCREEN_ORDER.indexOf(screen_key);
var temp_name=me.screen[1].getTemplateName();
if(isDLScreen(screen_key)){
var info=HOME.getScreenInfo(screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"activate",pos:current_index.toString(),template:temp_name,});
var prev_index=SCREEN_ORDER.indexOf(LAST_VIEW_SCREEN);
if((prev_index!=-1)&&(prev_index.toString()!=current_index.toString())){
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"switch",pos:current_index.toString(),
template:temp_name,from:prev_index.toString(),});}
}
me._storeLastScreen();
me.is_move=false;
me.setHomeEventStatus(false);
try{
prepareHomeBrowser();}catch(e){
console.log("## perpareHomeBrowser Error = "+e.message);};});});

me.toolbar.setScreenName(me.screen[1].getScreenName());
var menu=
[
{title:LANG("LT_HOME_SCREEN_SELECTION"),
voice:VOICE("LT_HOME_SCREEN_SELECTION"),
action:function(){me.switchUI(me,SWITCH_SCREEN);},
image:HOME_KEY,},
{title:LANG("LT_HOME_APPS"),
voice:VOICE("LT_HOME_APPS"),
action:function(){
if(system.mdl_cfg.apps_context==system.mdl_cfg.APPS_CONTEXT_SURFER){
discard_stage("apps");
add_stage_load_path("apps",PATH+"apps.js");
on_stage("apps");}else {
system.apps.launch_apps();}
},
image:APPS_KEY,},
{title:LANG("LT_HOME_SEARCH"),
voice:VOICE("LT_HOME_SEARCH"),
action:function(){
on_stage("search");
append_timer({},500,function(obj){
delete_timer(obj);
HOME.HomeSoundPlay("enter");});},
},
{title:LANG("LT_HOME_MESSAGES"),
voice:VOICE("LT_HOME_MESSAGES"),
action:function(){
on_stage("message");
append_timer({},500,function(obj){
delete_timer(obj);
HOME.HomeSoundPlay("enter");});},
},
{title:LANG("LT_HOME_TUTORIAL"),
voice:VOICE("LT_HOME_TUTORIAL"),
action:function(){
HOME.HomeSoundPlay("enter");
system.guidance.launch_request(system.guidance.LAUNCH_USER_HOMESCREEN);},
},
{title:LANG("LT_HOME_SETTINGS"),
voice:VOICE("LT_HOME_SETTINGS"),
action:function(){
switchUI(me,EDIT_SCREEN);},
}
];
if(SU_IS_GBL15){
menu.splice(2,2,null,menu[2]);}
me.toolbar.editButtons.apply(me.toolbar,menu);

if(system.mdl_cfg.with_smart_lock==true
&&system.mdl_cfg.is_smart_lock==true){
if(system.mdl_cfg.settings_lock==true){
me.toolbar.btn_list[5].setEnable(false);
me.toolbar.btn_list[5].setAction(null);
me.toolbar.btn_list[5].setVoice("");}
if(system.mdl_cfg.hs_lock==true){
me.toolbar.btn_list[0].setEnable(false);
me.toolbar.btn_list[0].setAction(null);
me.toolbar.btn_list[0].setVoice("");
me.toolbar.btn_list[4].setEnable(false);
me.toolbar.btn_list[4].setAction(null);
me.toolbar.btn_list[4].setVoice("");}
if(system.mdl_cfg.apps_lock==true){
me.toolbar.btn_list[1].setEnable(false);
me.toolbar.btn_list[1].setAction(null);
me.toolbar.btn_list[1].setVoice("");}
}
}
me.out_hook=function (){
me.visible_p=false;
if(me.screen[1] instanceof Screen)
me.screen[1].onFocus(false);
me._setFocusHide(false,me.focus_timer);
me.focus.setShow(false);
me.toolbar.setSolid(false);
me.toolbar.visible_p=false;
startup_ui.startup.visible_p=true;
var my_length=me.components.length;
var index=0;
for(var i=0;i<my_length;i++){
if((me.components[index] instanceof Screen)){
me.components.splice(index,1);}else {
index++;}
}
return [me.screen[0],me.screen[1],me.screen[2]];}
me.key_hook=function (up_down,key){
if(me.is_move==true)return false;

if(up_down==KEY_PRESS){
if(me.focus.getAlpha()!=255){
me._setFocusHide(false,me.focus_timer);
me._setFocusHide(true,me.focus_timer);
return true;}else {
me._setFocusHide(true,me.focus_timer);}
}

if(me.cursor&&me.cursor.key_hook
&&me.cursor.key_hook(up_down,key)){
return true;}
if(!SU_SUPPORT_MYHOMESCREEN)return false;
if(up_down!=KEY_PRESS)return true;
switch(key){
case TXK_UP:
if(me.cursor instanceof Screen){
if(me.cursor.getUnlockStatus()==true)return true;
me.cursor.onFocus(false,key);
me.cursor=me.toolbar;
me.cursor.onFocus(true,key);
return true;}
break;
case TXK_DOWN:
if(me.cursor instanceof Toolbar){
me.cursor.onFocus(false,key);
me.cursor=me.screen[1];
me.cursor.onFocus(true,key);
return true;}
break;
case TXK_HOME:
if(system.mdl_cfg.with_smart_lock
&&system.mdl_cfg.is_smart_lock
&&system.mdl_cfg.hs_lock){
return true;}
if(me.cursor instanceof Confirmpanel)me.cursor.closeAction();
me.switchUI(me,SWITCH_SCREEN);
return true;
break;}
return false;}
me.point_hook=function (type,id,x,y,screenX,screenY){
return false;}
me._setFocusHide=function (bool,timer){
return false;
if(bool==true){
delete_timer(timer);
append_timer(timer,3000,function(timer){
delete_timer(timer);
me.focus.transparentTo(0,1000,function(){
me.focus.setShow(false);});});}else {
delete_timer(timer);
me.focus.setAlpha(255);
me.focus.setShow(true);
force_redraw();}
}
me._storeLastScreen=function (){
var pon_select=null;
try{
pon_select=me.getPowerOnSelect();}catch(e){
console.log("## Error = "+e.message);}
var screen_id=me._active_screen[1].getScreenKey();
LAST_VIEW_SCREEN=screen_id;
if(pon_select=="last"){
me.storePowerOnScreen(screen_id);}
}
me.isTVGadget=function(){
if(this.cursor instanceof Screen){
return this.cursor.isTVGadget();}
return false;}
me.focusNoTVGadget=function(){
var active_screen=this.getActiveScreen();
if(active_screen[1] instanceof Screen){
this.cursor.onFocus(false);
this.cursor=active_screen[1];
active_screen[1].focusNoTVGadget();
this.cursor.onFocus(true);}
}
}
function initSwitchScreenOperator(focus,toolbar){
if(this.switchscreen_op)return;
this.switchscreen_op=new Operator(
focus,toolbar,getScreen,
storeScreenInfo,switchUI,getScreenInfo,
addNewScreen,deleteScreen,getScreenOrder,
getPowerOnScreen,storePowerOnScreen,
getPowerOnSelect,storePowerOnSelect,
getVanishProductIDs,
setHomeEventStatus
);
require("startup_selection");
_operator.components.push(this.switchscreen_op);
HOME.components.unshift(this.switchscreen_op);
this.switchscreen_op.cursor=null;
this.switchscreen_op.init();}
function initVoiceControlOperator(focus,toolbar){
if(this.voicecontrol_op)return;
initSwitchScreenOperator(focus,toolbar);
require("startup_voice_control");
this.voicecontrol_op=new startup_voice_control.voice_control({});
_operator.components.push(this.voicecontrol_op);
HOME.components.unshift(this.voicecontrol_op);
this.voicecontrol_op.cursor=null;
this.voicecontrol_op.init();}
function initEditScreenOperator(focus,toolbar){
if(this.editscreen_op)return;
this.editscreen_op=new Operator(
focus,toolbar,NULL_FUNCTION,
storeScreenInfo,switchUI,getScreenInfo,
null,null,getScreenOrder,
getPowerOnScreen,storePowerOnScreen,
getPowerOnSelect,storePowerOnSelect,
getVanishProductIDs,
setHomeEventStatus,getUniqID
);
_operator.components.push(this.editscreen_op);
HOME.components.unshift(this.editscreen_op);
this.editscreen_op.cursor=null;
this.editscreen_op.loading_circle=new loading_circle_item({width:100,height:100,
translate:[1920/2-(1920-460)/2,0,0],});
this.editscreen_op.exitTask=function(){
this.loading_circle.setShow(false);
background_anim.setShow(false);}
try{
test_load(PATH+"startup_settings.js");}catch(e){
console.log("Error = "+e.message);}
this.editscreen_op.init();};
function getScreen(_active_screen,pos){
var _screen=null;
var current_index=null;
var new_index=null;
var screen_info=null;
var screen_key=_active_screen[1].getScreenKey();
current_index=SCREEN_ORDER.indexOf(screen_key);
new_index=current_index+pos;
if(SCREEN_ORDER.length!=1
&&(current_index+pos>-1)&&(current_index+pos<SCREEN_ORDER.length)){
var screen_info=getScreenInfo(SCREEN_ORDER[new_index]);
_screen=getNewScreen(screen_info,SCREEN_ORDER[new_index]);
return _screen;}else if(current_index+pos==SCREEN_ORDER.length){
return null;}
return _screen;}
function changeOperator(prev_op,next_op,func){
this.cursor=next_op;
var enable_screen=prev_op.out_hook();
prev_op.clearScreenInstance();
this.last_operator=this.operator;
this.operator=next_op;

next_op.in_hook(enable_screen,func);}
function getNewScreen(screen_info,screen_key,isPowerOn){
var screen_template=get_screen_template(screen_info);
var new_screen=new screen_template(
screen_key,
screen_info.uniq_id_list,
function(translate,size,angle,speed,func){
if(startup_ui.focus_status=="slow"){
focus.moveTo(translate,size,angle,8,function(){
startup_ui.focus_status="normal";
if(func)func()});}else {
focus.moveTo(translate,size,angle,speed,func);}
},isPowerOn);
if(isDLScreen(screen_info.template))
new_screen.setTemplateName(screen_info.template);
if(screen_info.debug_mode===true&&screen_info.debug_gadget_list!==undefined)
new_screen.$setDebugGadgetList(screen_info.debug_gadget_list);
AnimationGraphics.apply(new_screen);
new_screen.rotation=[0,0,1,0];new_screen.width=0;new_screen.height=0;
try{
var lang_list=screen_info.screen_name_lang;
var name=encodeURIComponent(screen_info.screen_name);
var update=false;
if(lang_list){
for(var id in lang_list){
update|=(lang_list[id]==name);}
}
if(screen_info.screen_name_lang===undefined||!update){
new_screen.setScreenName(screen_info.screen_name);}else{
var tmplang=lang_list[system.locale.language.substr(0,5)];
if(isString(tmplang)){
screen_info.screen_name=decodeURIComponent(tmplang);
storeScreenInfo(screen_info,screen_key);}else{
var tmplang=lang_list[system.locale.language.substr(0,2)];
if(isString(tmplang)){
screen_info.screen_name=decodeURIComponent(tmplang);
storeScreenInfo(screen_info,screen_key);}else{
var tmplang=lang_list["default"];
if(isString(tmplang)){
screen_info.screen_name=decodeURIComponent(tmplang);
storeScreenInfo(screen_info,screen_key);}
}
}
}
}catch(e){
console.log("cannot change screen_name."+e.message);};
new_screen.setScreenName(screen_info.screen_name);
new_screen.setWallPaper(screen_info.wallpaper);
var screen_status={"removable":screen_info.removable,
"editable":screen_info.editable};
new_screen.setScreenStatus(screen_status);
new_screen.activate(false);
return new_screen;}
function storeScreenInfo(info,key){
var s_id="id:\""+(info.id||"").toString()+"\",";
var s_org_id="org_id:\""+(info.org_id||"").toString()+"\",";
var s_screenname="screen_name:\""+encodeURIComponent(info.screen_name.toString())+"\",";
var s_wallpaper="wallpaper:\""+(info.wallpaper||"").toString()+"\",";
var s_usrprof_id="usrprof_id:"+(isNumber(info.usrprof_id)?info.usrprof_id:"null")+",";
var s_template="template:\""+info.template.toString()+"\",";
var s_install_type="install_type:\""+(info.install_type||"").toString()+"\",";
var s_product_id_list="product_id_list:[";
var len=info.product_id_list.length;
for(var i=0;i<len;i++){
s_product_id_list=s_product_id_list+"\""+
info.product_id_list[i].toString()+"\",";}
s_product_id_list=s_product_id_list+"],";
var s_uniq_id_list="uniq_id_list:[";
var ulen=info.uniq_id_list.length;
for(var i=0;i<ulen;i++){
s_uniq_id_list=s_uniq_id_list+"\""+
info.uniq_id_list[i].toString()+"\",";}
s_uniq_id_list=s_uniq_id_list+"],";
var s_debug_mode="";
var s_debug_screen_path="";
var s_debug_gadget_list="";
if(info.debug_mode===true||info.debug_mode===false){
s_debug_mode="debug_mode:"+info.debug_mode.toString()+",";}
if(isString(info.debug_screen_path)){
s_debug_screen_path="debug_screen_path:\""+info.debug_screen_path+"\",";}
if(info.debug_gadget_list!==undefined){
s_debug_gadget_list="debug_gadget_list:{";
for(var pid in info.debug_gadget_list){
s_debug_gadget_list+="\""+pid+"\":\""+info.debug_gadget_list[pid]+"\",";}
s_debug_gadget_list+="},";}
var s_screen_name_lang="";
if(info.screen_name_lang!==undefined){
s_screen_name_lang="screen_name_lang:{";
for(var name in info.screen_name_lang){
s_screen_name_lang+="\""+name+"\":\""+info.screen_name_lang[name]+"\",";}
s_screen_name_lang+="},";}

var s_removable="removable:"+(info.removable===true).toString()+",";
var s_editable="editable:"+(info.editable!==false).toString()+",";
var s_screen_info="{"+s_id+s_org_id+s_screenname+s_wallpaper+s_usrprof_id+s_template+
s_install_type+
s_screen_name_lang+
s_product_id_list+s_uniq_id_list+s_removable+s_editable+
s_debug_mode+s_debug_screen_path+s_debug_gadget_list+"}";
if(isDLScreenKey(key)){
return storeDLScreenInfo(s_screen_info,key);}else{
return storeDefaultScreenInfo(s_screen_info,key);}
}
function storeDLScreenInfo(s_screen_info,key){
var screen_id=getScreenInstallId(key);
try{
var tmp=screen_nvram_file.read({filename:"screen",screen_id:screen_id});}catch(e){
return false;}
try{
if(sysutil.tconv.binary_to_string(tmp)==s_screen_info.toString())
return true;}catch(e){}
try{
screen_nvram_file.write({filename:"screen",data:s_screen_info.toString(),
screen_id:screen_id,});}catch(e){
console.log(" nvram cannot write screen_info: Error = "+e.message);
return false;};
return true;}
function storeDefaultScreenInfo(s_screen_info,key){
var key="screen"+key.toString();
try{
var tmp=apps_nvram_file.read({filename:key.toString(),product_id:"home",});
if(sysutil.tconv.binary_to_string(tmp)==s_screen_info.toString())
return true;}catch(e){}
try{
apps_nvram_file.write({filename:key.toString(),data:s_screen_info.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write screen_info: Error = "+e.message);
return false;};
return true;}
function getFullTVScreen(){
var order=getScreenOrder();
for(var i=0;i<order.length;i++){
if(isDLScreenKey(order[i]))continue;
var info=getScreenInfo(order[i]);
if(info.template=="tv"){
return order[i];}
}
return getPowerOnScreen();}
function getScreenInfo(key){
if(!isScreenKey(key))return null;
if(isDLScreenKey(key)){
return getDLScreenInfo(key);}else{
return getDefaultScreenInfo(key);}
}
function getDLScreenInfo(key){
var ret=null;
try{
var screen_id=getScreenInstallId(key);
ret=screen_nvram_file.read({"screen_id":screen_id,"filename":"screen"});
if(ret instanceof Binary)ret=sysutil.tconv.binary_to_string(ret);
ret=eval("("+ret+")");
ret.screen_name=decodeURIComponent(ret.screen_name);
if(!ret.id)ret.id="";
if(!ret.org_id)ret.org_id="";
if(ret.debug_mode===true&&isString(ret.debug_screen_path)){
ret.wallpaper=ret.debug_screen_path+"/wallpaper.jpg";}else if(isString(ret.wallpaper)&&ret.wallpaper.match("^http")){
ret.wallpaper=SCREEN_PATH+ret.id+"/wallpaper.jpg";}
if(ret.editable===undefined)
ret.editable=true;
if(ret.usrprof_id===undefined)
ret.usrprof_id=null;
ret.screen_install_id=screen_id;}catch(e){
ret={screen_name:LANG("LT_HOME_DL_DOWNLODING"),wallpaper:DEFAULT_SCREEN_WALLPAPER,template:"inst",
screen_install_id:"",id:"",
product_id_list:[TV_GADGET],
uniq_id_list:[TV_GADGET+"0009"],
removable:false,editable:true};}
return ret;}
function getDefaultScreenInfo(key){
var s_key="screen"+key.toString();
var ret=null;
try{
ret=apps_nvram_file.read({filename:s_key.toString(),async:false,
finished:function(){},product_id:"home",});
ret=sysutil.tconv.binary_to_string(ret);
ret=ret.replace(/,wallpaper:([^"]+),/g,",wallpaper:\"$1\"");
ret=eval("("+ret+")");
ret.screen_name=decodeURIComponent(ret.screen_name);
if(!ret.id)ret.id="";
if(!ret.org_id)ret.org_id="";
if(!isString(ret.wallpaper)||ret.wallpaper==""||ret.wallpaper=="null")
ret.wallpaper=DEFAULT_SCREEN_WALLPAPER;
if(ret.editable===undefined)
ret.editable=true;
if(ret.usrprof_id===undefined)
ret.usrprof_id=null;
ret.screen_install_id="";
if(ret.template=="tv")
ret.removable=false;}catch(e){
console.log(" nvram cannot read screen_info: Error = "+e.message);
ret={screen_name:"",wallpaper:"",template:"tv",id:"",
screen_install_id:"",
product_id_list:[TV_GADGET],
uniq_id_list:[TV_GADGET+"0000"],
removable:false,editable:true};}
return ret;}
function clearScreenInfo(key){
if(isDLScreenKey(key)){
return clearDLScreenInfo(key);}else{
return clearDefaultScreenInfo(key);}
}
function clearDLScreenInfo(key){
var screen_id=key;
try{
screen_id=getScreenInstallId(key);}catch(e){}
try{
screen_nvram_file.remove({filename:"screen",screen_id:screen_id});}catch(e){
console.log(" nvram cannot remove screen_info: Error = "+e.message);}
}
function clearDefaultScreenInfo(key){
var s_key="screen"+key.toString();
try{
apps_nvram_file.remove({filename:s_key.toString(),async:false,
finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot remove screen_info: Error = "+e.message);}
}
function clearUserBackground(file_name){
try{
apps_nvram_file.remove({filename:file_name,async:false,
finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot remove screen_info: Error = "+e.message);}
}
function storeScreenOrder(order){
var s_order="[";
var len=order.length;
var quot=false;
for(var i=0;i<len;i++){
quot=(isString(order[i]))?'"':'';
s_order=s_order+quot+order[i].toString()+quot+",";}
s_order=s_order+"]";
var old=null;
try{
old=apps_nvram_file.read({filename:"order",product_id:"home"});}catch(e){};
if(old==s_order)
return;
try{
apps_nvram_file.write({filename:"order",data:s_order,
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write order: Error = "+e.message);
return;};
_cache_screen_order=s_order;}
function getScreenOrder(){
var ret=null;

try{
return eval(_cache_screen_order);}catch(e){
_cache_screen_order=null;}
try{
ret=apps_nvram_file.read({filename:"order",async:false,finished:function(){},
product_id:"home",});
ret=eval(sysutil.tconv.binary_to_string(ret));}catch(e){
console.log(" nvram cannot read order: Error = "+e.message);
ret=[0,1,];}
_cache_screen_order=ret;
return ret;}
function storePowerOnScreen(screen_id){
try{
apps_nvram_file.write({filename:"poweron",data:screen_id.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write poweron: Error = "+e.message);};
var fulltv=0;
try{
var screen_info=getScreenInfo(screen_id);
if(screen_info.template=="tv")
fulltv=1;
apps_nvram_file.write({filename:"startup_fulltv",data:fulltv.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write adv_banner: Error = "+e.message);};}
function getPowerOnScreen(){
if(!SU_SUPPORT_MYHOMESCREEN)
return "0";
var ret=null;
try{
ret=apps_nvram_file.read({filename:"poweron",async:false,finished:function(){},
product_id:"home",});
ret=sysutil.tconv.binary_to_string(ret);}catch(e){
console.log(" nvram cannot read poweron: Error = "+e.message);
ret="0";}
if(!isDLScreenKey(ret))
ret=parseInt(ret);
return ret;}
function checkPowerOnScreen(screen_order){
var poweron_screen=0;
if(screen_order[0]!=null){
poweron_screen=screen_order[0];}else{
for(var i=1;i<screen_order.length;i++){
if(screen_order[i]!=null){
poweron_screen=screen_order[i];
break;}
}
}
if(SCREEN_ORDER.indexOf(poweron_screen)==-1)
poweron_screen=SCREEN_ORDER[1];
storePowerOnScreen(poweron_screen);
return poweron_screen;}
function storePowerOnSelect(selection){
try{
apps_nvram_file.write({filename:"pon_select",data:selection.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write poweron select: Error = "+e.message);};}
function getPowerOnSelect(){
var ret=null;
try{
ret=apps_nvram_file.read({filename:"pon_select",async:false,finished:function(){},
product_id:"home",});
ret=sysutil.tconv.binary_to_string(ret);}catch(e){
console.log(" nvram cannot read pon_select: Error = "+e.message);
ret="last";};
return ret;}
function storeInitStyle(style){
var ret=null;
try{
ret=apps_nvram_file.read({filename:"init_style",product_id:"home",});
ret=eval("("+sysutil.tconv.binary_to_string(ret)+")");
if(ret.zapping){
return;}
}catch(e){}
if(ret&&style&&ret.zapping==style.zapping)
return;
var s_style="{zapping:";
s_style+=style.zapping.toString()+",}";
try{
apps_nvram_file.write({filename:"init_style",data:s_style.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write init_style: Error ="+e.message);}
}
function getInitStyle(){
var ret=null;
try{
ret=apps_nvram_file.read({filename:"init_style",async:false,finished:function(){},
product_id:"home",});
ret=eval("("+sysutil.tconv.binary_to_string(ret)+")");
if(!ret)ret={zapping:false,};}catch(e){
console.log(" nvram cannot read init_style: Error = "+e.message);
ret={zapping:false,};};
return ret;}
function storeSoundMute(bool){
try{
apps_nvram.write("sound_mute",bool.toString(),"home");
system.effect_sound.mute=bool;
nvram_file.write({"filename":"system_sound_mute","data":bool.toString()});}catch(e){
console.log(" nvram cannot write sound_mute: Error = "+e.message);}
}
function getSoundMute(){
var ret=null;
try{
ret=apps_nvram.read("sound_mute","home");
ret=eval(ret);
if(ret==null)ret=false;
system.effect_sound.mute=ret;
nvram_file.write({"filename":"system_sound_mute","data":ret.toString()});}catch(e){
console.log(" nvram cannot write sound_mute: Error = "+e.message);
ret=false;system.effect_sound.mute=ret;}
return ret;}
function storePONCheck(){
try{
apps_nvram.write("poweron_check","true","home");}catch(e){
console.log(" nvram cannot write poweron_check: Error = "+e.message);}
}
function getVanishProductIDs(my_product_id_list,key){
var vanished_id_list=[];
var screen_order=getScreenOrder();
var screen_num=screen_order.length;
var id_num=my_product_id_list.length;
var screen_info=[];
for(var i=0;i<screen_num;i++){
screen_info[i]=getScreenInfo(screen_order[i]);}
for(var i=0;i<id_num;i++){
var ret=true;
for(var j=0;j<screen_num;j++){
if(screen_order[j].toString()!=key.toString()){
if(my_product_id_list[i]!=""&&
screen_info[j].product_id_list.indexOf(my_product_id_list[i])==-1){
}else {
ret=false;}
}else {
if(id_num==1&&my_product_id_list[i]!=""&&
screen_info[j].product_id_list.indexOf(my_product_id_list[i])!=-1){
var index=screen_info[j].product_id_list.indexOf(my_product_id_list[i]);
screen_info[j].product_id_list.splice(index,1);
if(screen_info[j].product_id_list.indexOf(my_product_id_list[i])==-1){
}else {
ret=false;}
}
}
}
if(ret==true)vanished_id_list.push(my_product_id_list[i]);}
return vanished_id_list;}
function storeDefaultScreenName(){
var default_name_list=screen_name_list.map(function(lt){return LANG(lt);});
var name="name:"+JSON.stringify(default_name_list)+",";
name+="lt_name:"+JSON.stringify(screen_name_list)+",";
var language="lang:\""+lang.toString()+"\"";
var tmp="{"+name+language+"}";
try{
apps_nvram_file.write({filename:"default_screen_name",data:tmp.toString(),
async:false,finished:function(){},product_id:"home",});}catch(e){
console.log(" nvram cannot write default_screen_name: Error = "+e.message);};}
function getDefaultScreenName(){
var ret=null;
try{
ret=apps_nvram_file.read({filename:"default_screen_name",async:false,
finished:function(){},product_id:"home",});
ret=eval("("+sysutil.tconv.binary_to_string(ret)+")");}catch(e){
console.log(" nvram cannot read default_screen_name: Error = "+e.message);
ret={name:[],lang:""};}
if(!ret.lt_name){
ret.lt_name=["LT_HOME_FULL_TV","LT_HOME_TV",
"LT_HOME_LIFESTYLE","LT_HOME_INFO",
"LT_HOME_MY_HOME_SCREEN"];}
return ret;}
function qsort(a){
if(a.length<=1)return a;
else {
var p=a.pop();
var s=[];
var l=[];
for(i in a){
if(a[i]<p){
s.push(a[i]);}else {
l.push(a[i]);}
}
s=qsort(s);
s.push(p);
a.push(p);
return s.concat(qsort(l));}
}
function searchSpaceNumForOrder(order){
if(order instanceof Array){
var len=order.length;
var index=0;
var tmp=[];
for(var i=0;i<len;i++)
tmp[getFaceScreenKey(order[i])]=true;
while(index<len+3){
if(tmp[index.toString()]!==undefined){
index++;}else {
break;}
}
return index;}else {
return 0;}
}
function searchSpaceNumForUniqID(order){
if(order instanceof Array){
var len=order.length;
var index=0;
while(index<10000){
if(order[index]==index){
index++;}else {
break;}
}
return index;}else {
return 0;}
}
function getUniqID(add_product_id){
var screen_order=getScreenOrder();
var screen_info=[];
var uniq_ids=[];
var key=[];
var order_num=screen_order.length;
for(var i=0;i<order_num;i++){
screen_info[i]=getScreenInfo(screen_order[i]);
while(1){
var index=screen_info[i].product_id_list.indexOf(add_product_id);
if(index!=-1){
key.push((screen_info[i].uniq_id_list[index].substr(16,4)),10);
uniq_ids.push(screen_info[i].uniq_id_list[index]);
screen_info[i].product_id_list.splice(index,1);
screen_info[i].uniq_id_list.splice(index,1);}else {
break;}
}
}
var add_uniq_id=add_product_id;
var tmp=[];
tmp=qsort(key);
var vacant_key=searchSpaceNumForUniqID(tmp);
var ziro_num=4-vacant_key.toString().length;
for(var i=0;i<ziro_num;i++){
add_uniq_id=add_uniq_id.toString()+"0";}
add_uniq_id=add_uniq_id.toString()+vacant_key.toString();
return add_uniq_id;}
function getUniqIDs(product_id_list){
var screen_order=getScreenOrder();
var order_num=screen_order.length;
var uniq_id_map={};
var uniq_id_list=[];
var ulen,uniq_id;
for(var i=0;i<order_num;i++)
{
var screen_info=getScreenInfo(screen_order[i]);
var uniq_id=screen_info.uniq_id_list||[];
var len=uniq_id.length;
for(var j=0;j<len;j++)
{
var pid=uniq_id[j].substr(0,16);
var uniq=parseInt(uniq_id[j].substr(16,4),10);
if(!uniq_id_map[pid])
uniq_id_map[pid]=[];
uniq_id_map[pid][uniq]=uniq;}
}
var len;
len=product_id_list.length;
for(var i=0;i<len;i++){
if(!(isString(product_id_list[i])&&product_id_list[i].length==16)){
uniq_id_list[i]="";
continue;}
var pid=product_id_list[i].substr(0,16);

var vacant_key=searchSpaceNumForUniqID(uniq_id_map[pid]);
uniq_id_list[i]=pid+("0000"+vacant_key).substr(-4,4);
if(!uniq_id_map[pid])
uniq_id_map[pid]=[];
uniq_id_map[pid][vacant_key]=vacant_key;}
return uniq_id_list;}
function gcHome(){
var tmporder=[];
var order=getScreenOrder();
var list=apps_nvram_file.list({product_id:"home"});
var len=order.length;
for(var i=0;i<order.length;i++){
var key=order[i];
if(isString(key)){
tmporder.push(key);}else if(isNumber(key)){
if(list&&list.indexOf("screen"+key)!=-1)
tmporder.push(key);}
}

if(tmporder.length<1)
tmporder=[0];
storeScreenOrder(tmporder);}
function addNewScreen(template_id,add_index){
SCREEN_ORDER=getScreenOrder();
var vacant_key=searchSpaceNumForOrder(SCREEN_ORDER);
var name_list=[];
var new_screen_name=LANG("LT_HOME_MY_HOME_SCREEN");
for(var i=0;i<SCREEN_ORDER.length;i++){
var info=getScreenInfo(SCREEN_ORDER[i]);
name_list.push(info.screen_name);}
for(var index=1;index<name_list.length+1;index++){
var tmp_name=(new_screen_name+index.toString());
if(name_list.indexOf(tmp_name)==-1){
new_screen_name=tmp_name;
break;}
}
var uniq_ids=[];
var my_len=GADGET_TEMPLATE[template_id].length;
for(var i=0;i<my_len;i++){
if(GADGET_TEMPLATE[template_id][i]==""){
uniq_ids[i]="";}else {
uniq_ids[i]=getUniqID(GADGET_TEMPLATE[template_id][i]);}
}
var screen_info={
screen_name:new_screen_name,
wallpaper:DEFAULT_SCREEN_WALLPAPER,
template:template_id.toString(),
product_id_list:GADGET_TEMPLATE[template_id],
uniq_id_list:uniq_ids,
removable:true,
};

var _screen=getNewScreen(screen_info,vacant_key);
storeScreenInfo(screen_info,vacant_key);
if(add_index>=SCREEN_ORDER.length){
SCREEN_ORDER.push(vacant_key);}else{
SCREEN_ORDER.splice(add_index,0,vacant_key);}
storeScreenOrder(SCREEN_ORDER);
return _screen;}
function deleteScreen(screen_key){
var screen_info=getScreenInfo(screen_key);
del_screen_template(screen_info.template);
SCREEN_ORDER=getScreenOrder();
var index=SCREEN_ORDER.indexOf(screen_key);
SCREEN_ORDER.splice(index,1);
storeScreenOrder(SCREEN_ORDER);clearScreenInfo(screen_key);if(isDLScreen(screen_key)){
var screen_id=getScreenInstallId(screen_key);
try{
screen_nvram_file.remove_screen_dir({screen_id:screen_id});
ebus.app_upd.sync();}catch(e){}
}
updateWeblinkTable();}
function switchUI(operator,next_ui,mode){
if(!SU_SUPPORT_MYHOMESCREEN)
return true;
if(operator===HOME.myscreen_op){
if(HOME.switchscreen_op&&
HOME.switchscreen_op._adding_screen==true)
return true;
switch(next_ui){
case EDIT_SCREEN:
UI_MODE=EDIT_SCREEN;
initEditScreenOperator(focus,toolbar);
changeOperator(HOME.myscreen_op,HOME.editscreen_op);
append_timer({},800,function(obj){
delete_timer(obj);
HomeSoundPlay("enter");});
return true;
case SWITCH_SCREEN:
UI_MODE=SWITCH_SCREEN;
initSwitchScreenOperator(focus,toolbar);
changeOperator(HOME.myscreen_op,HOME.switchscreen_op);
HomeSoundPlay(2);
return true;
break;
case VOICE_CONTROL_SCREEN:
UI_MODE=VOICE_CONTROL_SCREEN;
initVoiceControlOperator(focus,toolbar);
changeOperator(HOME.myscreen_op,HOME.voicecontrol_op);
HomeSoundPlay(2);
return true;
break;}
}else if(operator===HOME.switchscreen_op){
switch(next_ui){
case MY_SCREEN:
UI_MODE=MY_SCREEN;
changeOperator(HOME.switchscreen_op,HOME.myscreen_op);
if(HOME.switchscreen_op._adding_screen==true){
var active_screen=HOME.operator.getActiveScreen();
var screen_key=active_screen[1].getScreenKey();
append_timer(HOME,2000,function (obj){
delete_timer(obj);
UI_MODE=EDIT_SCREEN;
initEditScreenOperator(focus,toolbar);
obj.switchscreen_op._adding_screen=false;
changeOperator(obj.myscreen_op,obj.editscreen_op);});}else {
try{
if(HOME.visible_p&&!apputil.getCurrentProductID())
HomeSoundPlay(4);}catch(e){}
}
return true;
case EDIT_SCREEN:
break;
case VOICE_CONTROL_SCREEN:
UI_MODE=VOICE_CONTROL_SCREEN;
initVoiceControlOperator(focus,toolbar);
changeOperator(operator,HOME.voicecontrol_op);
HomeSoundPlay(2);
return true;
break;}
}else if(operator===HOME.editscreen_op){
switch(next_ui){
case MY_SCREEN:
UI_MODE=MY_SCREEN;
changeOperator(HOME.editscreen_op,HOME.myscreen_op);
return true;
case SWITCH_SCREEN:
break;
case VOICE_CONTROL_SCREEN:
UI_MODE=MY_SCREEN;
changeOperator(operator,HOME.myscreen_op);
append_timer(HOME,2000,function(obj){
delete_timer(obj);
var id=HOME.myscreen_op.getUsrprofID();
switchUI(HOME.myscreen_op,VOICE_CONTROL_SCREEN);
HOME.voicecontrol_op.setUsrprofID(id);});
break;}
}else if(operator===HOME.voicecontrol_op){

switch(next_ui){
case MY_SCREEN:
UI_MODE=MY_SCREEN;
changeOperator(operator,HOME.myscreen_op);
break;
case SWITCH_SCREEN:
UI_MODE=SWITCH_SCREEN;
changeOperator(operator,HOME.switchscreen_op);
break;
default:
break;}
}
return false;}
var multiProfile=false;
function isMultiProfile(){
return multiProfile;}
function _initMultiProfile(){
try{
var userprof=system.user_profile.get({"mhc":{}});
if(typeof(userprof.mhc.multiuser_supported)=="boolean")
multiProfile=userprof.mhc.multiuser_supported;}catch(e){}
};
_initMultiProfile();
function getCurProfId(){
if(!isMultiProfile())return 0;var id=null;
try{
var uprofile=system.user_profile.get({"mhc":{id:null}});
var list=system.user_profile.get({"mhc":{}});
if(isNumber(uprofile.mhc.id)&&list.mhc.all.indexOf(uprofile.mhc.id)!=-1)
id=uprofile.mhc.id;}catch(e){}
return id;};
function setCurProfId(usrprof_id){
if(!isMultiProfile())return;
if(isNumber(usrprof_id)){
try{
return system.user_profile.set({mhc:{current_id:usrprof_id}});}catch(e){}
}
try{system.user_profile.set({mhc:{current_id:null}});}catch(e){}
};
function GC_VoiceControlScreen(){
if(!isMultiProfile())return null;
require("startup_voice_control_util");
return startup_voice_control_util.GC_VoiceControlScreen();}
function storeVoiceControlScreen(usrprof_id,screen_key){
if(!isMultiProfile())return null;
require("startup_voice_control_util");
return startup_voice_control_util.storeVoiceControlScreen(usrprof_id,screen_key);}
function getVoiceControlScreen(usrprof_id){
if(!isMultiProfile())return null;
require("startup_voice_control_util");
return startup_voice_control_util.getVoiceControlScreen(usrprof_id);}
GC_VoiceControlScreen();

var jumpScreenTimer={};
function jumpScreen(dest_screen_key,finished_func){
append_timer(jumpScreenTimer,500,function (obj,cnt){
if(cnt>20){
console.log("<< !TimeOut! >>");
console.log("<< !!Reassemble!! >>");
system.reboot(dest_screen_key);
return;}
if(HOME.operator.is_move==true)return;
if(HOME.operator===HOME.editscreen_op){
HOME.operator.key_hook(KEY_PRESS,TXK_HOME);
return;}
if(HOME.operator===HOME.voicecontrol_op){
switchUI(HOME.operator,SWITCH_SCREEN);
return;}
if(HOME.operator===HOME.myscreen_op){
switchUI(HOME.operator,SWITCH_SCREEN);
return;}
if(HOME.operator.getMenuType()!=startup_selection.MENU_SELECT){
HOME.operator.key_hook(KEY_PRESS,TXK_RETURN);
return;}
delete_timer(obj);
var finished=function(){
append_timer({},500,function(obj){delete_timer(obj);
try{
switchUI(HOME.operator,HOME.MY_SCREEN);}catch(e){
console.log("<< !!Reassemble!! >>");
system.reboot(dest_screen_key);}
append_timer(obj,20*40,function(obj2){
delete_timer(obj2);
if(finished_func)finished_func();});});}
try{
HOME.operator.jumpScreen(dest_screen_key,finished);}catch(e){
console.log("<< !!Reassemble!! >>");
system.reboot(dest_screen_key);}
});}
function changeScreen(dest_screen_key){
var active_screen=HOME.operator.getActiveScreen();
var len=active_screen.length;
for(var i=0;i<len;i++){
var screen=active_screen[i];
if(screen instanceof Screen){
delete_timer(screen);
screen.activate(false);
screen.setShow(false);
screen.freeResource(true);
screen.destroyGadgets();
screen.destroy();
active_screen[i]=null;}
}

if(HOME.getPowerOnSelect()=="last")
storePowerOnScreen(dest_screen_key);
if(apputil.getCurrentProductID()!=null){
on_stage("HOME");}
for(var i=0;i<HOME._operator.components.length;i++){
var op=HOME._operator.components[i];
var id=HOME.components.indexOf(op);
if(id!=-1)
HOME.components.splice(id,1);}
HOME._operator.components=[];
boot_screen=dest_screen_key;
init_stage();
boot_screen=null;
complete_on_stage(startup_ui);
force_redraw();};
system.idle={
idle:true,
isIdle:function(){
return this.idle;},
update_count:function(){
this.idle=false;
append_timer(this,1000,function(obj){
delete_timer(obj);
obj.idle=true;});},
};
system.reboot=function (screen_key){
boot_screen=screen_key;
if(!isScreenKey(screen_key)){
boot_screen=null;}
discard_all_stage();
complete_off_stage(HOME);
discard_stage("HOME");
on_stage("HOME");}
var interface2Tutorial={};
interface2Tutorial.getScreenInfo=function (){
var active_screen=HOME.operator.getActiveScreen();
var screen_order=getScreenOrder();
var init_style=getInitStyle();
var screen_key=active_screen[1].getScreenKey();
var screen_info=getScreenInfo(screen_key);
var screen_template=active_screen[1].getTemplateName();
var screen_index=screen_order.indexOf(screen_key);
var tv_screen=screen_info.template=="tv"?true:false;
if(screen_info.template=="xumo")tv_screen=true;
var info={pos:screen_index,name:screen_info.screen_name.toString(),
is_tv:tv_screen,template:screen_template.toString(),
with_zapping:init_style.zapping,};
return info;}
function _changeTemplateScreen(template,anim_type,finished_func){
var order=getScreenOrder();
for(var i=0;i<order.length;i++){
var info=getScreenInfo(order[i]);
if(info.template==template){
switch(anim_type){
case "anim":
jumpScreen(order[i],finished_func);
return true;
case "no anim":
changeScreen(order[i]);
if(finished_func)finished_func();
return true;}
}
}
if(finished_func)
finished_func();
return false;}
function jumpTemplateScreen(template,finished_func){
return _changeTemplateScreen(template,"anim",finished_func);}
function jumpFirstScreen(finished_func){
var order=getScreenOrder();
var target=order[1];
if(!isScreenKey(target))
target=order[0];
jumpScreen(target,finished_func);
return true;}
function focusNoTVGadget(){
HOME.operator.focusNoTVGadget();}
function isTVGadget(){
return HOME.operator.isTVGadget();}
function isTVScreen(){
var active_screen=HOME.operator.getActiveScreen();
if(active_screen[1] instanceof Screen){
return (active_screen[1].getTemplateName()=="tv");}
return false;}
function hasXumoScreen(){
var order=getScreenOrder();
for(var i=0;i<order.length;i++){
var info=getScreenInfo(order[i]);
if(info.template=="xumo"){
return true;}
}
return false;}
function isXumoScreen(){
var active_screen=HOME.operator.getActiveScreen();
if(active_screen[1] instanceof Screen){
return (active_screen[1].getTemplateName()=="xumo");}
return false;}
var setVisibilityForTransit=function(type){
switch(type){
case "normal":
HOME.operator.visible_p=true;
_GLOBAL_.guidance_container.visible_p=false;
break;
case "guidance_only":
HOME.operator.visible_p=false;
_GLOBAL_.guidance_container.visible_p=true;
break;
case "resume":
HOME.operator.visible_p=true;
_GLOBAL_.guidance_container.faraway();
_GLOBAL_.guidance_container.visible_p=true;
break;}
};
function updateHomeLockedFace(){
var active_screen=HOME.operator.getActiveScreen();
active_screen[1].updateLockedFace();}
function backHomeStage(bool){
if(bool==true){
this.translate[2]=-2;}else {
this.translate[2]=0;}
force_redraw();}
function uninstallGadgets(){
var app_list_all=null;
var seeable_app_list=null;
var apps_del_list=[];
try{
var ret=apps_nvram_file.apps_list();
all_app_list=doFilter(ret,new RegExp("^[^\.]+$"));}catch(e){
console.log("all_apps_list is invalid: Error = "+e.message);
return;}
try{
var ret=apps_nvram_file.read({filename:"apps_list",async:false,
finished:function(){},product_id:"home",});
ret=sysutil.tconv.binary_to_string(ret);
seeable_app_list=eval(ret);}catch(e){
console.log("seeable apps_list is invalid: Error = "+e.message);
return;}
try{
var ret=apps_nvram_file.list({product_id:"home"});
apps_del_list=doFilter(ret,new RegExp("^apps_[^\.]+\.del$"));}catch(e){
console.log("apps_del_list is invalid: Error = "+e.message);
return;}
if(!all_app_list||!seeable_app_list||!apps_del_list)return;
var app_list=all_app_list;
var len=apps_del_list.length;
for(var i=0;i<len;i++){
var del_id=apps_del_list[i].match(new RegExp("^apps_([^\.]+)\.del$"));
if(del_id&&del_id.length>1){
if(seeable_app_list.indexOf(del_id[1])==-1){
var id=app_list.indexOf(del_id[1]);
app_list.splice(id,1);}
}
}
var active_screen=HOME.operator.getActiveScreen();
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
active_screen[i].uninstallGadgets(app_list);}
}

var screen_order=getScreenOrder();
var my_len=screen_order.length;
for(var i=0;i<my_len;i++){
var screen_info=getScreenInfo(screen_order[i]);
var id_len=screen_info.product_id_list.length;
for(var j=0;j<id_len;j++){
if((screen_info.product_id_list[j]!="")
&&(app_list.indexOf(screen_info.product_id_list[j])==-1)
&&(screen_info.product_id_list[j]!=TV_GADGET)
&&(screen_info.product_id_list[j]!=ZAPPING_GADGET)
&&(screen_info.product_id_list[j]!=APPS_GADGET)
&&(screen_info.product_id_list[j]!=BOOKMARK_GADGET)
&&(screen_info.product_id_list[j]!=SIGNAGELINK_GADGET)
&&(screen_info.product_id_list[j]!=WEBLINK_GADGET)){
if((screen_info.debug_mode!==true)
||(screen_info.debug_mode===true)
&&screen_info.debug_gadget_list
&&!isString(screen_info.debug_gadget_list[screen_info.product_id_list[j]]))
{
screen_info.product_id_list[j]="";
screen_info.uniq_id_list[j]="";}
}
}
storeScreenInfo(screen_info,screen_order[i]);}
if(HOME.operator===HOME.editscreen_op){
if(HOME.operator.cursor===active_screen[1]){
HOME.operator.edit_option.freeResource(true);
HOME.operator.cursor=HOME.operator.edit_panel;
HOME.operator.edit_panel.selectMenu(false,0);
HOME.operator.cursor.onFocus(true,true);}else if(HOME.operator.cursor===HOME.operator.edit_option){
HOME.operator.edit_option.setShow(false);
HOME.operator.edit_option.freeResource(true);
HOME.operator.cursor=HOME.operator.edit_panel;
HOME.operator.edit_panel.selectMenu(false,0);
HOME.operator.cursor.onFocus(true,true);}else if(HOME.operator.cursor===HOME.operator.add_app_panel){
HOME.operator.add_app_panel.setShow(false);
HOME.operator.edit_option.freeResource(true);
HOME.operator.cursor=HOME.operator.edit_panel;
HOME.operator.edit_panel.selectMenu(false,0);
HOME.operator.cursor.onFocus(true,true);}
}
var len=apps_del_list.length;
for(var i=0;i<len;i++){
try{
apps_nvram_file.remove({filename:apps_del_list[i],product_id:"home"});}catch(e){
console.log("cannot remove \""+apps_del_list[i]+"\" file.");};}
};
function updateWeblinkTable(){
var weblink_data=null;
try{
var tmp=null;
var nvram_file_list=apps_nvram_file.list({product_id:"home"});
if((nvram_file_list)&&(nvram_file_list.indexOf("Weblink_table")!=-1)){
tmp=apps_nvram_file.read({"filename":"Weblink_table",async:false,
finished:function(){},product_id:"home"});}
if(tmp){
tmp=sysutil.tconv.binary_to_string(tmp);
weblink_data=eval(tmp);}else{
weblink_data={};
weblink_data.weblink_table=[];}
}catch(e){
console.log(" nvram_file Weblink_table error :Error = "+e.message);
weblink_data={};
weblink_data.weblink_table=[];}
if(weblink_data.weblink_table.length==0){
return;}
var tmp_weblink_table=[];for(var i=0,max=weblink_data.weblink_table.length;i<max;i++){
if(checkWeblinkCount(WEBLINK_GADGET+weblink_data.weblink_table[i].id)
||checkWeblinkCount(SIGNAGELINK_GADGET+weblink_data.weblink_table[i].id)){
tmp_weblink_table.push(weblink_data.weblink_table[i]);}
}
weblink_data.weblink_table.splice(0,weblink_data.weblink_table.length);
weblink_data.weblink_table=tmp_weblink_table.slice(0);
tmp_weblink_table.splice(0,tmp_weblink_table.length);
try{
apps_nvram_file.write({"filename":"Weblink_table_bk","data":weblink_data.toSource(),
async:false,finished:function(){},product_id:"home"});
apps_nvram_file.rename({"from":"Weblink_table_bk","to":"Weblink_table",product_id:"home"});}catch(e){
console.log(" nvram_file write Weblink_table error :Error = "+e.message);}
}
function checkWeblinkCount(uniq_id){
var screen_order=getScreenOrder();var screen_info=[];
var order_num=screen_order.length;
for(var i=0;i<order_num;i++){
screen_info[i]=getScreenInfo(screen_order[i]);
var index=screen_info[i].uniq_id_list.indexOf(uniq_id);
if(index!=-1){
return true;}
}
return false;}
BROWSER={};
function prepareHomeBrowser(){
require("pkg_browser");
var self=BROWSER;
if(self.brw)return false;
self.brw=pkg_browser.brw_obj;
self.bookmark_data=null;
self.connecting=false;
self.capture_state=false;
self.capture_list=[];
self.get_bookmark_info=function(){
try{
var tmp=null;
tmp=apps_nvram_file.read({"filename":"Bookmark",async:false,
finished:function(){},product_id:"home"});
if(tmp){
tmp=sysutil.tconv.binary_to_string(tmp);
this.bookmark_data=eval(tmp);}else{
this.bookmark_data.bookmarkpanel=[];
console.log("[get_bookmark_info]not found!!!!!");}
}catch(e){
this.bookmark_data.bookmarkpanel=[];
console.log("[get_bookmark_info]err:"+e.message);}
};
self.set_bookmark_info=function(){
var bookmark_count=this.bookmark_data.bookmarkpanel.length;
if(bookmark_count>0){
var bookmark_url_list=new Array();
for(var i=0;i<bookmark_count;i++){
bookmark_url_list[i]=this.bookmark_data.bookmarkpanel[i].url;}
this.brw.set_bkmk_url_list({count:bookmark_count,list:bookmark_url_list});}else{
this.brw.set_bkmk_url_list({count:0,});}
};
self.get_bookmark_data=function(){
if(this.bookmark_data==null){
this.get_bookmark_info();}
return this.bookmark_data;};
self.get_bookmark_capture=function(id,url){
this.capture_list.push({id:id,url:url});
if(!this.capture_state){
this.start_capture();}
};
self.is_home=function(){
var tmp=this.brw.get_stage();
if(tmp==HOME){
return true;}else{
return false;}
};
self.appear_browser=function(){
this.capture_state=false;
delete_timer(this);
append_timer(this,50,function(obj){
if(_GLOBAL_.platinum_main){
delete_timer(obj);
return;}
if((ebus.pbrowser[0].get_status()!=2)
&&(ebus.pbrowser[0].get_status()!=3)){
delete_timer(obj);
if(BROWSER.brw.appear(this.brw_param)==0)
BROWSER.connecting=true;}
});};
self.disappear_browser=function(type){
delete_timer(this);
if(!type)
this.brw.clear_param();
this.brw.disappear();
this.connecting=false;
PLATINUM_CONNECTED_EV=0;};
self.update_browser_param=function(){
this.get_bookmark_info();
this.set_bookmark_info();
this.brw.appear(this.brw_param);};
self.disconnect_smapho=function(){
if(_GLOBAL_.platinum_main&&_GLOBAL_.platinum_main.SmaphoListner){
_GLOBAL_.platinum_main.SmaphoListner.smapho.disconnect();}
};
self.suspend=function(){
try{
BROWSER.disconnect_smapho()
BROWSER.disappear_browser();}catch(e){
console.log("BROWSER.suspend Error = "+e.message);}
};
self.start_capture=function(){
if(isDisclaimerNeeded()){
this.capture_list.splice(0,this.capture_list.length);
return;}
var caput_interval=this.brw.get_capture_update_time();
var now_time=(new Date()).getTime();
for(var i=0,max_i=this.capture_list.length;i<max_i;i++){
for(var j=0,max_j=this.bookmark_data.bookmarkpanel.length;j<max_j;j++){
if(this.capture_list[i].url==this.bookmark_data.bookmarkpanel[j].url){
if(parseInt(this.bookmark_data.bookmarkpanel[j].update_time)+caput_interval<parseInt(now_time)){
this.capture_state=true;
this.brw.open_url(this.capture_list[i].url);
this.capture_list.splice(0,i);
return;}
break;}
}
}
this.capture_list.splice(0,this.capture_list.length);};
self.brw_param=new Object();
self.brw_param.stage=HOME;
self.brw_param.connect_cb=function(){
self.connecting=false;};
self.brw_param.loaded_cb=function(){
console.log("[loaded]");
self.brw.stop_capture_req();
self.brw.get_pixmap();};
self.brw_param.disconnect_cb=function(){
};
self.brw_param.load_failed_cb=function(){
};
self.brw_param.get_pixmap_cb=function(data){
console.log("[get_pixmap_cb]");
self.get_bookmark_info();
var pos=null;
if(self.capture_state){
for(var i=0,max=self.bookmark_data.bookmarkpanel.length;i<max;i++){
if(self.bookmark_data.bookmarkpanel[i].url==self.capture_list[0].url){
pos=i;
break;}
}
if(pos!=null){
try{
var filename=self.bookmark_data.bookmarkpanel[pos].times+"";
self.bookmark_data.bookmarkpanel[pos].update_time=(new Date()).getTime()+"";
apps_nvram_file.write({"filename":"Bookmark_bk","data":self.bookmark_data.toSource(),
async:false,finished:function(){},product_id:"home"});
apps_nvram_file.rename({"from":"Bookmark_bk","to":"Bookmark",product_id:"home"});
if(data.result){
apps_nvram_file.write({"filename":filename,
"data":data.img,async:false,finished:function(){},product_id:"home"});
if((SU_IS_4K||SU_IS_PRO5TV)&&(data.img_4k!="")){

apps_nvram_file.write({"filename":filename+"_4k",
"data":data.img_4k,async:false,finished:function(){},product_id:"home"});}
if(system.mdl_cfg.with_bp_transit_effect&&!SU_IS_4K&&!SU_IS_PRO5TV){

if(platinum_transient_file!=null){
platinum_transient_file.write({"filename":filename+"_platinum",
"data":data.img_big,async:false,finished:function(){}});}
}
}
}catch(e){
console.log("bookmark capture err :"+e.message);}
self.capture_list.shift();}
}
self.capture_state=false;
if(self.capture_list.length!=0)
self.start_capture();};
self.get_bookmark_info();
self.set_bookmark_info();
self.appear_browser();
return true;}
var background_anim=new container({});
background_anim.width=1460;
background_anim.height=820;
background_anim.img=new gimage({width:1460,height:820,color:[255,255,255,180],
translate:[0,0,0],visible_p:true});
background_anim.components.push(background_anim.img);
background_anim.init=function(){
this.img.src=this.img_src;
this.translate=[1920/2-(1920-460)/2,-1500,200];}
background_anim.setShow=function(bool,img_path,func){
me=HOME.editscreen_op;
self=this;
if(bool){
me.components.push(background_anim);
this.img_src=img_path;
this.init();
this.visible_p=true;
this.moveTo([1920/2-(1920-460)/2,0,200],[1920,1080],0,10,
function(){
self.moveTo([380,80,-1000],[1920,1080],0,10,func);});}else{
delete_timer(this);
this.visible_p=false;
this.freeResource(true);
var index=me.components.indexOf(background_anim);
if(index!=-1){
me.components.splice(index,1);}
}
};
background_anim.freeResource=function(bool){
if(bool){
this.img.src="";}else{
this.img.src=this.img_src;}
}
AnimationGraphics.apply(background_anim);
function setBackgroundImage(image_url){
var me=HOME.editscreen_op;
if(me.set_bg_img_flag==true)return;
me.set_bg_img_flag=true;
if(me.edit_option.visible_p==true){
me.edit_option.setShow(false);}
if(me.add_bookmark_panel.visible_p==true){
me.add_bookmark_panel.setShow(false);}
if(me.power_on_option.visible_p==true){
me.power_on_option.setShow(false);}
if(me.sound_option.visible_p==true){
me.sound_option.setShow(false);}
if(me.kbd!=null){
if(me.kbd.visible_p==true){
del_event_hook(ebus.kbd);
me.kbd.visible_p=false;
me.kbd.kbd.free();
me.kbd.components.splice(0,me.kbd.components.length);
me._active_screen[1].setScreenNameShow(true);
me.screen_name.set_visible(false);
var index=me.components.indexOf(me.kbd);
me.components.splice(index,1);
index=me.components.indexOf(me.screen_name);
me.components.splice(index,1);
me.screen_name=null;
discard_package("kbd");
me.focus.setShow(true);}
}
if(me.bg_edit_panel.visible_p==true){
me.bg_edit_panel.setShow(false);}
if(me.bgedit_option.visible_p==true){
me.bgedit_option.setShow(false);}
if(me.file_select_panel.visible_p==true){
me.file_select_panel.setShow(false);}
if(me.edit_option.getMoveStatus()==true){
me.edit_option.setMoveStatus(false);
var ret=me._active_screen[1].selectFocusedGadget(false);}
me.cursor=me.edit_panel;
me.edit_panel.selectMenu(false,this.menu_index);
me.cursor.onFocus(true,true);
var file_path="file://";
var dir_path="/usr/local/apps_nv/data/home/";
var f_name_bg="bg_";
var f_name_bg_icon="bg_icon_";
var extension=".jpg"
var icon_max_num=4;
var path="";
var path_icon="";
var ret=true;
var file_name="bg_tmp.jpg";
var path_org=dir_path+file_name;
var loading_setshow=function(bool,word){
if(bool){
me._createConfirmpanel(null,[940,400],word,null,null,
function(translate,size,alpha,speed,func){
me.focus.moveTo(translate,size,alpha,speed,func);});
me.components.push(me.loading_circle);
me.loading_circle.init({translate:[1920/2-(1920-460)/2,-70,0]});
me.loading_circle.setShow(true);}else{
me.loading_circle.setShow(false);
me.confirm.setShow(false);
me.confirm.free();
me.components.splice(me.components.indexOf(me.confirm),1);
me.components.splice(me.components.indexOf(me.loading_circle),1);
me.cursor=me.edit_panel;
me.edit_panel.selectMenu(false,this.menu_index);
me.cursor.onFocus(true,true);}
};

var error_func=function(word,mode){
if(me.loading_circle.visible_p==false)return;
loading_setshow(false);
me._createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,
[940,400],word,LANG("LT_OK"),
function(){
me.confirm.setShow(false);
me.confirm.free();
me.components.splice(me.components.indexOf(me.confirm),1);
me.cursor=me.edit_panel;
me.edit_panel.selectMenu(false,this.menu_index);
me.cursor.onFocus(true,true);
me.set_bg_img_flag=false
},
function(translate,size,alpha,speed,func){
me.focus.moveTo(translate,size,alpha,speed,func);});};
var resize_cb1=function(ret1,ret2,ret3,ret4,ret5,ret6){
if((ret5==1)&&(ret6==0)){
resize_jpeg_async(dir_path+path,dir_path+path_icon,
214,120,2,resize_cb2);}else{
error_func(LANG("LT_HOME_ERR_BK_SETTING"));
console.log("resize_jpeg_async error ");}
}
var resize_cb2=function(ret1,ret2,ret3,ret4,ret5,ret6){
if((ret5!=2)||(ret6!=0)){
error_func(LANG("LT_HOME_ERR_BK_SETTING"));
return;}
if(me.loading_circle.visible_p==false)return;
background_anim.setShow(true,file_path+dir_path+path,function(){
try{
background_anim.setShow(false);
if(me.loading_circle.visible_p==true){
loading_setshow(false);
var key=me._active_screen[1].getScreenKey();
var screen_info=me.getScreenInfo(key);
screen_info.wallpaper=file_path+dir_path+path;
me.storeScreenInfo(screen_info,key);
me._active_screen[1].setWallPaper("");
me._active_screen[1].setWallPaper(file_path+dir_path+path);
me.set_bg_img_flag=false
}
}catch(e){
error_func(LANG("LT_HOME_ERR_BK_SETTING"));
console.log(" Error = "+e.message);}
});}
try{
var key=me._active_screen[1].getScreenKey();
var screen_info=me.getScreenInfo(key);
if(!screen_info.editable||screen_info.template=="tv"){
loading_setshow(true,LANG("LT_HOME_INFO_BK_SETTING"));
error_func(LANG("LT_HOME_DL_NOT_EDIT"));
return;}
}catch(e){};

for(var i=1;i<icon_max_num+1;i++){
path=f_name_bg+i+extension;
path_icon=f_name_bg_icon+i+extension;
try{
apps_nvram_file.read({filename:path_icon,async:false,
finished:function(){},product_id:"home",});
if(i==icon_max_num)ret=false;}catch(e){
break;}
}
if(ret==false){
me._createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,
[940,400],LANG("LT_HOME_ERR_BK_FULL"),
LANG("LT_OK"),
function(){
me.confirm.setShow(false);
me.confirm.free();
me.components.splice(me.components.indexOf(me.confirm),1);
me.cursor=me.edit_panel;
me.edit_panel.selectMenu(false,this.menu_index);
me.cursor.onFocus(true,true);
me.set_bg_img_flag=false
},
function(translate,size,alpha,speed,func){
me.focus.moveTo(translate,size,alpha,speed,func);});
return;}
loading_setshow(true,LANG("LT_HOME_INFO_BK_SETTING"));
http_request({url:image_url,
timeout:120,
limit_size:20*1024*1024,
sync:false,
limit_mode:LIMIT_NONE,
method:"GET",
onload:function(status,header,body){
try{
if(status==200){
resize_jpeg_async(body,dir_path+path,960,540,1,resize_cb1);}else {
error_func(LANG("LT_HOME_ERR_BK_SETTING"));}
}catch(e){
error_func(LANG("LT_HOME_ERR_BK_SETTING"));
console.log(" Error = "+e.message);}
}
});};
startup_screen.connect();
startup_screen.garbageCollection();
startup_screen.install();
startup_screen.complete();
startup_screen.reinstall();
var poweron_voice={};
append_timer(poweron_voice,1000,function(obj){
try{
if(getPowerStatus()!=system.POWER_STATUS_ON)return;
judgeNetworkAvailable("power");
if(system.is_ip_available()==1)
checkUpdateAsync();
delete_timer(obj);
var active_screen=HOME.operator.getActiveScreen();
if(active_screen[1]&&active_screen[1] instanceof Screen){
if(HOME.operator===HOME.myscreen_op){
VoiceReserve(active_screen[1].getScreenName());
active_screen[1].onFocus(false);
active_screen[1].onFocus(true);
var order=getScreenOrder();
var screen_key=active_screen[1].getScreenKey();
var current_index=order.indexOf(screen_key);
var temp_name=active_screen[1].getTemplateName();
if(isDLScreen(screen_key)){
var info=HOME.getScreenInfo(screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
append_timer({},60*1000,function(timer){
delete_timer(timer);
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"start",pos:current_index.toString(),template:temp_name});});}
}
}catch(e){
console.log("cannot send voice data: "+e.message);
delete_timer(obj);}
});
var home_key_enable=true;
function blockHomeKeyRepeat(up_down){
if(up_down==KEY_DOWN&&home_key_enable==false){
home_key_enable=true;}
if(home_key_enable==false)return true;
if(up_down==KEY_PRESS&&home_key_enable==true){
home_key_enable=false;}
}
function init_resume_task(){
if(reset_operator_status){
var active_screen=this.operator.getActiveScreen();
this.operator.is_move=false;
this.operator.in_hook(active_screen);}
reset_operator_status=false;
if(reset_screen_status){
var active_screen=HOME.operator.getActiveScreen();
if(active_screen[1]&&active_screen[1] instanceof Screen){
active_screen[1].reset();}
}
reset_screen_status=false;
if(return_home_anim)
HOME.operator.key_hook(KEY_PRESS,TXK_EXIT);
return_home_anim=false;}
function setHomeEventStatus(bool){
this.eventStatus=bool;}
function getHomeEventStatus(){
return this.eventStatus;}
function cancelConfirmPanel(){
if(HOME.operator===HOME.switchscreen_op){
if(HOME.operator.cursor instanceof Confirmpanel){
HOME.operator.key_hook(KEY_PRESS,TXK_RETURN);}
}
}
function transitReturnHOME(){
try{
var active_screen=HOME.operator.getActiveScreen();
if(HOME.operator!==HOME.editscreen_op&&!disable_transit){
HOME.visible_p=true;
if(active_screen[0])active_screen[0].visible_p=false;
if(active_screen[2])active_screen[2].visible_p=false;

active_screen[1].transitReturnHOME();

if(active_screen[0])active_screen[0].visible_p=true;
if(active_screen[2])active_screen[2].visible_p=true;}else{
if(disable_fadein){
HOME.visible_p=true;}else{
if(disable_transit)NEXT_STAGE="no stage";
HOME.visible_p=false;
system.effect.fade(system.effect.FADE_OUT);}
}
}catch(e){
console.log("transitReturnHOME error. "+e.message);}
disable_transit=false;
disable_fadein=false;}
function launchTVforTutorial(bool){
if(HOME.operator!=HOME.myscreen_op)
return;
try{
var active_screen=HOME.operator.getActiveScreen();
active_screen[1].launchTV(bool);}catch(e){
console.log("launchTVforTutorial error. "+e.message);}
}
function launchGadgetEvent(product_id,app_data_id){
var application_data_id=null;
var usrprof_id=null;
var launch_from=null;
if(isString(app_data_id)){
var ret=[];
var tmp=app_data_id.split(" ");
for(var i=0;i<tmp.length;i++){
switch(tmp[i]){
case "-U":
case "--usrprofid":
usrprof_id=parseInt(tmp[i+1]);
i++;
break;
case "-F":
case "--from":
launch_from=tmp[i+1];
i++;
break;
default:
ret.push(tmp[i])
break;}
}
application_data_id=ret.join(" ");}
if(isString(launch_from))
applink.setFrom(launch_from);
applink.set({"launch_to":product_id,
"usrprof_id":usrprof_id,
"application_data_id":application_data_id,
"rawdata":app_data_id});
console.log("applink.get: "+uneval(applink.get()));
if(apputil.getCurrentProductID()!=product_id){
return_home_anim=true;
HOME.setHomeEventStatus(true);
on_stage("HOME");
discard_all_stage();
var linkdata=applink.get();
var report={};
if(isString(linkdata.launch_from))
report.action=linkdata.launch_from.toLowerCase();
apputil.directLaunch(product_id,report);}
applink.clear();
VoiceStop();}
function screenChangeEvent(usrprof_id,is_anim){
append_timer({},40,function(obj){
if(!isActiveStatus()||isBooting)return;
delete_timer(obj);
on_stage("HOME");
var profile=getProfile(usrprof_id);
if(profile!=null){
var screen_key=getVoiceControlScreen(usrprof_id);
if(isScreenKey(screen_key)){
if(is_anim){
userIcon.setSkin(usrprof_id,screen_key);
jumpScreen(screen_key,function(){
userIcon.setSkin(null);});}else{
changeScreen(screen_key);}
}else{
var finished=function(){
switchUI(HOME.operator,VOICE_CONTROL_SCREEN);
HOME.operator.setUsrprofID(usrprof_id);}
if(HOME.operator.is_move==true){
append_timer(obj,40,function(obj2){
if(HOME.operator.is_move==true)return;
delete_timer(obj2);
finished();});}else{
finished();}
}
}});}
var loader=new container({visible_p:false});
loader.components=[
new gbox({width:1920,height:1080,color:[0,0,0,255]}),
loader.circle=new gimage({rotation:[0,0,0,-1],width:150,height:150,
src:IMG_PATH+"loading_circle.png"}),
];
loader.on=function(){
this.visible_p=true;
force_redraw();
append_timer(this.circle,50,function(obj,cnt){
if(cnt*50>3000)loader.off();
obj.rotation[0]=(obj.rotation[0]+30)%360;
force_redraw();});};
loader.off=function(){
this.visible_p=false;
delete_timer(this.circle);
force_redraw();};
var userIcon=new container({visible_p:false});
userIcon.setSkin=function(usrprof_id,screen_key){
if(!(isNumber(usrprof_id)&&usrprof_id>=0))
{
this.visible_p=false;
if(this.components.length!=0){
this.userIcon.src="";
setf_text(this.userName,"");
setf_text(this.msg,"");
this.components=[];}
force_redraw();
return false;}
var uprofile=getProfile(usrprof_id);
if(!uprofile)return false;
this.visible_p=true;
this.translate=[696,370,0];
this.width=500;
this.height=410;
this.components=[
this.bg=new gbox({width:(this.width),height:(this.height),color:COL_POP}),
this.userIcon=new gimage({translate:[-140,80,0],
width:180,height:180}),
this.userName=new gtextbox({translate:[100,80,0],font_size:42,
align:CENTER,valign:MIDDLE,
width:280,height:160,color:COL_TEXT_ONBASE}),
this.msg=new gtextbox({translate:[0,-100,0],font_size:28,
align:CENTER,valign:MIDDLE,
width:480,height:140,color:COL_TEXT_ONBASE}),
];
this.userIcon.src=(uprofile.mhc.icon||"");
setf_text(this.userName,(uprofile.mhc.name||""));
change_font_size_b(this.userName);
var info=HOME.getScreenInfo(screen_key);
if(!info)return;
var msg=(LANG("LT_CAMERA_MATCH_JUMP_MSG")||"Now jumping to [%s].").replace("%s",(info.screen_name||""));
setf_text(this.msg,msg);
change_font_size_b(this.msg);};
var common_inhook=function(){
isBooting=false;
delete_timer(this);
try{
system.key_control.set_key_mode(system.key_control.MODE_HOME);
system.key_control.color=false;
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,1);
resetInputDev();
ebus.asr.set_listener(0);}catch(e){}
append_timer({},1,function(obj){
delete_timer(obj);
discard_all_stage();});
apputil.setCurrentProductID(null);
var bplayer=new BroadcastPlayer();
bplayer.set_browser_mode(BR_SRC_DEFAULT);
setTVPlayerEventHook();};
var common_outhook=function(type){
loader.off();
try{
system.key_control.set_key_mode(system.key_control.MODE_OTHER);
if(type!="use_asr")
{
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,0);
ebus.asr.set_listener(0);}
}catch(e){}
try{
var active_screen=this.operator.getActiveScreen();
active_screen[1].suspend(true);}catch(e){}
try{
active_screen[1].activate(false);
HOME.operator.activateSelectedScreen(false);}catch(e){}
var bplayer=new BroadcastPlayer();
try{
bplayer.df_connect();
bplayer.osd_control(OSD_INVISIBLE);}catch(e){}
disable_transit=false;
disable_fadein=false;};
var isBooting=true;
var startup_ui=stage(
{
symbol:"HOME",
keep_me:true,
in:
[
{
from:["default"],
hook:function(obj){
console.log("### STARTUP UI ###");
common_inhook();
init_stage();
init_resume_task();
if(isActiveStatus()){
complete_on_stage(obj);
obj.visible_p=isVisibleStatus();}
}
},
{
from:["apps"],
hook:function(obj){
common_inhook();
console.log("### STARTUP UI from APPS###");
backHomeStage(false);
init_stage();
if(isActiveStatus())
complete_on_stage(obj);}
},
{
from:["platinum_main","signage"],
hook:function(obj){
console.log("### STARTUP UI BY PLATINUM ###");
common_inhook();
init_stage();
init_resume_task();
BROWSER.get_bookmark_info();
BROWSER.set_bookmark_info();
if(HOME.operator==HOME.myscreen_op){
var active_screen=this.operator.getActiveScreen();
if(active_screen[1]&&active_screen[1] instanceof Screen){
if(isActiveStatus())
{
active_screen[1].activate(true);}
}
}
if(isActiveStatus()){
complete_on_stage(obj);
BROWSER.disappear_browser();
BROWSER.appear_browser();}
if(SU_IS_SLOW_ANIM){
var fade_in_timer={};
append_timer(fade_in_timer,1000,function(obj2){
delete_timer(obj2);
if(system.effect)system.effect.fade(system.effect.FADE_IN);});}
else {
if(system.effect)system.effect.fade(system.effect.FADE_IN);}
}
},
{
from:["mystream"],
hook:function(obj){
common_inhook();
init_stage();
init_resume_task();
if(isActiveStatus()){
complete_on_stage(obj);}
if(SU_IS_PRO4_4K){
var fade_in_timer={};
append_timer(fade_in_timer,1000,function(obj2){
delete_timer(obj2);
if(system.effect)system.effect.fade(system.effect.FADE_IN);});}
else {
if(system.effect)system.effect.fade(system.effect.FADE_IN);}
}
},
],
out:
[
{
to:["default"],
hook:function(obj){
common_outhook();
complete_off_stage(obj);}
},
{
to:["HOME"],
hook:function(obj){
loader.off();
try{
system.key_control.set_key_mode(system.key_control.MODE_HOME);
system.key_control.color=false;
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,1);
ebus.asr.set_listener(0);}catch(e){}
}
},
{
to:["apps"],
hook:function(obj){
console.log("### STARTUP UI to APPS###");
backHomeStage(true);
var bplayer=new BroadcastPlayer();
bplayer.osd_control(OSD_INVISIBLE);}
},
{
to:["search"],
hook:function(obj){
try{
system.key_control.set_key_mode(system.key_control.MODE_OTHER);
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,0);}catch(e){}
try{
var active_screen=this.operator.getActiveScreen();
active_screen[1].suspend(true);}catch(e){}
try{
active_screen[1].activate(false);}catch(e){}
var bplayer=new BroadcastPlayer();
bplayer.df_connect();
bplayer.osd_control(OSD_INVISIBLE);
ebus.asr.set_listener(1);
append_timer(this,50*15,function(obj2){
delete_timer(obj2);
complete_off_stage(obj2);});}
},
{
to:["message"],
hook:function(obj){
common_outhook();
toolbar.setBadge([null,null,null,0,null,null]);
append_timer(this,50*15,function(obj2){
delete_timer(obj2);
complete_off_stage(obj2);});}
},
{
to:["platinum_main"],
hook:function(obj){
common_outhook("use_asr");
if(system.mdl_cfg.with_browser_with_tv){
system.key_control.set_key_mode(system.key_control.MODE_HOME);
system.key_control.numeral=true;ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,1);
ebus.asr.set_listener(1);}
complete_off_stage(obj);}
},
{
to:["mystream"],
hook:function(obj){
common_outhook("use_asr");
complete_off_stage(obj);}
},
],
bg_translate:[0,0,3*CAMERA_POS],
bg_image:[pre_videobox,pre_videobox_sub,startup],
components:[guidance_container,userIcon,loader],
key_hook:function(up_down,key){
if(guidance_container.key_hook(up_down,key))
return true;
system.idle.update_count();
if(system.is_apps_launch())
return false;

if(key==TXK_HOME&&blockHomeKeyRepeat(up_down)){
return true;}

if(this.cursor&&this.cursor.key_hook
&&this.cursor.key_hook(up_down,key)){
return true;}
if(up_down!=KEY_PRESS)return true;

if(key==TXK_EXIT||key==TXK_HOME)
return true;

return false;}
});
set_system_home_stage("HOME",PATH+"startup_ui.js");
discard_all_stage=function(){
var home=get_system_home_stage();
var log_msg=[];
for(var stg in stages){
if(stg!=home.symbol&&!(_GLOBAL_[stg]&&_GLOBAL_[stg].visible_p)){
complete_off_stage(_GLOBAL_[stg]);
discard_stage(stg);}else{
log_msg.push(stg);}
}
if(log_msg.length>2)
console.log("[JS fatal error] There are too many active stages. ["+log_msg.join(", ")+"]");};
visible_all_stage_except_apps=function(){
var home=get_system_home_stage();
for(var stg in stages){
if((stg!=home.symbol)&&(stg!="apps")&&(stg!="apps_customize")){
stages[stg].visible_p=true;}
}
};
invisible_all_stage_except_apps=function(){
var home=get_system_home_stage();
for(var stg in stages){
if((stg!=home.symbol)&&(stg!="apps")&&(stg!="apps_customize")){
stages[stg].visible_p=false;}
}
};
return_home_anim=false;
reset_screen_status=false;
reset_operator_status=false;
check_usrprof=false;
disable_transit=false;
disable_fadein=false;
default_system_key_hook=function (up_down,key){
if(up_down!=KEY_PRESS)
return false;
switch(key){
case TXK_APPS:
return false;
case TXK_HOME:
case TXK_EXIT:

try{
BROWSER.disconnect_smapho();}catch(e){};
var hb_mode=system.home_browser.get_mode();
if(hb_mode==system.home_browser.MODE_TV_MYSTREAM){
return true;}else if(hb_mode==system.home_browser.MODE_HOME_MYSTREAM){
return true;}else if((hb_mode==system.home_browser.MODE_HOME_MYSTREAM_BROWSER)||
(hb_mode==system.home_browser.MODE_TV_MYSTREAM_BROWSER)||
(hb_mode==system.home_browser.MODE_HOME_MYSTREAM_CONTINUE)||
(hb_mode==system.home_browser.MODE_TV_MYSTREAM_CONTINUE)){
launch_appli(MYSTREAM_APPS);
return true;}
discard_all_stage();
var home=get_system_home_stage();
if(HOME.operator===HOME.myscreen_op){
if(HOME.operator.is_move==true)reset_operator_status=true;
on_stage(home.symbol);}else {
if(key==TXK_HOME
||(key==TXK_EXIT&&system.locale.country=="JP")){
return_home_anim=true;
HOME.setHomeEventStatus(true);}
on_stage(home.symbol);}
return true;}
return false;}
set_system_key_hook(default_system_key_hook);
add_default_stage_event_hook(system.guidance,
function(stg,obj,ev){
switch(ev){
case system.guidance.LAUNCH_INITIAL:
case system.guidance.LAUNCH_USER_HOMESCREEN:
case system.guidance.LAUNCH_USER_BOOKMARK:
case system.guidance.LAUNCH_DEMO:
if(isActiveStatus()){
var ret=false;
try{
var active_screen=this.operator.getActiveScreen();
if(active_screen[1]&&active_screen[1] instanceof Screen)
active_screen[1]._SMAd_destroy();}catch(e){};
guidance_container.createObject();
ret=guidance_container.start(startup_ui,ev,
interface2Tutorial.getScreenInfo());
if(ret==false){
system.guidance.terminate_request(0);}
}else {
system.guidance.terminate_request(0);}
return true;
case system.guidance.TERMINATE:
guidance_container.stop();
guidance_container.clearObject();
return true;
default:
break;}
return false;});
add_default_stage_event_hook(
system.screensaver,
function (stg,obj,ev,data){
switch(ev){
case system.screensaver.NO_OPERATION:
if(!isActiveStatus())return false;
if(isMyHOME()){
switch(data){
case 5:
var active_screen=HOME.operator.getActiveScreen();
active_screen[1].launchTVWithAnim();
return true;
case 1:
system.screensaver.lower_brightness();
return true;}
}else{
if(data==5){
system.screensaver.start();
return true;}
}
break;
case system.screensaver.SCRSAVER_STAT:
break;
case system.screensaver.LOWERBRIGHT_STAT:
break;
default:
break;}
});
if(system.effect){
add_default_stage_event_hook(
system.effect,
function (stg,obj,ev){
switch(ev){
case system.effect.FADE_OUT_END:
var old=NEXT_STAGE;
NEXT_STAGE=null;
try{
switch(old){
case "no stage":
break;
case null:
on_stage("HOME");
break;
default:
on_stage(old);
break;}
}catch(e){
on_stage("HOME");}
append_timer(system.effect,40,function(obj){
delete_timer(obj);
system.effect.fade(system.effect.FADE_IN);});
return true;
case system.effect.FADE_IN_END:
return true;}
return false;});}
add_default_stage_event_hook(
ebus.pbrowser[0],
function (stg,obj,ev,data1,data2,data3){
switch(ev){
case ebus.pbrowser[0].CONNECTED_EV:
PLATINUM_CONNECTED_EV=1;
return true;}
return false;});
try{startup_ui.add_event_hook(system.system_event,
function(stg,obj,ev){
switch(ev){
case system.system_event.RETURN_TV:
var active_screen=HOME.operator.getActiveScreen();
active_screen[1].launchTVPlayer();
return true;
case system.system_event.RESET_PIN:
HOME.updateHomeLockedFace();
return true;
case system.system_event.SET_BG_IMG:
if(HOME.operator===HOME.editscreen_op){
console.log("set background",arguments[3]);
setBackgroundImage(arguments[3]);
return true;}
return false;
default:
break;}
return false;});
add_default_stage_event_hook(system.system_event,
function(stg,obj,ev,data){
if(runSystemEventHook(stg,obj,ev,data))
return true;
switch(ev){
case system.system_event.POWER_OFF:
system.reboot();
return true;
case system.system_event.POWER_ON:
return true;
case system.system_event.RETURN_HOME:
if(guidance_container.isActive){
system.guidance.terminate_request(0);}
try{
var active_screen=HOME.operator.getActiveScreen();
if(active_screen&&active_screen[1]){
var tv_obj=active_screen[1].getTVGadgetObject();
active_screen[1].resetFullscreenAppli(tv_obj);}
}catch(e){
console.log("cannot reset fullscreen appli");};
var browser_home_mode=system.home_browser.get_mode();
if(_GLOBAL_.platinum_main&&_GLOBAL_.platinum_main.components){
for(var i=0;i<platinum_main.components.length;i++){
if(platinum_main.components[i].free)platinum_main.components[i].free();}
}
discard_all_stage();
var bplayer=new BroadcastPlayer();
bplayer.set_browser_mode(BR_SRC_DEFAULT);
if(BROWSER.is_home&&!BROWSER.is_home()){
if(system.mdl_cfg.with_pen_support_web_browser)
system.touchpen.stop();
BROWSER.get_bookmark_info();
BROWSER.set_bookmark_info();}
if(HOME.operator.is_move==true)return true;
reset_screen_status=true;
if((browser_home_mode==system.home_browser.MODE_TV_BROWSER)
||(browser_home_mode==system.home_browser.MODE_TV_MYSTREAM)){

bplayer.df_disconnect();
bplayer.osd_control(OSD_NORMAL);
launch_appli(TV_GADGET);}
else if(HOME.operator===HOME.myscreen_op){
on_stage("HOME");}
else {
return_home_anim=true;
HOME.setHomeEventStatus(true);
on_stage("HOME");}
if(BROWSER.is_home&&!BROWSER.is_home()){
BROWSER.disappear_browser();
BROWSER.appear_browser();}
return true;
case system.system_event.LAUNCH_WEB_BROWSER:
if(!data||data==BROWSER_APPS){
try{
if(_GLOBAL_.platinum_main&&_GLOBAL_.platinum_main.visible_p)
return true;}catch(e){};
loader.on();
append_timer(this,10,function (obj,count){
delete_timer(obj);
discard_all_stage();
try{
on_stage("platinum_main");
apputil.setCurrentProductID(null);
loader.off();
discard_all_stage();
complete_off_stage(HOME);}catch(e){loader.off();}
});}else{
var filename=getInfoPlist(data,"pbrowser");
var symbol=data+"/"+filename;
var filepath=APPLI_PATH+data+"/gadget/"+filename;
add_stage_load_path(symbol,filepath);
discard_all_stage();
try{
if(isActiveStatus()){
on_stage(symbol);
apputil.setCurrentProductID(null);
complete_off_stage(HOME);}else{
jump_pbrowser.set(symbol);}
}catch(e){}
}
return true;
case system.system_event.LAUNCH_MYSTREAM:
loader.on();
if(!data||data==MYSTREAM_APPS){
try{
if(_GLOBAL_.mystream&&_GLOBAL_.mystream.visible_p)
return true;}catch(e){};
try{
BROWSER.disappear_browser();}catch(e){}
on_stage("HOME");discard_all_stage();
try{
on_stage("mystream");
apputil.setCurrentProductID(null);
discard_all_stage();
complete_off_stage(HOME);}catch(e){}
}
return true;
case system.system_event.RESTART_HOME_BROWSER:
if(BROWSER.is_home&&BROWSER.is_home()){
BROWSER.disappear_browser();
BROWSER.appear_browser();}else{
BROWSER.disappear_browser(1);}
break;
case system.system_event.UPDATE_HOME_LOCKFACE:
updateLockedList();
HOME.updateHomeLockedFace();return true;
case system.system_event.UNINSTALL_GADGETS:
HOME.uninstallGadgets();
ebus.app_upd.sync();
return true;
case system.system_event.RETURN_HOME_FULL_TV:
system.reboot(getFullTVScreen());
return true;
case system.system_event.REPORT_LAUNCH_APP:
if(data==SETUPUSER_APPS){
if(HOME.operator!==HOME.myscreen_op){
check_usrprof=true;
return_home_anim=true;
on_stage("HOME");}
}
jump_pbrowser.reset();
startup_screen.mhc_status="LAUNCH";
var req=0;
try{
var exist=apps_nvram_file.apps_exist({product_id:data,filename:"Info.plist"});
var cc=exist&&getInfoPlist(data,"cc");
if(cc&&cc.match("^true")){
var tmp=read_file("file:///usr/local/ajaxce/nvram/nvram_1383");
if(tmp){
apps_nvram_file.write({filename:"nvram",product_id:IPTV_CC_SETTING_APPS,data:tmp});
var ret=eval(apps_nvram.read("setting_param",IPTV_CC_SETTING_APPS));
req=ret.mode;}
}
}catch(e){}
try{
system.write_iptv_req(req);
if(req)console.log("Enable Closed Caption");}catch(e){}
return true;
case system.system_event.LAUNCH_GADGET:
var product_id=data;
var app_data_id=arguments[4];
disable_transit=true;
disable_fadein=false;
if(product_id==SETUPUSR_APPS)
disable_fadein=true;
loader.on();
if(isActiveStatus()&&!isBooting){
launchGadgetEvent(product_id,app_data_id);}else{
append_timer({},40,function(obj){
if(!isActiveStatus()||isBooting)return;
delete_timer(obj);
launchGadgetEvent(product_id,app_data_id);});}
return true;
case system.system_event.UPDATE_IP_AVAILABLE:
judgeNetworkAvailable("net");
if(isUpdateNeeded()==null){
if(system.is_ip_available()==1){
append_timer(update_latest_timer,1000,function(obj){
delete_timer(obj);
checkUpdateAsync();});}
}
return true;
case system.system_event.LAUNCH_MAIN_HS_SELECTOR:
var usrprof_id=data;
return_home_anim=true;
on_stage("HOME");
append_timer({},40,function(obj){
if(!isActiveStatus())return;
delete_timer(obj);
loader.off();
switchUI(HOME.operator,VOICE_CONTROL_SCREEN);
if(HOME.operator===HOME.voicecontrol_op){
HOME.operator.setLaunchFrom("setupuser");
HOME.operator.setUsrprofID(usrprof_id);}});
return true;
case system.system_event.SCREEN_CHANGE:
var usrprof_id=system.apps.get_auth_profid();
if(!isNumber(usrprof_id))break;
screenChangeEvent(usrprof_id,true);
return true;
case system.system_event.SCREEN_CHANGE_WITH_PROFID:
var usrprof_id=data;
if(!isNumber(usrprof_id))break;
screenChangeEvent(usrprof_id,false);
return true;
case system.system_event.SCREEN_CHANGE_WITH_TEMPLATE_NAME:
var template_name=data;
var pon_select=HOME.getPowerOnSelect();
if(pon_select!="last")return true;
_changeTemplateScreen(template_name,"no anim");
return true;
case system.system_event.REMOVED_USER:
usrprof_GC();
GC_VoiceControlScreen();
return true;
case system.system_event.LAUNCH_ADVBANNER:
if(system.is_pnlpow_on()){
if(HOME&&HOME.operator&&stg.symbol=="HOME"){
var active_screen=HOME.operator.getActiveScreen();
if(active_screen[1]){
active_screen[1]._my_add_SMAd();
active_screen[1]._SMAd_init();}
}
}
return true;
case system.system_event.RECREATE_GADGET:
is_power_on_netflix=false;
try{
if(isActiveStatus()){
var active_screen=HOME.operator.getActiveScreen();
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
active_screen[i].createGadgets(null,true);
active_screen[i].freeResource(false);}
}
}
}catch(e){
console.log("RESUME Error = "+e.message);
console.log("<< !!Reassemble!! >>");
system.reboot();}
return true;
default:
break;}
return false;});}catch(e){
console.log(" system event error: Error = "+e.message);}
try{add_default_stage_event_hook(system.user_agent,
function(stg,obj,ev){
if(runUserAgentHook.apply(this,arguments))
return true;
return false;});}catch(e){
console.log(" system event error: Error = "+e.message);}
try{add_default_stage_event_hook(system.multitask,
function(stg,obj,ev,data){
force_redraw();
switch(ev){
case obj.POST_SUSPEND:
console.log(" ## POST SUSPEND ");
setActiveStatus(false);
isDisclaimerNeeded();
var active_screen=HOME.operator.getActiveScreen();
active_screen[1].suspend(true);
active_screen[1].activate(false);
HOME.operator.activateSelectedScreen(false);
HOME.visible_p=false;
var bplayer=new BroadcastPlayer();
bplayer.df_disconnect();
if(BROWSER.is_home&&!BROWSER.is_home()){
if(system.mdl_cfg.with_pen_support_web_browser)
system.touchpen.stop();
BROWSER.get_bookmark_info();
BROWSER.set_bookmark_info();}
try{
BROWSER.suspend();}catch(e){}
invisible_all_stage_except_apps();
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
if(i!=1)
active_screen[i].freeResource(true);}
}
resetInputDev();
append_timer({},1,function(obj2){
delete_timer(obj2);
try{
cancelConfirmPanel();
on_stage("HOME");}catch(e){
console.log("<< !!Reassemble!! >>");
system.reboot();}});
break;
case obj.PRE_RESUME:
case obj.POST_RESUME:
console.log(" ## RESUME ");
setActiveStatus(true);
visible_all_stage_except_apps();
try{
if(HOME.operator===HOME.myscreen_op){
system.key_control.set_key_mode(system.key_control.MODE_HOME);
system.key_control.color=false;
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,1);}else {
system.key_control.set_key_mode(system.key_control.MODE_OTHER);
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,0);}
resetInputDev();
ebus.asr.set_listener(0);}catch(e){}
if(is_power_on_netflix){
system.reboot();
return;}
try{
var active_screen=HOME.operator.getActiveScreen();
var update_list=usrprof_GC();
HOME.operator.updateUsrprof();
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
var screen_key=active_screen[i].getScreenKey();
if(update_list.indexOf(screen_key)!=-1)
active_screen[i].destroyGadgets();}
}
}catch(e){console.log(e.message);}
check_usrprof=false;

try{
for(var i=0;i<active_screen.length;i++){
if(active_screen[i]&&active_screen[i] instanceof Screen){
active_screen[i].createGadgets(null,true);
active_screen[i].freeResource(false);}
}
active_screen[1].suspend(false);
if(!HOME.operator.activateSelectedScreen(true)){
active_screen[1].activate(true);}
if((HOME.getHomeEventStatus()==false)&&
(HOME.operator.is_move==true||
(HOME.operator._rotate_state&&HOME.operator._rotate_state!=false))){
HOME.operator.is_move=false;
HOME.operator._rotate_state=false;
HOME.operator.in_hook(active_screen);}
if(data==1&&
!jump_pbrowser.get()&&
system.home_browser.get_mode()==system.home_browser.MODE_HOME){
transitReturnHOME();}else {
HOME.visible_p=true;}

PLATINUM_CONNECTED_EV=0;
try{
BROWSER.appear_browser();}catch(e){};
try{
if(startup_screen.mhc_status){
var tmp=startup_screen.mhc_status.match("^ANIMATION:(.+)");
if(tmp&&tmp.length>0&&isString(tmp[1])){
var order=HOME.getScreenOrder();
var len=order.length;
if(HOME.operator===HOME.switchscreen_op&&
HOME.operator.getMenuType()==startup_selection.MENU_ADD2){
HOME.operator.addDLScreen(tmp[1]);}else{
jumpScreen(tmp[1]);}
}
}
}catch(e){
console.log("animation error: "+e.message);}
startup_screen.mhc_status=null;
append_timer({},1000,function(obj){
delete_timer(obj);
HOME.HomeSoundPlay("cancel");});}catch(e){
console.log("RESUME Error = "+e.message);
console.log("<< !!Reassemble!! >>");
system.reboot();}
try{
var symbol=jump_pbrowser.get();
if(symbol){
loader.on();
append_timer({},500,function(obj){
loader.off();
delete_timer(obj);
on_stage(symbol);
complete_off_stage(HOME);});}
}catch(e){}
jump_pbrowser.reset();
break;}
});}catch(e){console.log("cannot MultiTasking ");}
