OSDN Git Service

Add Methods to Push Rich Notifications [0.2.1]
[kit/kit.git] / system.js
1 "use strict";
2
3 //   _    _ _   
4 //  | | _(_) |_ 
5 //  | |/ / | __|
6 //  |   <| | |_ 
7 //  |_|\_\_|\__|
8 //
9 // THIS IS THE KIT KERNEL, KIT APPS FRAMEWORK AND KIT WINDOW SYSTEM
10 // http://web.kitit.ml/
11 // https://github.com/mtsgi/kit
12
13
14 $( document ).ready( kit );
15
16 function kit() {
17     S = System;
18
19     if( localStorage.getItem( "kit-pid" ) ) pid = localStorage.getItem( "kit-pid" );
20
21     if( !localStorage.getItem( "kit-username" ) ) localStorage.setItem( "kit-username", "ユーザー" );
22     $( "#kit-header-username" ).text( localStorage.getItem( "kit-username" ) );
23
24     if( localStorage.getItem( "kit-lock" ) == null ) localStorage.setItem( "kit-lock", "false" );
25
26     if( System.bootopt.get("safe") ) $( "#kit-wallpaper" ).css( "background","#404040" );
27     else if( localStorage.getItem( "kit-wallpaper" ) ) $( "#kit-wallpaper" ).css( "background", localStorage.getItem( "kit-wallpaper" ) ).css( "background-size", "cover" ).css( "background-position", "center" );
28
29     if( !localStorage.getItem( "kit-default-browser" ) ) localStorage.setItem( "kit-default-browser", "browser" );
30
31     if( localStorage.getItem("kit-fusen") ){
32         this.list = JSON.parse(localStorage.getItem("kit-fusen"));
33         for( let i in this.list ){
34             KWS.fusen.add(this.list[i]);
35         }
36     }
37     
38     if( localStorage.getItem("kit-darkmode") == "true" ){
39         KWS.darkmode = true;
40         $("#kit-darkmode").attr("href", "system/theme/kit-darkmode.css");
41         $(".winc-darkmode").addClass("kit-darkmode");
42     }
43
44     if( System.bootopt.get("safe") ){
45         $("#kit-theme-file").attr("href", "./system/theme/theme-light.css" );
46     }
47     else{
48         if( !localStorage.getItem( "kit-theme" ) ) localStorage.setItem( "kit-theme", "theme-default.css" );
49         $("#kit-theme-file").attr("href", "./system/theme/" + localStorage.getItem("kit-theme") );
50     }
51
52     if( !localStorage.getItem( "kit-appdir" ) ) localStorage.setItem( "kit-appdir", "./app/" );
53     S.appdir = localStorage.getItem( "kit-appdir" );
54
55     if( localStorage.getItem( "kit-installed" ) ) System.installed = JSON.parse( localStorage.getItem( "kit-installed" ) );
56
57     if( localStorage["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
58     if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
59
60     System.moveDesktop( "1" );
61
62     var clockmove;
63     if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
64     else  clockmove = setInterval( System.clock, 10 );
65
66     if ( localStorage.getItem("kit-shutted-down") == "false" ) {
67         Notification.push( "お知らせ", "kitは前回終了時、正しくシャットダウンされませんでした。", "system" );
68     }
69     localStorage.setItem("kit-shutted-down", false);
70
71     Notification.push( "kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system", null, null, 'documents/icon.png', [
72         {
73             label: 'kitについて',
74             func: () => launch( 'settings', {'view': 'about'} )
75         }
76     ]);
77
78     if( localStorage.getItem( "kit-startup" ) == undefined ) {
79         localStorage.setItem( "kit-startup", new Array( "welcome" ) );
80     }
81     System.startup = localStorage.getItem( "kit-startup" ).split( "," );
82     if( System.bootopt.get("safe") ){
83         Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
84         System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
85     }
86     else for( let i of System.startup ) if( i != "" ) launch( i );
87     
88     $("#kit-header-fullscreen").hide();
89
90     //イベントハンドラ
91     $( "#desktops" ).click( function() {
92         $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
93     } ).mousedown( function() {
94         $( ".window" ).css( "opacity", "0.6" );
95     } ).mouseup( function() {
96         $( ".window" ).css( "opacity", "1.0" );
97     } );
98     //タスク一覧
99     $( "#footer-tasks" ).click( function() {
100         if( $( "#kit-tasks" ).is( ":visible" ) ) {
101             $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
102         }
103         else {
104             $( "#task-ctx" ).fadeOut( 200 );
105             $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
106         }
107     } );
108     $.getJSON("system/testload.json").fail( () => {
109         $('#body').append(`<div id='wcors' class="window windowactive" style="top: 70px; left: 50px; width: calc(100% - 100px)">
110             <div class="wt">問題が発生しました</div>
111             <div class="winc">JSONデータ読み込みに失敗しました。<br>
112             クロスオリジン制約によりkitアプリケーションの動作が制限されている場合があります。<br>
113             詳細は<a class="kit-hyperlink" onclick="location.href = 'https://mtsgi.github.io/kitdocs/#/cors'">こちらの記事</a>をご確認ください。</div>
114         </div>`);
115         $('<kit-button-alt class="kit-block kit-text-c m">閉じる</kit-button-alt>').appendTo('#wcors .winc').on('click', ()=>{
116             $('#wcors').remove();
117         })
118     });
119     
120     $.getJSON("config/desktop.json", (data) => {
121         for( let i in data ){
122             $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
123         }
124         $(".desktop-icon").on("click", function(){
125             launch( $(this).attr("data-launch") );
126         });
127     }).fail( function() {
128         Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
129     } );
130     
131     $.getJSON("config/apps.json", System.initLauncher).fail( function() {
132         Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
133     } );
134     $( "#kit-tasks" ).delegate( ".task", "click", function() {
135         System.close( this.id.slice( 1 ) );
136         $( this ).hide();
137     } );
138     
139     $( "#footer-noti" ).click( function() {
140         $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
141         if( $( "#notifications" ).is( ":visible" ) ) {
142             $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
143         }
144         else {
145             $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
146         }
147     } );
148     $( "#last-notification-close" ).click( function() {
149         $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
150     } );
151     $("#notifications-dnp").prop("checked", false).on("change", ()=>{
152         if( $("#notifications-dnp").is(":checked") ){
153             Notification.goodnight = true;
154         }
155         else Notification.goodnight = false;
156     });
157     
158     $( ".power-button" ).click( function() {
159         $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
160         $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
161         $( "#kit-wallpaper" ).css( "filter", "blur(5px)" );
162         $( "footer, header, #launcher, #task-ctx, #kit-sightre, .dropdown, #desktop-" + currentDesktop ).hide();
163         $( "#kit-power" ).show();
164     } );
165     $( "#kit-power-back" ).click( function() {
166         $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
167         $( "footer, header, #desktop-" + currentDesktop ).show();
168         $( "#kit-power" ).hide();
169     } );
170     $( "#kit-power-shutdown" ).click( function() {
171         System.shutdown();
172     } );
173     $( "#kit-power-reboot" ).click( function() {
174         System.reboot();
175     } );
176     $( "#kit-power-suspend" ).click( function() {
177         location.reload();
178         $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
179         $( "#kit-power" ).fadeOut( 300 );
180         System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
181     } );
182     $( "#kit-power-lock" ).click( function() {
183         System.lock();
184     } );
185     $( "#lock-password" ).on( 'keypress', function( e ) {
186         if( e.which == 13 ) $( "#lock-unl" ).click();
187     } );
188     $( "#lock-unl" ).on( 'click', function() {
189         if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
190             $( "header, footer" ).show();
191             $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
192             $( "#lock-password" ).val( "" );
193             System.moveDesktop(1);
194         }
195         else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
196     } ).hover( function() {
197         $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
198     }, function() {
199         $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
200     } );
201     
202     $( "#launch" ).click( function() {
203         $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
204         if( $( "#launcher" ).is( ":visible" ) ) {
205             $( "#kit-wallpaper" ).css( "filter", "none" );
206             $( "#desktop-" + currentDesktop ).show();
207             $( "#launcher" ).hide();
208         }
209         else {
210             $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
211             $( "section, #task-ctx" ).hide();
212             $( "#launcher" ).show();
213         }
214     } );
215
216     //Sightre
217     $('#kit-header-sightre').on('click', () => {
218         if($('#kit-sightre').is( ":visible" )) {
219             $('#kit-sightre').fadeOut(300);
220         }
221         else {
222             $('#kit-sightre-results').html('');
223             $('#kit-sightre').show();
224             $('#kit-sightre-form').val('').focus();
225         }
226     });
227     let sightrePrevWord = '';
228     $('#kit-sightre-form').on('keypress', (e) => {
229         let _word = $('#kit-sightre-form').val();
230         if( e.which == 13 && _word ) {
231             if( _word == "kit" ){
232                 S.alert("", "<div style='text-align:left;'> _    _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>|   〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
233                 return;
234             }
235             let _args = null;
236             try {
237                 if( _word.split(",")[1] ) _args = JSON.parse( _word.split(",").slice(1).join().trim() );
238             }
239             catch(error) {
240                 Notification.push("引数の解釈に失敗", error, "system");
241             }
242             launch( _word.split(",")[0], _args );
243             sightrePrevWord = '';
244             $('#kit-sightre-form').val('');
245             $('#kit-sightre-results').html('');
246             $('#kit-sightre').fadeOut(300);
247         }
248     }).on('keydown keyup change', (e) => {
249         let _word = $('#kit-sightre-form').val();
250         if( e.which == 27 ) $('#kit-sightre').fadeOut(300);
251         else {
252             if( _word == sightrePrevWord ) return;
253             $('#kit-sightre-results').html('');
254             if( !_word ) return;
255             sightrePrevWord = _word;
256             for( let i in System.apps ){
257                 if( i.indexOf(_word) == 0 || S.apps[i].name.indexOf(_word) == 0 ){
258                     $(`<div class='kit-sightre-result -app'>
259                             <img class='--icon' src='${S.apps[i].icon}'/>
260                             <div class='--info'>
261                                 <div class='--name'>${S.apps[i].name}</div>
262                                 <div class='--desc'>kitアプリケーション - ${i}</div>
263                             </div>
264                             <div class='--open fa fa-arrow-right'></div>
265                         </div>`).appendTo('#kit-sightre-results').on('click', () => {
266                         launch(i);
267                         $('#kit-sightre-results').html('');
268                         $('#kit-sightre').fadeOut(300);
269                     });
270                 }
271             }
272             for( let i in System.userarea ){
273                 if( i.indexOf(_word) == 0 || i.indexOf(_word) == 0 ){
274                     $(`<div class='kit-sightre-result -file'>
275                             <i class="fa fa-file --icon"></i>
276                             <div class='--info'>
277                                 <div class='--name'>${i}</div>
278                                 <div class='--desc'>ファイル - 種類:${S.userarea[i].type} - ユーザー:${System.username}</div>
279                             </div>
280                             <div class='--open fa fa-arrow-right'></div>
281                         </div>`).appendTo('#kit-sightre-results').on('click', () => {
282                         System.open(i);
283                         $('#kit-sightre-results').html('');
284                         $('#kit-sightre').fadeOut(300);
285                     });
286                 }
287             }
288             $(`<div class='kit-sightre-result -link'>
289                     <i class="fa fa-search --icon"></i>
290                     <div class='--info'>
291                         <div class='--name'>${_word}</div>
292                         <div class='--desc'>をWebで検索</div>
293                     </div>
294                     <div class='--open fa fa-arrow-right'></div>
295                 </div>`).appendTo('#kit-sightre-results').on('click', () => {
296                 launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
297                 $('#kit-sightre-results').html('');
298                 $('#kit-sightre').fadeOut(300);
299             });
300             $(`<div class='kit-sightre-result -link'>
301                     <i class="fab fa-wikipedia-w --icon"></i>
302                     <div class='--info'>
303                         <div class='--name'>${_word}</div>
304                         <div class='--desc'>wikipediaの記事を表示</div>
305                     </div>
306                     <div class='--open fa fa-arrow-right'></div>
307                 </div>`).appendTo('#kit-sightre-results').on('click', () => {
308                 launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
309                 $('#kit-sightre-results').html('');
310                 $('#kit-sightre').fadeOut(300);
311             });
312         }
313     });
314
315     $("#dropdown-sound-slider").slider({
316         min: 0, max: 100, step: 1, value: 100,
317         change: (e, ui) => {
318             System.audio.level = ui.value;
319             $("#dropdown-sound-level").text(ui.value);
320             localStorage.setItem("kit-audio-level", ui.value);
321             for( let i in System.audio.list ){
322                 System.audio.list[i].volume = System.audio.level / 100;
323             }
324             if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
325             else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
326         }
327     });
328     if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
329
330     $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
331         if( $("#dropdown-sound-silent").is(":checked") ){
332             System.audio.silent = true;
333             $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
334         }
335         else{
336             System.audio.silent = false;
337             $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
338         }
339     });
340
341     $("#kit-header-user").on("click", ()=>{
342         launch("user");
343     });
344
345     $(":root section:not(#desktop-l)").on("contextmenu", function() {
346         let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
347         S.selectedElement = _ptelem;
348         S.selectedText = window.getSelection();
349         $( "#kit-context-input" ).val( S.selectedText );
350         if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
351         else $("#kit-contextgroup-text").show();
352         if( _ptelem[0].id == "desktop-" + currentDesktop ){
353             $("#kit-contextgroup-desktop").show();
354             $("#kit-contextgroup-elem").hide();
355         }
356         else{
357             $("#kit-contextgroup-desktop").hide();
358             $("#kit-contextgroup-elem").show();
359         }
360         $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
361         $("#kit-contextgroup-custom").hide();
362
363         let  _ctxid = _ptelem.attr("data-kit-contextid") || _ptelem.attr("kit-context");
364         if( _ctxid ){
365             $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
366             let  _ctxname = KWS.context[_ctxid].name || _ctxid; 
367             $("#kit-context-custom").text( _ctxname );
368             for( let i in KWS.context[_ctxid]){
369                 if( i == "name" ) continue;
370                 $("#kit-contextgroup-custom").append("<a id='kit-context-" + _ctxid + "-" + i + "'><span class='fa " + KWS.context[_ctxid][i].icon + "'></span> " + KWS.context[_ctxid][i].label +"</a>");
371                 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
372                     KWS.context[_ctxid][i].function();
373                     $("#kit-context").fadeOut(300);
374                 });
375             }
376         }
377         if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
378         $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
379         $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
380         return false;
381     });
382     $("#kit-context-open").on("click", function(){
383         S.alert("要素", S.selectedElement.clone());
384     });
385     $("#kit-context-save").on("click", function(){
386         S.obj2img( S.selectedElement , true );
387     });
388     $( "#kit-context-search" ).on("click", function(){
389         $("#kit-context").fadeOut(300);
390         launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#kit-context-input" ).val() } );
391     });
392     $( "#kit-context-input" ).keypress( function( e ) {
393         if( e.which == 13 ) $( "#kit-context-search" ).click();
394     } );
395     $("#kit-context a").on("click", function(){
396         $("#kit-context").fadeOut(300);
397     });
398     $("#kit-context-vacuum").on("click", function(){
399         for( let i in process ){
400             KWS.vacuum( S.mouseX, S.mouseY );    
401         }
402         setTimeout(() => {
403             $(".window").css("transition", "none");
404         }, 500);
405     });
406     $("#kit-context-fusen").on("click", function(){
407         KWS.fusen.add("");
408     });
409
410
411     $("section").on("click", function(){
412         $("#kit-context").fadeOut(300);
413     })
414
415     $( document ).delegate( "a", "click", function() {
416         if( this.href ) {
417             launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
418             return false;
419         }
420     } ).on("mousemove", function(event){
421         System.mouseX = event.clientX;
422         System.mouseY = event.clientY;
423     }).delegate( ".textbox", "keypress", function( e ) {
424         if( e.which == 13 && this.id ){
425             if( $("#" + this.id + " + .kit-button").length ){
426                 Notification.push("debug", this.id, "system");
427                 $("#" + this.id + " + .kit-button").click();
428             }
429             else if( $("#" + this.id + " + kit-button").length ){
430                 Notification.push("debug", this.id, "system");
431                 $("#" + this.id + " + kit-button").click();
432             }
433         }
434     } );
435
436     window.onresize = () => {
437         System.display.width = window.innerWidth;
438         System.display.height = window.innerWidth;
439
440         if( KWS.fullscreen.pid ){
441             KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
442         }
443     }
444
445     if( localStorage.getItem( "kit-lock" ) == "true" ){
446         $("section").hide();
447         setTimeout(() =>  System.lock(), 100);
448     }
449 }
450
451 function launch( str, args, dir ) {
452     let _pid = pid;
453     System.args[_pid] = args;
454     System.launchpath[_pid] = dir || System.appdir + str;
455
456     if( System.appCache[str] ) {
457         if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
458         appData( System.appCache[str] );
459     }
460     else {
461         try{
462             $.getJSON( S.launchpath[_pid] + '/define.json', appData ).fail( () => {
463                 Notification.push('kitアプリをロードできません。', `${str}を展開できませんでした。`, 'system');
464             } );
465         }
466         catch(error){
467             Notification.push( "System Error", error, "system" );
468         }
469     }
470 }
471
472 function appData( data ) {
473     let _pid = pid;
474     process[String( _pid )] = {
475         id: data.id,
476         time: System.time.obj.toLocaleString(),
477         isactive: false,
478         preventclose: false,
479         title: data.name
480     };
481     System.appCache[data.id] = data;
482     app = new App(_pid);
483     let _taskAppend = `<span id='t${_pid}'>`;
484     if( data.icon && data.icon != "none" ) _taskAppend += `<img src='${S.launchpath[_pid]}/${data.icon}'>`;
485     _taskAppend += `<span id='tname${_pid}'>${data.name}<span></span>`;
486     $( "#tasks" ).append( _taskAppend );
487     $( "#t" + _pid ).addClass( "task" ).on({
488         click: function() {
489             if( $(this).hasClass("t-active") || $(this).hasClass("task-min") ) KWS.min( _pid );
490             else{
491                 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
492                 KWS.refreshWindowIndex();
493             }
494         },
495         mouseenter: function() {
496             $( "#task-ctx-name" ).text( data.name );
497             if( data.icon && data.icon != "none" ) $( "#task-ctx-img" ).attr( "src", System.launchpath[_pid] + "/" + data.icon );
498             else $( "#task-ctx-img" ).hide();
499             $( "#task-ctx-ver" ).text( data.version + "/pid:" + _pid );
500             $( "#task-ctx-info" ).off().on( "click", function() { System.appInfo( _pid )} );
501             $( "#task-ctx-sshot" ).off().on( "click", function() { S.screenshot(_pid, true) } );
502             $( "#task-ctx-min" ).off().on( "click", function() { KWS.min( String(_pid) ) } );
503             if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
504             else $( "#task-ctx-front" ).show();
505             $( "#task-ctx-front" ).off().on( "click", function() {
506                 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
507                 KWS.refreshWindowIndex();
508             } );
509             $( "#task-ctx-close" ).off().on("click", () => System.close(_pid));
510             $( "#task-ctx-kill" ).off().on("click", () => System.kill( data.id));
511             const _ctxleft = $(this).offset().left, _ctxtop = window.innerHeight - $(this).offset().top;
512             if( _ctxleft != $( "#task-ctx" ).offset().left ) $( "#task-ctx" ).hide();
513             $( "#task-ctx" ).css( "left", _ctxleft ).css( "bottom", _ctxtop ).show();
514         }
515     } );
516     $( "section, #kit-tasks" ).on( "mouseenter", function() {
517         $( "#task-ctx" ).fadeOut( 200 );
518     } );
519     $( "#t" + _pid ).on({
520         mouseenter: () => {
521             prevWindowIndex = $( "#w" + _pid ).css( "z-index" );
522             $( "#w" + _pid ).addClass( "win-highlight" );
523         },
524         mouseleave: () => $( "#w" + _pid ).removeClass( "win-highlight" )
525     });
526
527     let _windowAppend = "<div id='w" + _pid + "'><div id='wt" + _pid + "' class='wt'><i class='wmzx'><span id='wm" + _pid + "'></span>";
528     if( data.support && data.support['fullscreen'] == true ) _windowAppend += "<span id='wz" + _pid + "'></span>";
529     _windowAppend += "<span id='wx" + _pid + "'></span></i>";
530     if( data.icon && data.icon != "none" ) _windowAppend += "<img src='" + S.launchpath[_pid] + "/" + data.icon + "'>";
531     _windowAppend += "<span id='wtname" + _pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + _pid + "'></div></div>";
532     $( "#desktop-" + currentDesktop ).append( _windowAppend );
533
534     if( data.support && data.support['darkmode'] == true ) $("#winc"+_pid).addClass("winc-darkmode");
535     if( KWS.darkmode ) $("#winc"+_pid).addClass("kit-darkmode");
536
537     if( data.size ){
538         $("#winc"+_pid).css("width", data.size.width).css("height", data.size.height);
539     }
540     if( data.resize ){
541         let _minwidth = 200, _minheight = 40;
542         if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
543         if( data.resize.minHeight ) _minheight = data.resize.minHeight;
544         $("#winc"+_pid).windowResizable({
545             minWidth: _minwidth,
546             minHeight: _minheight
547         });
548     }
549
550     let windowPos = 50 + ( _pid % 10 ) * 20;
551     KWS.windowIndex ++;
552     $( "#w"+_pid ).addClass( "window" ).pep({
553         elementsWithInteraction: ".winc, .ui-resizable-handle",
554         useCSSTranslation: false,
555         disableSelect: false,
556         shouldEase:     true,
557         initiate: function(){
558             $(this.el).addClass("ui-draggable-dragging");
559             KWS.windowIndex ++;
560             this.el.style.zIndex = KWS.windowIndex;
561             KWS.refreshWindowIndex();
562         },
563         stop: function(){
564             this.el.style.transition = "none";
565             $(this.el).removeClass("ui-draggable-dragging");
566         }
567     }).on( "mousedown", function(){
568         $(".window").css( "transition", "none" );
569         $(this).css("z-index", KWS.windowIndex + 1);
570         KWS.refreshWindowIndex();
571     } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index",  KWS.windowIndex );
572     KWS.refreshWindowIndex();
573     $( `#wm${_pid}` ).addClass( "wm fa fa-window-minimize" ).on("click", () => KWS.min( _pid ) );
574     $( `#wz${_pid}` ).addClass( "wz fas fa-square" ).on("click", () => KWS.max( _pid ) );
575     $( `#wx${_pid}` ).addClass( "wx fa fa-times" ).on("click", () => System.close( _pid )  );
576     $( "#winc" + _pid ).resizable( {
577         minWidth: "200"
578     } ).load( System.launchpath[_pid] + "/" + data.view, (r, s, x) => {
579         if( s == "error" ){
580             Notification.push("起動に失敗:" + x.status, x.statusText);
581             return false;
582         }
583         if( !data.script || data.script != "none" ) $.getScript( System.launchpath[_pid] + "/" + data.script, () => {
584             if( !data.support || data.support['kaf'] != false ) App.kaf(_pid);
585             pid++;
586         }).fail( () => {
587             App.kaf(_pid);
588             pid++;
589         });
590         else if( !data.support || data.support['kaf'] != false ){
591             App.kaf(_pid);
592             pid++;
593         }
594         else pid++;
595         if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
596             $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
597         }
598         localStorage.setItem( "kit-pid", pid );
599     } );
600 }
601
602 const System = new function() {
603     this.version = "0.2.1";
604     this.username = localStorage.getItem("kit-username");
605     this.appdir = localStorage.getItem("kit-appdir");
606     this.loc = { ...location };
607
608     this.bootopt = new URLSearchParams(location.search);
609
610     this.mouseX = 0;
611     this.mouseY = 0;
612
613     this.display = {
614         "width": window.innerWidth,
615         "height": window.innerHeight
616     }
617
618     this.selectedElement = null;
619     this.selectedText = null;
620
621     this.dom = function(_pid, ..._elems) {
622         let q = "";
623         if( !_elems.length ) q = ",#winc" + _pid;
624         else for( let i of _elems ){
625             q += ",#winc" + _pid + " " + i;
626         }
627         return $( q.substring(1) );
628     }
629
630     this.qs = ( _pid, ..._elems ) => {
631         let q = "";
632         if( !_elems.length ) q = ",#winc" + _pid;
633         else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
634         return document.querySelectorAll( q.substring(1) )
635     }
636
637     this.userarea = new Object();
638     this.recycle = new Object();
639
640     this.appCache = {};
641     //アプリ引数
642     this.args = {};
643     //アプリ起動パス
644     this.launchpath = {};
645
646     this.support = $.support;
647     this.debugmode = false;
648
649     this.battery = null;
650
651     this.log = new Array();
652     this.noop = () => {}
653
654     this.setBattery = function(){
655         if( navigator.getBattery ) navigator.getBattery().then((e)=>{
656             let _lv =  e.level * 100;
657             System.battery = _lv;
658             return _lv;
659         });
660     }
661
662     this.screenshot = function( _pid, _popup ){
663         let _elem = document.querySelector("body");
664         if( _pid ) _elem = document.querySelector("#w"+_pid);
665         html2canvas( _elem ).then(canvas => {
666             if( _popup ){
667                 canvas.style.border = "1px solid #909090";
668                 S.save( canvas.toDataURL("image/png"), "image" );
669             }
670             return canvas;
671         });
672     }
673
674     this.obj2img = function( _obj, _popup ){
675         let _elem = _obj[0];
676         html2canvas( _elem ).then(canvas => {
677             if( _popup ){
678                 canvas.style.border = "1px solid #909090";
679                 S.save( canvas.toDataURL("image/png"), "image" );
680             }
681             return canvas;
682         });
683     }
684
685     this.save = function(data, type){
686         launch("fivr", { "save" : data, "type" : type });
687     }
688
689     this.open = function(filename){
690         launch("fivr", { "open" : filename });
691     }
692
693     this.preventClose = function( _pid ){
694         if( !process[_pid] ) return false;
695         process[_pid].preventclose = true;
696         return true;
697     }
698     
699     this.shutdown = function(_opt) {
700         $( "#last-notification-close" ).click();
701         $( "#kit-power-back" ).click();
702         for( let i in process ) {
703             if( process[i].preventclose == true ){
704                 S.dialog( "シャットダウンの中断", "pid" + System.appCache[process[i].id].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
705                     process[i].preventclose = false;
706                     System.shutdown();
707                 } );
708                 return false;
709             }
710             else System.close( i );
711         }
712         $( "section" ).hide();
713         $( "body" ).css( "background-color", "black" );
714         $( "header, footer" ).fadeOut( 300 );
715         $( "#kit-wallpaper" ).fadeOut( 1500 );
716         if( _opt == "reboot" ) location.href = "autorun.html";
717         localStorage.setItem("kit-shutted-down", true);
718     }
719
720     this.reboot = function() {
721         System.shutdown("reboot");
722     }
723
724     this.lock = function(){
725         System.moveDesktop( "l" );
726
727         $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
728         $( "section, header, footer" ).css( "filter", "none" );
729         $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
730         $( "header, footer, #kit-power" ).hide();
731
732         $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
733         if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
734         else $( "#lock-password" ).hide();
735     }
736
737     this.alert = function( title, content, winname ) {
738         launch( "alert", [title, content, winname] );
739     }
740
741     this.dialog = function( title, content, func ){
742         launch("dialog", {
743             "title": title,
744             "content": content,
745             "func": func
746         })
747     }
748
749     this.appInfo = function( _pid ){
750         let _title = "", _content = "";
751         let ac = System.appCache[process[_pid].id];
752         let _lp = System.launchpath[_pid];
753         if( ac ){
754             _title = ac.name + " " + ac.version;
755             if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
756             for( let i in ac ){
757                 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
758             }
759             _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
760         }
761         else _title = "取得に失敗しました";
762         System.alert( _title, _content );
763     }
764
765     this.apps = new Object();
766     this.installed = new Array();
767
768     this.close = function( _str ) {
769         let _pid = String( _str );
770         $( "#w" + _pid ).remove();
771         $( "#t" + _pid ).remove();
772         $( "#task-ctx" ).hide();
773         delete process[_pid];
774         KWS.refreshWindowIndex();
775     }
776
777     this.kill = function( _str ){
778         for( let _pid in process ) {
779             if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
780         }
781     }
782     
783     this.vacuum = function( _left, _top ){
784         KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
785     }
786
787     this.time = {
788         "obj" : new Date(),
789         "y" : "1970",
790         "m" : "1",
791         "d" : "1",
792         "h" : "00",
793         "i" : "00",
794         "s" : "00",
795         "ms" : "0"
796     }
797
798     this.clock = function() {
799         let DD = new Date();
800         S.time.obj = DD;
801         let Year = DD.getFullYear();
802         S.time.day = DD.getDay();
803         S.time.y = Year;
804         let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
805         S.time.m = Month;
806         let DateN = ( "00" + DD.getDate() ).slice( -2 );
807         S.time.d = DateN;
808         let Hour = ( "00" + DD.getHours() ).slice( -2 );
809         S.time.h = Hour;
810         let Min = ( "00" + DD.getMinutes() ).slice( -2 );
811         S.time.i = Min;
812         let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
813         S.time.s = Sec;
814         $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
815         let MS = DD.getMilliseconds();
816         S.time.ms = MS;
817         let circle = {
818             outer: { radius: .9, color: "transparent" },
819             inner: { radius: .85, color: "transparent" }
820         }
821         let lines = {
822             long: { from: .8, to: .7, width: 2, color: "#303030" },
823             short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
824         }
825         let hands = {
826             hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
827             minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
828             second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
829         }
830         let canvas = $(".dropdown-clock-canvas")[0];
831         canvas.width = "200", canvas.height = "200";
832         let context = canvas.getContext("2d");
833         let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
834         let radius = Math.min(center.x, center.y), angle, len;
835         context.beginPath();context.fillStyle = circle.outer.color;
836         context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
837         context.fill();context.beginPath();context.fillStyle = circle.inner.color;
838         context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
839         context.fill();
840         for( let i=0; i<60; i++ ){
841             angle = Math.PI * i / 30;
842             context.beginPath();
843             let line = ( i%5 == 0 ) ? lines.long : lines.short;
844             context.lineWidth = line.width, context.strokeStyle = line.color;
845             context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
846             context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
847             context.stroke();
848         }
849         angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
850         context.beginPath(), context.lineWidth = hands.hour.width;
851         context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
852         context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
853         context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
854         angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
855         context.beginPath(), context.lineWidth = hands.minute.width;
856         context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
857         context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
858         context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
859         angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
860         context.beginPath(), context.lineWidth = hands.second.width;
861         context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
862         context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
863         context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
864     }
865
866     this.changeWallpaper = function( str ) {
867         $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
868         localStorage.setItem( "kit-wallpaper", str )
869     }
870
871     this.moveDesktop = function( str ) {
872         str = String( str );
873         $( "section" ).hide();
874         $( "#desktop-" + str ).show();
875         $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
876         currentDesktop = str;
877     }
878
879     this.avoidMultiple = function( _pid, _alert ) {
880         let _id = process[_pid].id;
881         let _cnt = 0;
882         for( let i in process ) {
883             if( process[i].id == _id ) _cnt += 1;
884         }
885         Notification.push( "debug", _cnt );
886         if( _cnt > 1 ) {
887             System.close( _pid );
888             if( !_alert ){
889                 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
890             }
891         }
892         return _cnt;
893     }
894
895     this.resizable = function( _pid, _elem, _width, _height ){
896         let E = ".winc";
897         if( _elem ) E = String( _elem );
898         if( !_width ) _width = null;
899         if( !_height ) _height = "100";
900         $("#w" + _pid).resizable({
901             alsoResize: "#w" + _pid + " " + E,
902             minWidth: _width,
903             minHeight: _height
904         });
905     }
906
907     this.initLauncher = function(data){
908         $("#launcher-apps").html("");
909         System.apps = data;
910         for( let i in data ){
911             $("#launcher-apps").append("<div class='launcher-app' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
912         }
913         if( !System.bootopt.get("safe") ){
914             for( let i of System.installed ){
915                 $("#launcher-apps").append("<div class='launcher-app' data-define-path='" + i.path + "' data-define-id='" + i.id + "'><img src='" + i.icon + "'>" + i.name + "</div>");
916             }
917         }
918         $(".launcher-app").on("click", function(){
919             $("#launch").click();
920             if( $(this).attr("data-launch") ) launch( $(this).attr("data-launch") );
921             else if( $(this).attr("data-define-path") ){
922                 launch( $(this).attr("data-define-id"), null, $(this).attr("data-define-path") );
923             };
924         });
925     }
926
927     this.clip = new function(){
928         this.content = null;
929         this.history = new Array();
930
931         this.set = function( content ){
932             this.content = content;
933             this.history.push(content);
934             return content;
935         }
936         this.get = ()=>{ return this.content }
937     }
938
939     this.config = new function(){
940         this.apps = new Object();
941     }
942
943     this.audio = new function(){
944         this.level = localStorage["kit-audio-level"] || 100;
945         this.silent = false;
946
947         this.list = new Array();
948
949         this.volume = function( _level ){
950             $("#dropdown-sound-slider").slider("value", _level);
951         }
952
953         this.play = function( _audioid, _src ){
954             if( !System.audio.list[_audioid] ){
955                 System.audio.list[_audioid] = new Audio(_src);
956                 System.audio.list[_audioid].volume = System.audio.level / 100;
957             }
958             System.audio.list[_audioid].play();
959         }
960
961         this.get = function( _audioid ){
962             return System.audio.list[_audioid];
963         }
964
965         this.pause = function( _audioid ){
966             System.audio.list[_audioid].pause();
967         }
968
969         this.stop = function( _audioid ){
970             System.audio.list[_audioid].pause();
971             System.audio.list[_audioid] = null;
972         }
973
974         this.seek = function( _audioid, _time ){
975             System.audio.list[_audioid].fastSeek(_time);
976         }
977
978         this.mute = function( _audioid, _bool ){
979             System.audio.list[_audioid].muted = _bool;
980         }
981     }
982 }
983
984 const KWS = new function(){
985     this.version = "3.2.2";
986     this.active = null;
987
988     this.darkmode = false;
989
990     this.changeWindowTitle = function( _pid, _str ){
991         $("#tname"+_pid).text( _str );
992         $("#wtname"+_pid).text( _str );
993     }
994
995     this.min = function( _str ) {
996         let _pid = String( _str );
997         if( $( "#w" + _pid ).is( ":visible" ) ) {
998             $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
999             $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1000             $( "#t" + _pid ).addClass( "task-min" );
1001         }
1002         else {
1003             $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1004             $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1005             $( "#t" + _pid ).removeClass( "task-min" );
1006         }
1007     }
1008
1009     this.fullscreen = {
1010         "pid": null,
1011         "prevWidth": null,
1012         "prevHeight": null,
1013         "prevTop": 0,
1014         "prevLeft": 0
1015     }
1016
1017     this.max = function( _pid ){
1018         if( KWS.fullscreen.pid ){
1019             Notification.push("最大化に失敗", "最大化しているウィンドウがあります。");
1020             return;
1021         }
1022         $( "#wt"+_pid ).addClass("wtmaximize");
1023         $( "#w"+_pid ).css({
1024             "top": "0px",
1025             "left": "0px"
1026         })
1027         .addClass("windowmaximize")
1028         .css("z-index", KWS.windowIndex + 1);
1029         KWS.refreshWindowIndex();
1030
1031         KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1032         KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1033         KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1034         KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1035
1036         KWS.resize( _pid, System.display.width, System.display.height - 30 );
1037         $("footer").hide();
1038         $("#kit-header-fullscreen").show().on("click", () => {
1039             KWS.unmax( _pid );
1040         });
1041         KWS.fullscreen.pid = _pid;
1042     }
1043
1044     this.unmax = function( _pid ){
1045         if( _pid != KWS.fullscreen.pid ){
1046             Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1047             return;
1048         }
1049         $( "#wt"+_pid ).removeClass("wtmaximize");
1050         $( "#w"+_pid ).css({
1051             "top": KWS.fullscreen.prevTop,
1052             "left": KWS.fullscreen.prevLeft
1053         })
1054         .removeClass("windowmaximize");
1055         $("footer").show();
1056         $("#kit-header-fullscreen").hide().off();
1057         KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1058         KWS.fullscreen.pid = null;
1059         KWS.fullscreen.prevWidth = null;
1060         KWS.fullscreen.prevHeight = null;
1061         KWS.fullscreen.prevTop = null;
1062         KWS.fullscreen.prevLeft = null;
1063     }
1064
1065     this.vacuum = function( _left, _top ){
1066         for( let i in process ){
1067             $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1068         }
1069         setTimeout(() => {
1070             $(".window").css("transition", "none");
1071         }, 500);
1072     }
1073
1074     this.active = null;
1075     this.windowIndex = 1;
1076
1077     this.refreshWindowIndex = function(){
1078         let num = $(".window").length;
1079         let array = new Array();
1080         let obj = new Object();
1081         for( let i = 0; i < num; i++ ){
1082             obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1083             array.push( obj );
1084         };
1085         array.sort( (a,b) => {
1086             return Number(a.zindex - b.zindex);
1087         } );
1088         for( let i in array ){
1089             document.getElementById(array[i].id).style.zIndex = i;
1090             if( i == num-1 ){
1091                 $("#"+array[i].id).addClass("windowactive");
1092                 $("#t"+String(array[i].id).substring(1)).addClass("t-active");
1093                 KWS.active = String(array[i].id).substring(1);
1094                 process[array[i].id.substring(1)].isactive = true;
1095             }
1096             else{
1097                 $("#"+array[i].id).removeClass("windowactive");
1098                 $("#t"+String(array[i].id).substring(1)).removeClass("t-active");
1099                 process[array[i].id.substring(1)].isactive = false;
1100             }
1101         }
1102         KWS.windowIndex = num;
1103     }
1104
1105     this.front = function( _pid ) {
1106         $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1107         KWS.refreshWindowIndex();
1108     }
1109
1110     this.resize = function( _pid, _width, _height ){
1111         if( _width ) $("#winc"+_pid).css("width", _width)
1112         if( _height ) $("#winc"+_pid).css("height", _height);
1113     }
1114
1115     this.fusen = new function(){
1116         this.fid = 0;
1117         this.list = new Object();
1118
1119         this.add = function(_text){
1120             KWS.fusen.list[KWS.fusen.fid] = String(_text);
1121             $("#desktop-"+currentDesktop).append("<div class='kit-fusen' id='kit-f"+KWS.fusen.fid+"'><i class='fa fa-quote-left'></i><textarea class='kit-fusen-textarea kit-selectable' data-fid='"+KWS.fusen.fid+"' kit-context='fusen'>"+_text+"</textarea></div>");
1122             $("#kit-f"+KWS.fusen.fid).css({
1123                 "left": Number(KWS.fusen.fid)*40 + 20,
1124                 "top": Number(KWS.fusen.fid)*10 + 100,
1125             }).pep({
1126                 elementsWithInteraction: ".kit-fusen-textarea",
1127                 useCSSTranslation: false,
1128                 disableSelect: false,
1129                 shouldEase:     true,
1130                 initiate: function(){
1131                     $(this.el).css("ui-opacity", "0.7");
1132                 },
1133                 stop: function(){
1134                     this.el.style.transition = "none";
1135                     $(this.el).css("ui-opacity", "1.0");
1136                 }
1137             })
1138             $(".kit-fusen-textarea").off().on("change",function(){
1139                 Notification.push($(this).attr("data-fid"), $(this).val(), "debug");
1140                 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1141                 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1142             });
1143             localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1144             KWS.fusen.fid++;
1145         }
1146
1147         this.remove = function(_fid){
1148             delete KWS.fusen.list[_fid];
1149             localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1150             $("#kit-f"+_fid).remove();
1151         }
1152     }
1153
1154     this.addCustomContext = function( _elem, _contextid, _obj ){
1155         KWS.context[_contextid] = _obj;
1156     }
1157
1158     this.context = {
1159         "fusen" : {
1160             "name" : "ふせん",
1161             "delete" : {
1162                 "label" : "ふせんを削除",
1163                 "icon" : "fa-trash-alt",
1164                 "function" : function(){
1165                     KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1166                 }
1167             },
1168             "copy" : {
1169                 "label" : "ふせんを複製",
1170                 "icon" : "fa-copy",
1171                 "function" : function(){
1172                     KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1173                 }
1174             }
1175         }
1176     }
1177 }
1178
1179 const Notification = new function() {
1180     this.nid = 0;
1181     this.list = new Object();
1182
1183     this.goodnight = false;
1184     this.sound = null;
1185
1186     this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1187         let _nid = this.nid;
1188         if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1189             return false;
1190         }
1191         Notification.list[_nid] = {
1192             title: _title,
1193             content: _content,
1194             app: _app,
1195             time: System.time.obj.toLocaleString(),
1196             pid: _pid,
1197             action: () => {
1198                 if( typeof _action == 'function' ) _action();
1199                 else if( _pid ) KWS.front(_pid);
1200                 $('#notifications').hide('drop', {direction: 'right'}, 300);
1201             },
1202             img: _img
1203         };
1204         if( _pid && System.appCache[_app] ){
1205             _app = `<img src='${System.launchpath[_pid]}/${System.appCache[_app].icon}'>${_app}`;
1206         }
1207         if( !this.goodnight ){
1208             if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1209             $('#last-notification-title').text('').text( _title );
1210             $('#last-notification-content').text('').text( _content );
1211             $('#last-notification-app').text('').html( _app );
1212             $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1213             if( _img ) $('#last-notification-img').attr('src', _img).show();
1214             else $('#last-notification-img').attr('src', '').hide();
1215         }
1216         let imgtag = '';
1217         if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1218         $(`<div class='notis' id='nt${_nid}'>
1219                 ${imgtag}
1220                 <span class='notis_close' id='nc${_nid}'></span>
1221                 <div class='notis_app'>${_app}</div>
1222                 <span>${_title}</span>
1223                 ${_content}
1224                 <div class='notis_buttons'></div>
1225                 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1226             </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1227         $(`#nc${_nid}`).on('click', (e) => {
1228             e.stopPropagation();
1229             $(`#nt${_nid}`).fadeOut(300);
1230         });
1231         $('#last-notification-buttons').html('');
1232         if( _buttons ){
1233             for( let b of _buttons ){
1234                 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1235                     e.stopPropagation();
1236                     b.func();
1237                 });
1238                 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1239                     e.stopPropagation();
1240                     b.func();
1241                 });
1242             }
1243         }
1244         this.nid ++;
1245         return (this.nid - 1);
1246     }
1247 }
1248
1249 class App {
1250     constructor(_pid) {
1251         App.e[_pid] = new Object();
1252         App.d[_pid] = new Object();
1253         
1254         this.process = process[_pid];
1255         this.info = System.appCache[process[_pid].id];
1256
1257         this.args = System.args[_pid];
1258         this.close = () => System.close(_pid);
1259         this.d = App.d[_pid];
1260         this.dom = (..._args) => System.dom(_pid, ..._args);
1261         this.e =  App.e[_pid];
1262         this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1263         this.qs = (...args) => System.qs(_pid, ...args);
1264         this.front = () => KWS.front(_pid);
1265
1266         this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1267         this.data = (_name, _value) => App.data(_pid, _name, _value);
1268         this.event = (_name, _event) => App.event(_pid, _name, _event);
1269         this.getPath = _path => App.getPath(_pid, _path);
1270         this.kaf = () => App.kaf(_pid);
1271         this.load = _path => App.load(_pid, _path);
1272         this.preventClose = _bool => App.preventClose(_pid, _bool);
1273     }
1274
1275     static changeWindowTitle( _pid, _t ) {
1276         $( "#tname"+_pid ).text( _t );
1277         $( "#wtname"+_pid ).text( _t );
1278         process[_pid].title = _t;
1279         return App;
1280     }
1281
1282     static context( _cid, _obj ) {
1283         KWS.context[ _cid ] = _obj;
1284         return App;
1285     }
1286
1287     static data( _pid, _name, _value ) {
1288         if( _value !== undefined ) {
1289             S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1290             S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1291             if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1292             else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1293             return App.d[_pid][_name] = _value;
1294         }
1295         else if( _name ) return App.d[_pid][_name];
1296         else return App.d[_pid];
1297     }
1298
1299     static event( _pid, _name, _event ) {
1300         if( !App.e[_pid] ) App.e[_pid] = new Object();
1301         App.e[_pid][_name] = _event;
1302         return App;
1303     }
1304
1305     static getPath( _pid, _path ) {
1306         return System.launchpath[_pid] + _path;
1307     }
1308
1309     static kaf( _pid ) {
1310         let attrs = [
1311             "[kit-ref]",
1312             "[kit-e]",
1313             "[kit-src]",
1314             "[kit-alert]",
1315             "[kit-launch]",
1316             "[kit-close]",
1317             "[kit-text]",
1318             "[kit-html]",
1319             "[kit\\:bind]",
1320             "[kit\\:observe]",
1321             "[kit\\:value]",
1322             "[kit-value]",
1323             "[kit-color]",
1324             "[kit\\:if]",
1325             "[kit-if]"
1326         ]
1327         const PID = _pid;
1328         const DATA = App.data(_pid);
1329         const ARGS = System.args[_pid];
1330         for( let i of S.qs(_pid, ...attrs) ){
1331             if( i.hasAttribute("kit-ref") ){
1332                 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1333             }
1334             if( i.hasAttribute("kit-e") ){
1335                 let _eqs = i.getAttribute("kit-e").split(",");
1336                 for( let k of _eqs ){
1337                     let _eq = k.split(" ");
1338                     $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1339                 }
1340             }
1341             if( i.hasAttribute("kit-src") ){
1342                 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1343             }
1344             if( i.hasAttribute("kit-alert") ){
1345                 $(i).on("click", ()=> System.alert( System.appCache[ process[_pid].id ].name, i.getAttribute("kit-alert") ) );
1346             }
1347             if( i.hasAttribute("kit-launch") ){
1348                 $(i).on("click", ()=> launch( i.getAttribute("kit-launch") ) );
1349             }
1350             if( i.hasAttribute("kit-close") ){
1351                 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1352             }
1353             if( i.hasAttribute("kit-text") ){
1354                 $(i).text( eval(i.getAttribute("kit-text")) );
1355             }
1356             if( i.hasAttribute("kit-html") ){
1357                 $(i).html( eval(i.getAttribute("kit-html")) );
1358             }
1359             if( i.hasAttribute("kit:bind") ){
1360                 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1361                 $(i).on('keydown keyup keypress change', () => {
1362                     let _name = i.getAttribute("kit:bind");
1363                     App.d[_pid][_name] = i.value;
1364                     S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1365                     if( i.value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1366                     else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1367                 } );
1368             }
1369             if( i.hasAttribute("kit:observe") ){
1370                 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1371             }
1372             if( i.hasAttribute("kit:value") ){
1373                 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1374             }
1375             if( i.hasAttribute("kit-value") ){
1376                 $(i).val( eval(i.getAttribute("kit-value")) );
1377             }
1378             if( i.hasAttribute("kit-color") ){
1379                 $(i).css('color', i.getAttribute("kit-color"));
1380             }
1381             if( i.hasAttribute("kit:if") ){
1382                 if( App.d[_pid][i.getAttribute("kit:if")] ){
1383                     $(i).show();
1384                 }
1385                 else $(i).hide();
1386             }
1387             if( i.hasAttribute("kit-if") ){
1388                 if( eval( i.getAttribute("kit-if")) ){
1389                     $(i).show();
1390                 }
1391                 else $(i).hide();
1392             }
1393         }
1394     }
1395
1396     static load( _pid, _path ) {
1397         S.dom(_pid).load( System.launchpath[_pid] +"/"+ _path, () => {
1398             App.kaf(_pid);
1399         } );
1400         return App;
1401     }
1402
1403     static preventClose( _pid, _bool = true ) {
1404         process[_pid].preventclose = _bool || true;
1405         return App;
1406     }
1407 }
1408
1409 App.d = new Object();
1410 App.e = new Object();
1411 App.version = "2.1.1";
1412
1413 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;