OSDN Git Service

Add Counting Screen-time to KWS and app/screentime [0.2.1]
[kit/kit.git] / system.js
index beb3277..cc8ff3b 100644 (file)
--- a/system.js
+++ b/system.js
@@ -6,7 +6,7 @@
 //  |   <| | |_ 
 //  |_|\_\_|\__|
 //
-// THIS IS THE KIT KERNEL AND KIT WINDOW SYSTEM
+// THIS IS THE KIT KERNEL, KIT APPS FRAMEWORK AND KIT WINDOW SYSTEM
 // http://web.kitit.ml/
 // https://github.com/mtsgi/kit
 
@@ -52,7 +52,9 @@ function kit() {
     if( !localStorage.getItem( "kit-appdir" ) ) localStorage.setItem( "kit-appdir", "./app/" );
     S.appdir = localStorage.getItem( "kit-appdir" );
 
-    if( localStorage.getItem( "kit-installed" ) ) System.installed = JSON.parse( localStorage.getItem( "kit-installed" ) );
+    if( localStorage.getItem('kit-installed') ) System.installed = JSON.parse( localStorage.getItem('kit-installed') );
+
+    if( localStorage.getItem('kit-screentime') ) KWS.screenTime = JSON.parse( localStorage.getItem('kit-screentime') );
 
     if( localStorage["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
     if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
@@ -63,8 +65,18 @@ function kit() {
     if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
     else  clockmove = setInterval( System.clock, 10 );
 
-    Notification.push( "kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system" );
-    //スタートアップ
+    if ( localStorage.getItem("kit-shutted-down") == "false" ) {
+        Notification.push("お知らせ", "kitは前回終了時、正しくシャットダウンされませんでした。", "system");
+    }
+    localStorage.setItem("kit-shutted-down", false);
+
+    Notification.push("kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system", null, null, 'documents/icon.png', [
+        {
+            label: 'kitについて',
+            func: () => System.launch( 'settings', {'view': 'about'} )
+        }
+    ]);
+
     if( localStorage.getItem( "kit-startup" ) == undefined ) {
         localStorage.setItem( "kit-startup", new Array( "welcome" ) );
     }
@@ -73,7 +85,7 @@ function kit() {
         Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
         System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
     }
-    else for( let i of System.startup ) if( i != "" ) launch( i );
+    else for( let i of System.startup ) if( i != "" ) System.launch(i);
     
     $("#kit-header-fullscreen").hide();
 
@@ -95,18 +107,29 @@ function kit() {
             $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
         }
     } );
-    //デスクトップアイコン
+    $.getJSON("system/testload.json").fail( () => {
+        $('#body').append(`<div id='wcors' class="window windowactive" style="top: 70px; left: 50px; width: calc(100% - 100px)">
+            <div class="wt">問題が発生しました</div>
+            <div class="winc">JSONデータ読み込みに失敗しました。<br>
+            クロスオリジン制約によりkitアプリケーションの動作が制限されている場合があります。<br>
+            詳細は<a class="kit-hyperlink" onclick="location.href = 'https://mtsgi.github.io/kitdocs/#/cors'">こちらの記事</a>をご確認ください。</div>
+        </div>`);
+        $('<kit-button-alt class="kit-block kit-text-c m">閉じる</kit-button-alt>').appendTo('#wcors .winc').on('click', ()=>{
+            $('#wcors').remove();
+        })
+    });
+    
     $.getJSON("config/desktop.json", (data) => {
         for( let i in data ){
             $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
         }
         $(".desktop-icon").on("click", function(){
-            launch( $(this).attr("data-launch") );
+            System.launch( $(this).attr("data-launch") );
         });
     }).fail( function() {
         Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
     } );
-    //ランチャー
+    
     $.getJSON("config/apps.json", System.initLauncher).fail( function() {
         Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
     } );
@@ -114,7 +137,7 @@ function kit() {
         System.close( this.id.slice( 1 ) );
         $( this ).hide();
     } );
-    //通知バー
+    
     $( "#footer-noti" ).click( function() {
         $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
         if( $( "#notifications" ).is( ":visible" ) ) {
@@ -133,7 +156,7 @@ function kit() {
         }
         else Notification.goodnight = false;
     });
-    //電源管理
+    
     $( ".power-button" ).click( function() {
         $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
         $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
@@ -177,7 +200,7 @@ function kit() {
     }, function() {
         $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
     } );
-    //ランチャー起動
+    
     $( "#launch" ).click( function() {
         $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
         if( $( "#launcher" ).is( ":visible" ) ) {
@@ -236,7 +259,7 @@ function kit() {
                             </div>
                             <div class='--open fa fa-arrow-right'></div>
                         </div>`).appendTo('#kit-sightre-results').on('click', () => {
-                            launch('kish', { 'rc': [ _cmd ] });
+                            System.launch('kish', { 'rc': [ _cmd ] });
                     });
                 }
             }
@@ -249,7 +272,7 @@ function kit() {
                         </div>
                         <div class='--open fa fa-arrow-right'></div>
                     </div>`).appendTo('#kit-sightre-results').on('click', () => {
-                        launch( localStorage.getItem( "kit-default-browser" ), { "url" : _word } );
+                        System.launch( localStorage.getItem('kit-default-browser'), { "url" : _word } );
                 });
             }
             else {
@@ -268,7 +291,7 @@ function kit() {
                         catch(error) {
                             Notification.push("引数の解釈に失敗", error, "system");
                         }
-                        launch( _word.split(",")[0], _args );
+                        System.launch( _word.split(",")[0], _args );
                 });
             }
             for( let i in System.apps ){
@@ -281,7 +304,7 @@ function kit() {
                             </div>
                             <div class='--open fa fa-arrow-right'></div>
                         </div>`).appendTo('#kit-sightre-results').on('click', () => {
-                        launch(i);
+                        System.launch(i);
                         $('#kit-sightre-results').html('');
                         $('#kit-sightre').fadeOut(300);
                     });
@@ -311,7 +334,7 @@ function kit() {
                     </div>
                     <div class='--open fa fa-arrow-right'></div>
                 </div>`).appendTo('#kit-sightre-results').on('click', () => {
-                launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
+                System.launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
                 $('#kit-sightre-results').html('');
                 $('#kit-sightre').fadeOut(300);
             });
@@ -323,14 +346,13 @@ function kit() {
                     </div>
                     <div class='--open fa fa-arrow-right'></div>
                 </div>`).appendTo('#kit-sightre-results').on('click', () => {
-                launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
+                System.launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
                 $('#kit-sightre-results').html('');
                 $('#kit-sightre').fadeOut(300);
             });
         }
     });
 
-    //サウンドドロップダウン
     $("#dropdown-sound-slider").slider({
         min: 0, max: 100, step: 1, value: 100,
         change: (e, ui) => {
@@ -357,11 +379,8 @@ function kit() {
         }
     });
 
-    $("#kit-header-user").on("click", ()=>{
-        launch("user");
-    });
+    $('#kit-header-user').on('click', () => System.launch('user') );
 
-    //コンテキストメニュー
     $(":root section:not(#desktop-l)").on("contextmenu", function() {
         let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
         S.selectedElement = _ptelem;
@@ -407,7 +426,7 @@ function kit() {
     });
     $( "#kit-context-search" ).on("click", function(){
         $("#kit-context").fadeOut(300);
-        launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#kit-context-input" ).val() } );
+        System.launch( 'browser', {'url': `https://www.bing.com/search?q=${$('#kit-context-input').val()}`} );
     });
     $( "#kit-context-input" ).keypress( function( e ) {
         if( e.which == 13 ) $( "#kit-context-search" ).click();
@@ -432,15 +451,15 @@ function kit() {
         $("#kit-context").fadeOut(300);
     })
 
-    $( document ).delegate( "a", "click", function() {
+    $( document ).delegate('a', 'click', function() {
         if( this.href ) {
-            launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
+            System.launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
             return false;
         }
-    } ).on("mousemove", function(event){
-        System.mouseX = event.clientX;
-        System.mouseY = event.clientY;
-    }).delegate( ".textbox", "keypress", function( e ) {
+    } ).on("mousemove", function(e){
+        System.mouseX = e.clientX;
+        System.mouseY = e.clientY;
+    }).delegate('.textbox', 'keypress', function(e) {
         if( e.which == 13 && this.id ){
             if( $("#" + this.id + " + .kit-button").length ){
                 Notification.push("debug", this.id, "system");
@@ -468,19 +487,23 @@ function kit() {
     }
 }
 
-function launch( str, args, dir ) {
+async function launch( str, args, dir ) {
+    while(System.launchLock) await System.ajaxWait();
+    System.launchLock = true;
+
     let _pid = pid;
     System.args[_pid] = args;
-    System.launchpath[_pid] = dir || System.appdir + str;
+    let _path = dir || System.appdir + str;
+    System.launchpath[_pid] = _path;
 
-    if( System.appCache[str] ) {
+    if( System.appCache[_path] ) {
         if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
-        appData( System.appCache[str] );
+        appData( System.appCache[_path] );
     }
     else {
         try{
-            $.getJSON( S.launchpath[_pid] + "/define.json", appData ).fail( function() {
-                Notification.push("kitアプリをロードできません", str + "を展開できませんでした。アプリが存在しないか、クロスオリジン要求がブロックされている可能性があります。詳細:https://kitdev.home.blog/", "system");
+            $.getJSON( S.launchpath[_pid] + '/define.json', appData ).fail( () => {
+                Notification.push('kitアプリをロードできません。', `${str}を展開できませんでした。`, 'system');
             } );
         }
         catch(error){
@@ -489,9 +512,8 @@ function launch( str, args, dir ) {
     }
 }
 
-function appData( data ) {
+async function appData( data ) {
     let _pid = pid;
-    app = new App(_pid);
     process[String( _pid )] = {
         id: data.id,
         time: System.time.obj.toLocaleString(),
@@ -499,7 +521,8 @@ function appData( data ) {
         preventclose: false,
         title: data.name
     };
-    System.appCache[data.id] = data;
+    System.appCache[System.launchpath[pid]] = data;
+    app = new App(_pid);
     let _taskAppend = `<span id='t${_pid}'>`;
     if( data.icon && data.icon != "none" ) _taskAppend += `<img src='${S.launchpath[_pid]}/${data.icon}'>`;
     _taskAppend += `<span id='tname${_pid}'>${data.name}<span></span>`;
@@ -616,6 +639,7 @@ function appData( data ) {
             $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
         }
         localStorage.setItem( "kit-pid", pid );
+        System.launchLock = false;
     } );
 }
 
@@ -671,6 +695,24 @@ const System = new function() {
     this.log = new Array();
     this.noop = () => {}
 
+    this.launchLock = false;
+    
+    this.waitLaunchUnlock = (callback) => {
+        setTimeout(()=>{
+            if(this.ajaxLock){
+                this.waitLaunchUnlock(callback);
+            }else{
+                return callback();
+            }
+        }, 100)
+    }
+
+    this.ajaxWait = () =>{
+        return new Promise(resolve =>{
+             System.waitLaunchUnlock(resolve);
+        });
+    }
+
     this.setBattery = function(){
         if( navigator.getBattery ) navigator.getBattery().then((e)=>{
             let _lv =  e.level * 100;
@@ -703,11 +745,11 @@ const System = new function() {
     }
 
     this.save = function(data, type){
-        launch("fivr", { "save" : data, "type" : type });
+        System.launch("fivr", { "save" : data, "type" : type });
     }
 
     this.open = function(filename){
-        launch("fivr", { "open" : filename });
+        System.launch("fivr", { "open" : filename });
     }
 
     this.preventClose = function( _pid ){
@@ -721,7 +763,7 @@ const System = new function() {
         $( "#kit-power-back" ).click();
         for( let i in process ) {
             if( process[i].preventclose == true ){
-                S.dialog( "シャットダウンの中断", "pid" + System.appCache[process[i].id].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
+                S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
                     process[i].preventclose = false;
                     System.shutdown();
                 } );
@@ -734,6 +776,7 @@ const System = new function() {
         $( "header, footer" ).fadeOut( 300 );
         $( "#kit-wallpaper" ).fadeOut( 1500 );
         if( _opt == "reboot" ) location.href = "autorun.html";
+        localStorage.setItem("kit-shutted-down", true);
     }
 
     this.reboot = function() {
@@ -753,21 +796,21 @@ const System = new function() {
         else $( "#lock-password" ).hide();
     }
 
-    this.alert = function( title, content, winname ) {
-        launch( "alert", [title, content, winname] );
+    this.alert = function( title, content, wtitle ) {
+        System.launch("alert", [title, content, wtitle]);
     }
 
     this.dialog = function( title, content, func ){
-        launch("dialog", {
+        System.launch("dialog", {
             "title": title,
             "content": content,
             "func": func
-        })
+        });
     }
 
     this.appInfo = function( _pid ){
         let _title = "", _content = "";
-        let ac = System.appCache[process[_pid].id];
+        let ac = System.appCache[S.launchpath[_pid]];
         let _lp = System.launchpath[_pid];
         if( ac ){
             _title = ac.name + " " + ac.version;
@@ -927,22 +970,51 @@ const System = new function() {
         $("#launcher-apps").html("");
         System.apps = data;
         for( let i in data ){
-            $("#launcher-apps").append("<div class='launcher-app' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
+            $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
         }
-        if( !System.bootopt.get("safe") ){
+        if( !System.bootopt.get('safe') ){
             for( let i of System.installed ){
-                $("#launcher-apps").append("<div class='launcher-app' data-define-path='" + i.path + "' data-define-id='" + i.id + "'><img src='" + i.icon + "'>" + i.name + "</div>");
+                $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
             }
         }
-        $(".launcher-app").on("click", function(){
-            $("#launch").click();
-            if( $(this).attr("data-launch") ) launch( $(this).attr("data-launch") );
-            else if( $(this).attr("data-define-path") ){
-                launch( $(this).attr("data-define-id"), null, $(this).attr("data-define-path") );
-            };
+        $('.launcher-app').on('click', function(){
+            $('#launch').click();
+            System.launch( $(this).attr('data-launch') );
         });
     }
 
+    this.launch = async function(path, args) {
+        while(this.launchLock) await this.ajaxWait();
+        this.launchLock = true;
+
+        let _pid = pid;
+        System.args[_pid] = args;
+        let _path = path;
+        if(_path.lastIndexOf('/') == _path.length - 1) {
+            _path = _path.substring(0, _path.length - 1);
+        }
+        else if(_path.indexOf('/') == -1) {
+            _path = System.appdir + _path;
+        }
+
+        System.launchpath[_pid] = _path;
+    
+        if( System.appCache[_path] ) {
+            if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
+            appData( System.appCache[_path] );
+        }
+        else {
+            try{
+                $.getJSON( _path + '/define.json', appData ).fail( () => {
+                    Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
+                } );
+            }
+            catch(error){
+                Notification.push( "System Error", error, "system" );
+            }
+        }
+    }
+
     this.clip = new function(){
         this.content = null;
         this.history = new Array();
@@ -1001,7 +1073,7 @@ const System = new function() {
 }
 
 const KWS = new function(){
-    this.version = "3.2.2";
+    this.version = "3.2.3";
     this.active = null;
 
     this.darkmode = false;
@@ -1034,10 +1106,16 @@ const KWS = new function(){
     }
 
     this.max = function( _pid ){
-        if( KWS.fullscreen.pid ){
-            Notification.push("最大化に失敗", "最大化しているウィンドウがあります。");
+        let _appcache = System.appCache[System.launchpath[_pid]];
+        if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
+            Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
             return;
         }
+        KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
+        KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
+        KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
+        KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
+        KWS.fullscreen.pid = _pid;
         $( "#wt"+_pid ).addClass("wtmaximize");
         $( "#w"+_pid ).css({
             "top": "0px",
@@ -1046,18 +1124,9 @@ const KWS = new function(){
         .addClass("windowmaximize")
         .css("z-index", KWS.windowIndex + 1);
         KWS.refreshWindowIndex();
-
-        KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
-        KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
-        KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
-        KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
-
         KWS.resize( _pid, System.display.width, System.display.height - 30 );
         $("footer").hide();
-        $("#kit-header-fullscreen").show().on("click", () => {
-            KWS.unmax( _pid );
-        });
-        KWS.fullscreen.pid = _pid;
+        $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
     }
 
     this.unmax = function( _pid ){
@@ -1065,8 +1134,8 @@ const KWS = new function(){
             Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
             return;
         }
-        $( "#wt"+_pid ).removeClass("wtmaximize");
-        $( "#w"+_pid ).css({
+        $('#wt'+_pid).removeClass("wtmaximize");
+        $('#w'+_pid).css({
             "top": KWS.fullscreen.prevTop,
             "left": KWS.fullscreen.prevLeft
         })
@@ -1079,6 +1148,10 @@ const KWS = new function(){
         KWS.fullscreen.prevHeight = null;
         KWS.fullscreen.prevTop = null;
         KWS.fullscreen.prevLeft = null;
+
+        if( !System.appCache[System.launchpath[_pid]].size.height ) {
+            System.qs(_pid)[0].style.height = "auto";
+        }
     }
 
     this.vacuum = function( _left, _top ){
@@ -1106,26 +1179,52 @@ const KWS = new function(){
         } );
         for( let i in array ){
             document.getElementById(array[i].id).style.zIndex = i;
+            let _pid = String(array[i].id).substring(1);
             if( i == num-1 ){
                 $("#"+array[i].id).addClass("windowactive");
-                $("#t"+String(array[i].id).substring(1)).addClass("t-active");
-                KWS.active = String(array[i].id).substring(1);
-                process[array[i].id.substring(1)].isactive = true;
+                $("#t"+_pid).addClass("t-active");
+                KWS.active = _pid;
+                process[_pid].isactive = true;
+                KWS.screenPrevSwitched = new Date();
+                localStorage.setItem('kit-screentime', JSON.stringify(KWS.screenTime));
             }
             else{
+                console.log(_pid + '外れました');
                 $("#"+array[i].id).removeClass("windowactive");
-                $("#t"+String(array[i].id).substring(1)).removeClass("t-active");
-                process[array[i].id.substring(1)].isactive = false;
+                $("#t"+_pid).removeClass("t-active");
+                process[_pid].isactive = false;
+                if( KWS.active == _pid ){
+                    let _diff = (new Date() - KWS.screenPrevSwitched);
+                    let _appid = process[_pid].id
+                    if( !KWS.screenTime[_appid] ) KWS.screenTime[_appid] = new Number();
+                    KWS.screenTime[_appid] += _diff;
+                }
             }
         }
         KWS.windowIndex = num;
     }
 
+    this.front = function( _pid ) {
+        $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
+        KWS.refreshWindowIndex();
+    }
+
     this.resize = function( _pid, _width, _height ){
         if( _width ) $("#winc"+_pid).css("width", _width)
         if( _height ) $("#winc"+_pid).css("height", _height);
     }
 
+    this.setTheme = function(_name){
+        localStorage.setItem('kit-theme', _name);
+        if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
+        else $('#kit-theme-file').attr('href', '');
+        System.moveDesktop(currentDesktop);
+    }
+
+    this.screenTime = new Object();
+
+    this.screenPrevSwitched = new Date();
+
     this.fusen = new function(){
         this.fid = 0;
         this.list = new Object();
@@ -1150,7 +1249,6 @@ const KWS = new function(){
                 }
             })
             $(".kit-fusen-textarea").off().on("change",function(){
-                Notification.push($(this).attr("data-fid"), $(this).val(), "debug");
                 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
                 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
             });
@@ -1197,35 +1295,64 @@ const Notification = new function() {
     this.goodnight = false;
     this.sound = null;
 
-    this.push = function( _title, _content, _app ) {
+    this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
+        let _nid = this.nid;
         if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
             return false;
         }
-        this.list[this.nid] = {
-            "title" : _title,
-            "content" : _content,
-            "app" : _app,
-            "time" : System.time.obj.toLocaleString()
+        Notification.list[_nid] = {
+            title: _title,
+            content: _content,
+            app: _app,
+            time: System.time.obj.toLocaleString(),
+            pid: _pid,
+            action: () => {
+                if( typeof _action == 'function' ) _action();
+                else if( _pid ) KWS.front(_pid);
+                $('#notifications').hide('drop', {direction: 'right'}, 300);
+            },
+            img: _img
         };
+        if( _pid && System.appCache[System.launchpath[_pid]] ){
+            _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
+        }
         if( !this.goodnight ){
             if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
-            $( "#last-notification-title" ).text("").text( _title );
-            $( "#last-notification-content" ).text("").text( _content );
-            $( "#last-notification-app" ).text("").text( _app );
-            $( "#last-notification" ).hide().show( "drop", {direction: "right"}, 300 );
-        }
-        $( "#notifications" ).append( "<div class='notis' id='nt" + this.nid + "'><span class='notis_close' id='nc" + this.nid + "'></span><span><span class='fas fa-comment-alt'></span>" + _title + "</span>" + _content + "<div class='notis_time'>" + System.time.obj.toLocaleString() + "</div></div>" );
-        $("#nc" + this.nid).on("click", function(){
-            let _nid = this.id.slice(2);
-            $("#nt" + _nid).fadeOut(300);
-            return false;
-        } );
-        $("#nt" + this.nid).on("click", function(){
-            let _nid = this.id.slice(2);
-            if( Notification.list[ _nid ].app != "system" ){
-                launch(Notification.list[ _nid ].app);
+            $('#last-notification-title').text('').text( _title );
+            $('#last-notification-content').text('').text( _content );
+            $('#last-notification-app').text('').html( _app );
+            $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
+            if( _img ) $('#last-notification-img').attr('src', _img).show();
+            else $('#last-notification-img').attr('src', '').hide();
+        }
+        let imgtag = '';
+        if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
+        $(`<div class='notis' id='nt${_nid}'>
+                ${imgtag}
+                <span class='notis_close' id='nc${_nid}'></span>
+                <div class='notis_app'>${_app}</div>
+                <span>${_title}</span>
+                ${_content}
+                <div class='notis_buttons'></div>
+                <div class='notis_time'>${System.time.obj.toTimeString()}</div>
+            </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
+        $(`#nc${_nid}`).on('click', (e) => {
+            e.stopPropagation();
+            $(`#nt${_nid}`).fadeOut(300);
+        });
+        $('#last-notification-buttons').html('');
+        if( _buttons ){
+            for( let b of _buttons ){
+                $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
+                    e.stopPropagation();
+                    b.func();
+                });
+                $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
+                    e.stopPropagation();
+                    b.func();
+                });
             }
-        } );
+        }
         this.nid ++;
         return (this.nid - 1);
     }
@@ -1236,12 +1363,17 @@ class App {
         App.e[_pid] = new Object();
         App.d[_pid] = new Object();
         
+        this.process = process[_pid];
+        this.cache = System.appCache[System.launchpath[_pid]];
+
         this.args = System.args[_pid];
         this.close = () => System.close(_pid);
-        this.d = () => App.d[_pid];
+        this.d = App.d[_pid];
         this.dom = (..._args) => System.dom(_pid, ..._args);
+        this.e =  App.e[_pid];
+        this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
         this.qs = (...args) => System.qs(_pid, ...args);
-        this.e = App.e[_pid];
+        this.front = () => KWS.front(_pid);
 
         this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
         this.data = (_name, _value) => App.data(_pid, _name, _value);
@@ -1278,11 +1410,13 @@ class App {
 
     static event( _pid, _name, _event ) {
         if( !App.e[_pid] ) App.e[_pid] = new Object();
-        App.e[_pid][_name] = _event;
+        if( !_event && App.e[_pid][_name] ) App.e[_pid][_name].call();
+        else App.e[_pid][_name] = _event;
         return App;
     }
 
     static getPath( _pid, _path ) {
+        if( String(_path)[0] != '/' ) _path = '/' + _path;
         return System.launchpath[_pid] + _path;
     }
 
@@ -1322,10 +1456,10 @@ class App {
                 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
             }
             if( i.hasAttribute("kit-alert") ){
-                $(i).on("click", ()=> System.alert( System.appCache[ process[_pid].id ].name, i.getAttribute("kit-alert") ) );
+                $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
             }
             if( i.hasAttribute("kit-launch") ){
-                $(i).on("click", ()=> launch( i.getAttribute("kit-launch") ) );
+                $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
             }
             if( i.hasAttribute("kit-close") ){
                 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
@@ -1374,13 +1508,19 @@ class App {
     }
 
     static load( _pid, _path ) {
-        S.dom(_pid).load( System.launchpath[_pid] +"/"+ _path, () => {
+        if( String(_path)[0] != '/' ) _path = '/' + _path;
+        _path = System.launchpath[_pid] + _path;
+        S.dom(_pid).load( _path, () => {
             App.kaf(_pid);
+            let _appcache = System.appCache[System.launchpath[_pid]];
+            if( !KWS.fullscreen.pid && !_appcache.size.height ) {
+                System.qs(_pid)[0].style.height = "auto";
+            }
         } );
         return App;
     }
 
-    static preventClose( _pid, _bool ) {
+    static preventClose( _pid, _bool = true ) {
         process[_pid].preventclose = _bool || true;
         return App;
     }
@@ -1388,5 +1528,6 @@ class App {
 
 App.d = new Object();
 App.e = new Object();
+App.version = "2.1.1";
 
 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;