OSDN Git Service

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