9 // THIS IS THE KIT KERNEL, KIT APPS FRAMEWORK AND KIT WINDOW SYSTEM
10 // http://web.kitit.ml/
11 // https://github.com/mtsgi/kit
14 $( document ).ready( kit );
19 if( localStorage.getItem( "kit-pid" ) ) pid = localStorage.getItem( "kit-pid" );
21 if( !localStorage.getItem( "kit-username" ) ) localStorage.setItem( "kit-username", "ユーザー" );
22 $( "#kit-header-username" ).text( localStorage.getItem( "kit-username" ) );
24 if( localStorage.getItem( "kit-lock" ) == null ) localStorage.setItem( "kit-lock", "false" );
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" );
29 if( !localStorage.getItem( "kit-default-browser" ) ) localStorage.setItem( "kit-default-browser", "browser" );
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]);
38 if( localStorage.getItem("kit-darkmode") == "true" ){
40 $("#kit-darkmode").attr("href", "system/theme/kit-darkmode.css");
41 $(".winc-darkmode").addClass("kit-darkmode");
44 if( System.bootopt.get("safe") ){
45 $("#kit-theme-file").attr("href", "./system/theme/theme-light.css" );
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") );
52 if( !localStorage.getItem( "kit-appdir" ) ) localStorage.setItem( "kit-appdir", "./app/" );
53 S.appdir = localStorage.getItem( "kit-appdir" );
55 if( localStorage.getItem('kit-installed') ) System.installed = JSON.parse( localStorage.getItem('kit-installed') );
57 if( localStorage.getItem('kit-screentime') ) KWS.screenTime = JSON.parse( localStorage.getItem('kit-screentime') );
59 if( localStorage["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
60 if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
62 System.moveDesktop( "1" );
65 if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
66 else clockmove = setInterval( System.clock, 10 );
68 if ( localStorage.getItem("kit-shutted-down") == "false" ) {
69 Notification.push("お知らせ", "kitは前回終了時、正しくシャットダウンされませんでした。", "system");
71 localStorage.setItem("kit-shutted-down", false);
73 Notification.push("kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system", null, null, 'documents/icon.png', [
76 func: () => System.launch( 'settings', {'view': 'about'} )
80 if( localStorage.getItem( "kit-startup" ) == undefined ) {
81 localStorage.setItem( "kit-startup", new Array( "welcome" ) );
83 System.startup = localStorage.getItem( "kit-startup" ).split( "," );
84 if( System.bootopt.get("safe") ){
85 Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
86 System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
88 else for( let i of System.startup ) if( i != "" ) System.launch(i);
90 $("#kit-header-fullscreen").hide();
93 $( "#desktops" ).click( function() {
94 $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
95 } ).mousedown( function() {
96 $( ".window" ).css( "opacity", "0.6" );
97 } ).mouseup( function() {
98 $( ".window" ).css( "opacity", "1.0" );
101 $( "#footer-tasks" ).click( function() {
102 if( $( "#kit-tasks" ).is( ":visible" ) ) {
103 $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
106 $( "#task-ctx" ).fadeOut( 200 );
107 $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
110 $.getJSON("system/testload.json").fail( () => {
111 $('#body').append(`<div id='wcors' class="window windowactive" style="top: 70px; left: 50px; width: calc(100% - 100px)">
112 <div class="wt">問題が発生しました</div>
113 <div class="winc">JSONデータ読み込みに失敗しました。<br>
114 クロスオリジン制約によりkitアプリケーションの動作が制限されている場合があります。<br>
115 詳細は<a class="kit-hyperlink" onclick="location.href = 'https://mtsgi.github.io/kitdocs/#/cors'">こちらの記事</a>をご確認ください。</div>
117 $('<kit-button-alt class="kit-block kit-text-c m">閉じる</kit-button-alt>').appendTo('#wcors .winc').on('click', ()=>{
118 $('#wcors').remove();
122 $.getJSON("config/desktop.json", (data) => {
123 for( let i in data ){
124 $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
126 $(".desktop-icon").on("click", function(){
127 System.launch( $(this).attr("data-launch") );
129 }).fail( function() {
130 Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
133 $.getJSON("config/apps.json", System.initLauncher).fail( function() {
134 Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
136 $( "#kit-tasks" ).delegate( ".task", "click", function() {
137 System.close( this.id.slice( 1 ) );
141 $( "#footer-noti" ).click( function() {
142 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
143 if( $( "#notifications" ).is( ":visible" ) ) {
144 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
147 $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
150 $( "#last-notification-close" ).click( function() {
151 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
153 $("#notifications-dnp").prop("checked", false).on("change", ()=>{
154 if( $("#notifications-dnp").is(":checked") ){
155 Notification.goodnight = true;
157 else Notification.goodnight = false;
160 $( ".power-button" ).click( function() {
161 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
162 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
163 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" );
164 $( "footer, header, #launcher, #task-ctx, #kit-sightre, .dropdown, #desktop-" + currentDesktop ).hide();
165 $( "#kit-power" ).show();
167 $( "#kit-power-back" ).click( function() {
168 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
169 $( "footer, header, #desktop-" + currentDesktop ).show();
170 $( "#kit-power" ).hide();
172 $( "#kit-power-shutdown" ).click( function() {
175 $( "#kit-power-reboot" ).click( function() {
178 $( "#kit-power-suspend" ).click( function() {
180 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
181 $( "#kit-power" ).fadeOut( 300 );
182 System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
184 $( "#kit-power-lock" ).click( function() {
187 $( "#lock-password" ).on( 'keypress', function( e ) {
188 if( e.which == 13 ) $( "#lock-unl" ).click();
190 $( "#lock-unl" ).on( 'click', function() {
191 if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
192 $( "header, footer" ).show();
193 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
194 $( "#lock-password" ).val( "" );
195 System.moveDesktop(1);
197 else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
198 } ).hover( function() {
199 $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
201 $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
204 $( "#launch" ).click( function() {
205 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
206 if( $( "#launcher" ).is( ":visible" ) ) {
207 $( "#kit-wallpaper" ).css( "filter", "none" );
208 $( "#desktop-" + currentDesktop ).show();
209 $( "#launcher" ).hide();
212 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
213 $( "section, #task-ctx" ).hide();
214 $( "#launcher" ).show();
219 $('#kit-header-sightre').on('click', () => {
220 if($('#kit-sightre').is( ":visible" )) {
221 $('#kit-sightre').fadeOut(300);
224 $('#kit-sightre-results').html('');
225 $('#kit-sightre').show();
226 $('#kit-sightre-form').val('').focus();
229 let sightrePrevWord = '';
230 $('#kit-sightre-form').on('keypress', (e) => {
231 let _word = $('#kit-sightre-form').val();
232 if( e.which == 13 && _word ) {
233 if( _word == "kit" ){
234 S.alert("", "<div style='text-align:left;'> _ _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>| 〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
237 $('.kit-sightre-result.-first').click();
238 sightrePrevWord = '';
239 $('#kit-sightre-form').val('');
240 $('#kit-sightre-results').html('');
241 $('#kit-sightre').fadeOut(300);
243 }).on('keydown keyup change', (e) => {
244 let _word = $('#kit-sightre-form').val();
245 if( e.which == 27 ) $('#kit-sightre').fadeOut(300);
247 if( _word == sightrePrevWord ) return;
248 $('#kit-sightre-results').html('');
250 sightrePrevWord = _word;
251 if( _word.indexOf('kish ') == 0 || _word.indexOf('🥧 ') == 0 ){
252 let _cmd = _word.substring( _word.indexOf(" ") + 1 );
254 $(`<div class='kit-sightre-result -first'>
255 <img class='--icon' src='app/kish/icon.png'/>
257 <div class='--name'>${_cmd}</div>
258 <div class='--desc'>kishでコマンドを実行</div>
260 <div class='--open fa fa-arrow-right'></div>
261 </div>`).appendTo('#kit-sightre-results').on('click', () => {
262 System.launch('kish', { 'rc': [ _cmd ] });
266 else if( _word.indexOf('http://') == 0 || _word.indexOf('https://') == 0 || _word.indexOf('localhost') == 0 ){
267 $(`<div class='kit-sightre-result -first'>
268 <img class='--icon' src='app/browser/icon.png'/>
270 <div class='--name'>${_word}</div>
271 <div class='--desc'>ブラウザでURLを開く</div>
273 <div class='--open fa fa-arrow-right'></div>
274 </div>`).appendTo('#kit-sightre-results').on('click', () => {
275 System.launch( localStorage.getItem('kit-default-browser'), { "url" : _word } );
279 $(`<div class='kit-sightre-result -first'>
280 <img class='--icon' src='system/icons/q.png'/>
282 <div class='--name'>${_word}</div>
283 <div class='--desc'>アプリを起動する</div>
285 <div class='--open fa fa-arrow-right'></div>
286 </div>`).appendTo('#kit-sightre-results').on('click', () => {
289 if( _word.split(",")[1] ) _args = JSON.parse( _word.split(",").slice(1).join().trim() );
292 Notification.push("引数の解釈に失敗", error, "system");
294 System.launch( _word.split(",")[0], _args );
297 for( let i in System.apps ){
298 if( i.indexOf(_word) == 0 || S.apps[i].name.indexOf(_word) == 0 ){
299 $(`<div class='kit-sightre-result -app'>
300 <img class='--icon' src='${S.apps[i].icon}'/>
302 <div class='--name'>${S.apps[i].name}</div>
303 <div class='--desc'>kitアプリケーション - ${i}</div>
305 <div class='--open fa fa-arrow-right'></div>
306 </div>`).appendTo('#kit-sightre-results').on('click', () => {
308 $('#kit-sightre-results').html('');
309 $('#kit-sightre').fadeOut(300);
313 for( let i in System.userarea ){
314 if( i.indexOf(_word) == 0 || i.indexOf(_word) == 0 ){
315 $(`<div class='kit-sightre-result -file'>
316 <i class="fa fa-file --icon"></i>
318 <div class='--name'>${i}</div>
319 <div class='--desc'>ファイル - 種類:${S.userarea[i].type} - ユーザー:${System.username}</div>
321 <div class='--open fa fa-arrow-right'></div>
322 </div>`).appendTo('#kit-sightre-results').on('click', () => {
324 $('#kit-sightre-results').html('');
325 $('#kit-sightre').fadeOut(300);
329 $(`<div class='kit-sightre-result -link'>
330 <i class="fa fa-search --icon"></i>
332 <div class='--name'>${_word}</div>
333 <div class='--desc'>をWebで検索</div>
335 <div class='--open fa fa-arrow-right'></div>
336 </div>`).appendTo('#kit-sightre-results').on('click', () => {
337 System.launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
338 $('#kit-sightre-results').html('');
339 $('#kit-sightre').fadeOut(300);
341 $(`<div class='kit-sightre-result -link'>
342 <i class="fab fa-wikipedia-w --icon"></i>
344 <div class='--name'>${_word}</div>
345 <div class='--desc'>wikipediaの記事を表示</div>
347 <div class='--open fa fa-arrow-right'></div>
348 </div>`).appendTo('#kit-sightre-results').on('click', () => {
349 System.launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
350 $('#kit-sightre-results').html('');
351 $('#kit-sightre').fadeOut(300);
356 $("#dropdown-sound-slider").slider({
357 min: 0, max: 100, step: 1, value: 100,
359 System.audio.level = ui.value;
360 $("#dropdown-sound-level").text(ui.value);
361 localStorage.setItem("kit-audio-level", ui.value);
362 for( let i in System.audio.list ){
363 System.audio.list[i].volume = System.audio.level / 100;
365 if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
366 else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
369 if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
371 $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
372 if( $("#dropdown-sound-silent").is(":checked") ){
373 System.audio.silent = true;
374 $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
377 System.audio.silent = false;
378 $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
382 $('#kit-header-user').on('click', () => System.launch('user') );
384 $(":root section:not(#desktop-l)").on("contextmenu", function() {
385 let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
386 S.selectedElement = _ptelem;
387 S.selectedText = window.getSelection();
388 $( "#kit-context-input" ).val( S.selectedText );
389 if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
390 else $("#kit-contextgroup-text").show();
391 if( _ptelem[0].id == "desktop-" + currentDesktop ){
392 $("#kit-contextgroup-desktop").show();
393 $("#kit-contextgroup-elem").hide();
396 $("#kit-contextgroup-desktop").hide();
397 $("#kit-contextgroup-elem").show();
399 $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
400 $("#kit-contextgroup-custom").hide();
402 let _ctxid = _ptelem.attr("data-kit-contextid") || _ptelem.attr("kit-context");
404 $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
405 let _ctxname = KWS.context[_ctxid].name || _ctxid;
406 $("#kit-context-custom").text( _ctxname );
407 for( let i in KWS.context[_ctxid]){
408 if( i == "name" ) continue;
409 $("#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>");
410 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
411 KWS.context[_ctxid][i].function();
412 $("#kit-context").fadeOut(300);
416 if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
417 $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
418 $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
421 $("#kit-context-open").on("click", function(){
422 S.alert("要素", S.selectedElement.clone());
424 $("#kit-context-save").on("click", function(){
425 S.obj2img( S.selectedElement , true );
427 $( "#kit-context-search" ).on("click", function(){
428 $("#kit-context").fadeOut(300);
429 System.launch( 'browser', {'url': `https://www.bing.com/search?q=${$('#kit-context-input').val()}`} );
431 $( "#kit-context-input" ).keypress( function( e ) {
432 if( e.which == 13 ) $( "#kit-context-search" ).click();
434 $("#kit-context a").on("click", function(){
435 $("#kit-context").fadeOut(300);
437 $("#kit-context-vacuum").on("click", function(){
438 for( let i in process ){
439 KWS.vacuum( S.mouseX, S.mouseY );
442 $(".window").css("transition", "none");
445 $("#kit-context-fusen").on("click", function(){
450 $("section").on("click", function(){
451 $("#kit-context").fadeOut(300);
454 $( document ).delegate('a', 'click', function() {
456 System.launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
459 } ).on("mousemove", function(e){
460 System.mouseX = e.clientX;
461 System.mouseY = e.clientY;
462 }).delegate('.textbox', 'keypress', function(e) {
463 if( e.which == 13 && this.id ){
464 if( $("#" + this.id + " + .kit-button").length ){
465 Notification.push("debug", this.id, "system");
466 $("#" + this.id + " + .kit-button").click();
468 else if( $("#" + this.id + " + kit-button").length ){
469 Notification.push("debug", this.id, "system");
470 $("#" + this.id + " + kit-button").click();
475 window.onresize = () => {
476 System.display.width = window.innerWidth;
477 System.display.height = window.innerWidth;
479 if( KWS.fullscreen.pid ){
480 KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
484 if( localStorage.getItem( "kit-lock" ) == "true" ){
486 setTimeout(() => System.lock(), 100);
490 async function launch( str, args, dir ) {
491 while(System.launchLock) await System.ajaxWait();
492 System.launchLock = true;
495 System.args[_pid] = args;
496 let _path = dir || System.appdir + str;
497 System.launchpath[_pid] = _path;
499 if( System.appCache[_path] ) {
500 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
501 appData( System.appCache[_path] );
505 $.getJSON( S.launchpath[_pid] + '/define.json', appData ).fail( () => {
506 Notification.push('kitアプリをロードできません。', `${str}を展開できませんでした。`, 'system');
510 Notification.push( "System Error", error, "system" );
515 async function appData( data ) {
517 process[String( _pid )] = {
519 time: System.time.obj.toLocaleString(),
524 System.appCache[System.launchpath[pid]] = data;
526 let _taskAppend = `<span id='t${_pid}'>`;
527 if( data.icon && data.icon != "none" ) _taskAppend += `<img src='${S.launchpath[_pid]}/${data.icon}'>`;
528 _taskAppend += `<span id='tname${_pid}'>${data.name}<span></span>`;
529 $( "#tasks" ).append( _taskAppend );
530 $( "#t" + _pid ).addClass( "task" ).on({
532 if( $(this).hasClass("t-active") || $(this).hasClass("task-min") ) KWS.min( _pid );
534 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
535 KWS.refreshWindowIndex();
538 mouseenter: function() {
539 $( "#task-ctx-name" ).text( data.name );
540 if( data.icon && data.icon != "none" ) $( "#task-ctx-img" ).attr( "src", System.launchpath[_pid] + "/" + data.icon );
541 else $( "#task-ctx-img" ).hide();
542 $( "#task-ctx-ver" ).text( data.version + "/pid:" + _pid );
543 $( "#task-ctx-info" ).off().on( "click", function() { System.appInfo( _pid )} );
544 $( "#task-ctx-sshot" ).off().on( "click", function() { S.screenshot(_pid, true) } );
545 $( "#task-ctx-min" ).off().on( "click", function() { KWS.min( String(_pid) ) } );
546 if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
547 else $( "#task-ctx-front" ).show();
548 $( "#task-ctx-front" ).off().on( "click", function() {
549 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
550 KWS.refreshWindowIndex();
552 $( "#task-ctx-close" ).off().on("click", () => System.close(_pid));
553 $( "#task-ctx-kill" ).off().on("click", () => System.kill( data.id));
554 const _ctxleft = $(this).offset().left, _ctxtop = window.innerHeight - $(this).offset().top;
555 if( _ctxleft != $( "#task-ctx" ).offset().left ) $( "#task-ctx" ).hide();
556 $( "#task-ctx" ).css( "left", _ctxleft ).css( "bottom", _ctxtop ).show();
559 $( "section, #kit-tasks" ).on( "mouseenter", function() {
560 $( "#task-ctx" ).fadeOut( 200 );
562 $( "#t" + _pid ).on({
564 prevWindowIndex = $( "#w" + _pid ).css( "z-index" );
565 $( "#w" + _pid ).addClass( "win-highlight" );
567 mouseleave: () => $( "#w" + _pid ).removeClass( "win-highlight" )
570 let _windowAppend = "<div id='w" + _pid + "'><div id='wt" + _pid + "' class='wt'><i class='wmzx'><span id='wm" + _pid + "'></span>";
571 if( data.support && data.support['fullscreen'] == true ) _windowAppend += "<span id='wz" + _pid + "'></span>";
572 _windowAppend += "<span id='wx" + _pid + "'></span></i>";
573 if( data.icon && data.icon != "none" ) _windowAppend += "<img src='" + S.launchpath[_pid] + "/" + data.icon + "'>";
574 _windowAppend += "<span id='wtname" + _pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + _pid + "'></div></div>";
575 $( "#desktop-" + currentDesktop ).append( _windowAppend );
577 if( data.support && data.support['darkmode'] == true ) $("#winc"+_pid).addClass("winc-darkmode");
578 if( KWS.darkmode ) $("#winc"+_pid).addClass("kit-darkmode");
581 $("#winc"+_pid).css("width", data.size.width).css("height", data.size.height);
584 let _minwidth = 200, _minheight = 40;
585 if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
586 if( data.resize.minHeight ) _minheight = data.resize.minHeight;
587 $("#winc"+_pid).windowResizable({
589 minHeight: _minheight
593 let windowPos = 50 + ( _pid % 10 ) * 20;
595 $( "#w"+_pid ).addClass( "window" ).pep({
596 elementsWithInteraction: ".winc, .ui-resizable-handle",
597 useCSSTranslation: false,
598 disableSelect: false,
600 initiate: function(){
601 $(this.el).addClass("ui-draggable-dragging");
603 this.el.style.zIndex = KWS.windowIndex;
604 KWS.refreshWindowIndex();
607 this.el.style.transition = "none";
608 $(this.el).removeClass("ui-draggable-dragging");
610 }).on( "mousedown", function(){
611 $(".window").css( "transition", "none" );
612 $(this).css("z-index", KWS.windowIndex + 1);
613 KWS.refreshWindowIndex();
614 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
615 KWS.refreshWindowIndex();
616 $( `#wm${_pid}` ).addClass( "wm fa fa-window-minimize" ).on("click", () => KWS.min( _pid ) );
617 $( `#wz${_pid}` ).addClass( "wz fas fa-square" ).on("click", () => KWS.max( _pid ) );
618 $( `#wx${_pid}` ).addClass( "wx fa fa-times" ).on("click", () => System.close( _pid ) );
619 $( "#winc" + _pid ).resizable( {
621 } ).load( System.launchpath[_pid] + "/" + data.view, (r, s, x) => {
623 Notification.push("起動に失敗:" + x.status, x.statusText);
626 if( !data.script || data.script != "none" ) $.getScript( System.launchpath[_pid] + "/" + data.script, () => {
627 if( !data.support || data.support['kaf'] != false ) App.kaf(_pid);
633 else if( !data.support || data.support['kaf'] != false ){
638 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
639 $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
641 localStorage.setItem( "kit-pid", pid );
642 System.launchLock = false;
646 const System = new function() {
647 this.version = "0.2.1";
648 this.username = localStorage.getItem("kit-username");
649 this.appdir = localStorage.getItem("kit-appdir");
650 this.loc = { ...location };
652 this.bootopt = new URLSearchParams(location.search);
658 "width": window.innerWidth,
659 "height": window.innerHeight
662 this.selectedElement = null;
663 this.selectedText = null;
665 this.dom = function(_pid, ..._elems) {
667 if( !_elems.length ) q = ",#winc" + _pid;
668 else for( let i of _elems ){
669 q += ",#winc" + _pid + " " + i;
671 return $( q.substring(1) );
674 this.qs = ( _pid, ..._elems ) => {
676 if( !_elems.length ) q = ",#winc" + _pid;
677 else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
678 return document.querySelectorAll( q.substring(1) )
681 this.userarea = new Object();
682 this.recycle = new Object();
688 this.launchpath = {};
690 this.support = $.support;
691 this.debugmode = false;
695 this.log = new Array();
698 this.launchLock = false;
700 this.waitLaunchUnlock = (callback) => {
703 this.waitLaunchUnlock(callback);
710 this.ajaxWait = () =>{
711 return new Promise(resolve =>{
712 System.waitLaunchUnlock(resolve);
716 this.setBattery = function(){
717 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
718 let _lv = e.level * 100;
719 System.battery = _lv;
724 this.screenshot = function( _pid, _popup ){
725 let _elem = document.querySelector("body");
726 if( _pid ) _elem = document.querySelector("#w"+_pid);
727 html2canvas( _elem ).then(canvas => {
729 canvas.style.border = "1px solid #909090";
730 S.save( canvas.toDataURL("image/png"), "image" );
736 this.obj2img = function( _obj, _popup ){
738 html2canvas( _elem ).then(canvas => {
740 canvas.style.border = "1px solid #909090";
741 S.save( canvas.toDataURL("image/png"), "image" );
747 this.save = function(data, type){
748 System.launch("fivr", { "save" : data, "type" : type });
751 this.open = function(filename){
752 System.launch("fivr", { "open" : filename });
755 this.preventClose = function( _pid ){
756 if( !process[_pid] ) return false;
757 process[_pid].preventclose = true;
761 this.shutdown = function(_opt) {
762 $( "#last-notification-close" ).click();
763 $( "#kit-power-back" ).click();
764 for( let i in process ) {
765 if( process[i].preventclose == true ){
766 S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
767 process[i].preventclose = false;
772 else System.close( i );
774 $( "section" ).hide();
775 $( "body" ).css( "background-color", "black" );
776 $( "header, footer" ).fadeOut( 300 );
777 $( "#kit-wallpaper" ).fadeOut( 1500 );
778 if( _opt == "reboot" ) location.href = "autorun.html";
779 localStorage.setItem("kit-shutted-down", true);
782 this.reboot = function() {
783 System.shutdown("reboot");
786 this.lock = function(){
787 System.moveDesktop( "l" );
789 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
790 $( "section, header, footer" ).css( "filter", "none" );
791 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
792 $( "header, footer, #kit-power" ).hide();
794 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
795 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
796 else $( "#lock-password" ).hide();
799 this.alert = function( title, content, wtitle ) {
800 System.launch("alert", [title, content, wtitle]);
803 this.dialog = function( title, content, func ){
804 System.launch("dialog", {
811 this.appInfo = function( _pid ){
812 let _title = "", _content = "";
813 let ac = System.appCache[S.launchpath[_pid]];
814 let _lp = System.launchpath[_pid];
816 _title = ac.name + " " + ac.version;
817 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
819 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
821 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
823 else _title = "取得に失敗しました";
824 System.alert( _title, _content );
827 this.apps = new Object();
828 this.installed = new Array();
830 this.close = function( _str ) {
831 let _pid = String( _str );
832 $( "#w" + _pid ).remove();
833 $( "#t" + _pid ).remove();
834 $( "#task-ctx" ).hide();
835 delete process[_pid];
836 KWS.refreshWindowIndex();
839 this.kill = function( _str ){
840 for( let _pid in process ) {
841 if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
845 this.vacuum = function( _left, _top ){
846 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
860 this.clock = function() {
863 let Year = DD.getFullYear();
864 S.time.day = DD.getDay();
866 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
868 let DateN = ( "00" + DD.getDate() ).slice( -2 );
870 let Hour = ( "00" + DD.getHours() ).slice( -2 );
872 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
874 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
876 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
877 let MS = DD.getMilliseconds();
880 outer: { radius: .9, color: "transparent" },
881 inner: { radius: .85, color: "transparent" }
884 long: { from: .8, to: .7, width: 2, color: "#303030" },
885 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
888 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
889 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
890 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
892 let canvas = $(".dropdown-clock-canvas")[0];
893 canvas.width = "200", canvas.height = "200";
894 let context = canvas.getContext("2d");
895 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
896 let radius = Math.min(center.x, center.y), angle, len;
897 context.beginPath();context.fillStyle = circle.outer.color;
898 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
899 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
900 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
902 for( let i=0; i<60; i++ ){
903 angle = Math.PI * i / 30;
905 let line = ( i%5 == 0 ) ? lines.long : lines.short;
906 context.lineWidth = line.width, context.strokeStyle = line.color;
907 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
908 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
911 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
912 context.beginPath(), context.lineWidth = hands.hour.width;
913 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
914 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
915 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
916 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
917 context.beginPath(), context.lineWidth = hands.minute.width;
918 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
919 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
920 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
921 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
922 context.beginPath(), context.lineWidth = hands.second.width;
923 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
924 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
925 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
928 this.changeWallpaper = function( str ) {
929 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
930 localStorage.setItem( "kit-wallpaper", str )
933 this.moveDesktop = function( str ) {
935 $( "section" ).hide();
936 $( "#desktop-" + str ).show();
937 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
938 currentDesktop = str;
941 this.avoidMultiple = function( _pid, _alert ) {
942 let _id = process[_pid].id;
944 for( let i in process ) {
945 if( process[i].id == _id ) _cnt += 1;
947 Notification.push( "debug", _cnt );
949 System.close( _pid );
951 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
957 this.resizable = function( _pid, _elem, _width, _height ){
959 if( _elem ) E = String( _elem );
960 if( !_width ) _width = null;
961 if( !_height ) _height = "100";
962 $("#w" + _pid).resizable({
963 alsoResize: "#w" + _pid + " " + E,
969 this.initLauncher = function(data){
970 $("#launcher-apps").html("");
972 for( let i in data ){
973 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
975 if( !System.bootopt.get('safe') ){
976 for( let i of System.installed ){
977 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
980 $('.launcher-app').on('click', function(){
981 $('#launch').click();
982 System.launch( $(this).attr('data-launch') );
986 this.launch = async function(path, args) {
987 while(this.launchLock) await this.ajaxWait();
988 this.launchLock = true;
991 System.args[_pid] = args;
993 if(_path.lastIndexOf('/') == _path.length - 1) {
994 _path = _path.substring(0, _path.length - 1);
996 else if(_path.indexOf('/') == -1) {
997 _path = System.appdir + _path;
1000 System.launchpath[_pid] = _path;
1002 if( System.appCache[_path] ) {
1003 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
1004 appData( System.appCache[_path] );
1008 $.getJSON( _path + '/define.json', appData ).fail( () => {
1009 Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
1013 Notification.push( "System Error", error, "system" );
1018 this.clip = new function(){
1019 this.content = null;
1020 this.history = new Array();
1022 this.set = function( content ){
1023 this.content = content;
1024 this.history.push(content);
1027 this.get = ()=>{ return this.content }
1030 this.config = new function(){
1031 this.apps = new Object();
1034 this.audio = new function(){
1035 this.level = localStorage["kit-audio-level"] || 100;
1036 this.silent = false;
1038 this.list = new Array();
1040 this.volume = function( _level ){
1041 $("#dropdown-sound-slider").slider("value", _level);
1044 this.play = function( _audioid, _src ){
1045 if( !System.audio.list[_audioid] ){
1046 System.audio.list[_audioid] = new Audio(_src);
1047 System.audio.list[_audioid].volume = System.audio.level / 100;
1049 System.audio.list[_audioid].play();
1052 this.get = function( _audioid ){
1053 return System.audio.list[_audioid];
1056 this.pause = function( _audioid ){
1057 System.audio.list[_audioid].pause();
1060 this.stop = function( _audioid ){
1061 System.audio.list[_audioid].pause();
1062 System.audio.list[_audioid] = null;
1065 this.seek = function( _audioid, _time ){
1066 System.audio.list[_audioid].fastSeek(_time);
1069 this.mute = function( _audioid, _bool ){
1070 System.audio.list[_audioid].muted = _bool;
1075 const KWS = new function(){
1076 this.version = "3.2.3";
1079 this.darkmode = false;
1081 this.changeWindowTitle = function( _pid, _str ){
1082 $("#tname"+_pid).text( _str );
1083 $("#wtname"+_pid).text( _str );
1086 this.min = function( _str ) {
1087 let _pid = String( _str );
1088 if( $( "#w" + _pid ).is( ":visible" ) ) {
1089 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
1090 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1091 $( "#t" + _pid ).addClass( "task-min" );
1094 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1095 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1096 $( "#t" + _pid ).removeClass( "task-min" );
1108 this.max = function( _pid ){
1109 let _appcache = System.appCache[System.launchpath[_pid]];
1110 if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
1111 Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
1114 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1115 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1116 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1117 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1118 KWS.fullscreen.pid = _pid;
1119 $( "#wt"+_pid ).addClass("wtmaximize");
1120 $( "#w"+_pid ).css({
1124 .addClass("windowmaximize")
1125 .css("z-index", KWS.windowIndex + 1);
1126 KWS.refreshWindowIndex();
1127 KWS.resize( _pid, System.display.width, System.display.height - 30 );
1129 $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
1132 this.unmax = function( _pid ){
1133 if( _pid != KWS.fullscreen.pid ){
1134 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1137 $('#wt'+_pid).removeClass("wtmaximize");
1139 "top": KWS.fullscreen.prevTop,
1140 "left": KWS.fullscreen.prevLeft
1142 .removeClass("windowmaximize");
1144 $("#kit-header-fullscreen").hide().off();
1145 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1146 KWS.fullscreen.pid = null;
1147 KWS.fullscreen.prevWidth = null;
1148 KWS.fullscreen.prevHeight = null;
1149 KWS.fullscreen.prevTop = null;
1150 KWS.fullscreen.prevLeft = null;
1152 if( !System.appCache[System.launchpath[_pid]].size.height ) {
1153 System.qs(_pid)[0].style.height = "auto";
1157 this.vacuum = function( _left, _top ){
1158 for( let i in process ){
1159 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1162 $(".window").css("transition", "none");
1167 this.windowIndex = 1;
1169 this.refreshWindowIndex = function(){
1170 let num = $(".window").length;
1171 let array = new Array();
1172 let obj = new Object();
1173 for( let i = 0; i < num; i++ ){
1174 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1177 array.sort( (a,b) => {
1178 return Number(a.zindex - b.zindex);
1180 for( let i in array ){
1181 document.getElementById(array[i].id).style.zIndex = i;
1182 let _pid = String(array[i].id).substring(1);
1184 $("#"+array[i].id).addClass("windowactive");
1185 $("#t"+_pid).addClass("t-active");
1187 process[_pid].isactive = true;
1188 KWS.screenPrevSwitched = new Date();
1189 localStorage.setItem('kit-screentime', JSON.stringify(KWS.screenTime));
1192 console.log(_pid + '外れました');
1193 $("#"+array[i].id).removeClass("windowactive");
1194 $("#t"+_pid).removeClass("t-active");
1195 process[_pid].isactive = false;
1196 if( KWS.active == _pid ){
1197 let _diff = (new Date() - KWS.screenPrevSwitched);
1198 let _appid = process[_pid].id
1199 if( !KWS.screenTime[_appid] ) KWS.screenTime[_appid] = new Number();
1200 KWS.screenTime[_appid] += _diff;
1204 KWS.windowIndex = num;
1207 this.front = function( _pid ) {
1208 $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1209 KWS.refreshWindowIndex();
1212 this.resize = function( _pid, _width, _height ){
1213 if( _width ) $("#winc"+_pid).css("width", _width)
1214 if( _height ) $("#winc"+_pid).css("height", _height);
1217 this.setTheme = function(_name){
1218 localStorage.setItem('kit-theme', _name);
1219 if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
1220 else $('#kit-theme-file').attr('href', '');
1221 System.moveDesktop(currentDesktop);
1224 this.screenTime = new Object();
1226 this.screenPrevSwitched = new Date();
1228 this.fusen = new function(){
1230 this.list = new Object();
1232 this.add = function(_text){
1233 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1234 $("#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>");
1235 $("#kit-f"+KWS.fusen.fid).css({
1236 "left": Number(KWS.fusen.fid)*40 + 20,
1237 "top": Number(KWS.fusen.fid)*10 + 100,
1239 elementsWithInteraction: ".kit-fusen-textarea",
1240 useCSSTranslation: false,
1241 disableSelect: false,
1243 initiate: function(){
1244 $(this.el).css("ui-opacity", "0.7");
1247 this.el.style.transition = "none";
1248 $(this.el).css("ui-opacity", "1.0");
1251 $(".kit-fusen-textarea").off().on("change",function(){
1252 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1253 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1255 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1259 this.remove = function(_fid){
1260 delete KWS.fusen.list[_fid];
1261 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1262 $("#kit-f"+_fid).remove();
1266 this.addCustomContext = function( _elem, _contextid, _obj ){
1267 KWS.context[_contextid] = _obj;
1275 "icon" : "fa-trash-alt",
1276 "function" : function(){
1277 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1283 "function" : function(){
1284 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1291 const Notification = new function() {
1293 this.list = new Object();
1295 this.goodnight = false;
1298 this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1299 let _nid = this.nid;
1300 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1303 Notification.list[_nid] = {
1307 time: System.time.obj.toLocaleString(),
1310 if( typeof _action == 'function' ) _action();
1311 else if( _pid ) KWS.front(_pid);
1312 $('#notifications').hide('drop', {direction: 'right'}, 300);
1316 if( _pid && System.appCache[System.launchpath[_pid]] ){
1317 _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
1319 if( !this.goodnight ){
1320 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1321 $('#last-notification-title').text('').text( _title );
1322 $('#last-notification-content').text('').text( _content );
1323 $('#last-notification-app').text('').html( _app );
1324 $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1325 if( _img ) $('#last-notification-img').attr('src', _img).show();
1326 else $('#last-notification-img').attr('src', '').hide();
1329 if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1330 $(`<div class='notis' id='nt${_nid}'>
1332 <span class='notis_close' id='nc${_nid}'></span>
1333 <div class='notis_app'>${_app}</div>
1334 <span>${_title}</span>
1336 <div class='notis_buttons'></div>
1337 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1338 </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1339 $(`#nc${_nid}`).on('click', (e) => {
1340 e.stopPropagation();
1341 $(`#nt${_nid}`).fadeOut(300);
1343 $('#last-notification-buttons').html('');
1345 for( let b of _buttons ){
1346 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1347 e.stopPropagation();
1350 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1351 e.stopPropagation();
1357 return (this.nid - 1);
1363 App.e[_pid] = new Object();
1364 App.d[_pid] = new Object();
1366 this.process = process[_pid];
1367 this.cache = System.appCache[System.launchpath[_pid]];
1369 this.args = System.args[_pid];
1370 this.close = () => System.close(_pid);
1371 this.d = App.d[_pid];
1372 this.dom = (..._args) => System.dom(_pid, ..._args);
1373 this.e = App.e[_pid];
1374 this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1375 this.qs = (...args) => System.qs(_pid, ...args);
1376 this.front = () => KWS.front(_pid);
1378 this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1379 this.data = (_name, _value) => App.data(_pid, _name, _value);
1380 this.event = (_name, _event) => App.event(_pid, _name, _event);
1381 this.getPath = _path => App.getPath(_pid, _path);
1382 this.kaf = () => App.kaf(_pid);
1383 this.load = _path => App.load(_pid, _path);
1384 this.preventClose = _bool => App.preventClose(_pid, _bool);
1387 static changeWindowTitle( _pid, _t ) {
1388 $( "#tname"+_pid ).text( _t );
1389 $( "#wtname"+_pid ).text( _t );
1390 process[_pid].title = _t;
1394 static context( _cid, _obj ) {
1395 KWS.context[ _cid ] = _obj;
1399 static data( _pid, _name, _value ) {
1400 if( _value !== undefined ) {
1401 S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1402 S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1403 if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1404 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1405 return App.d[_pid][_name] = _value;
1407 else if( _name ) return App.d[_pid][_name];
1408 else return App.d[_pid];
1411 static event( _pid, _name, _event ) {
1412 if( !App.e[_pid] ) App.e[_pid] = new Object();
1413 if( !_event && App.e[_pid][_name] ) App.e[_pid][_name].call();
1414 else App.e[_pid][_name] = _event;
1418 static getPath( _pid, _path ) {
1419 if( String(_path)[0] != '/' ) _path = '/' + _path;
1420 return System.launchpath[_pid] + _path;
1423 static kaf( _pid ) {
1442 const DATA = App.data(_pid);
1443 const ARGS = System.args[_pid];
1444 for( let i of S.qs(_pid, ...attrs) ){
1445 if( i.hasAttribute("kit-ref") ){
1446 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1448 if( i.hasAttribute("kit-e") ){
1449 let _eqs = i.getAttribute("kit-e").split(",");
1450 for( let k of _eqs ){
1451 let _eq = k.split(" ");
1452 $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1455 if( i.hasAttribute("kit-src") ){
1456 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1458 if( i.hasAttribute("kit-alert") ){
1459 $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
1461 if( i.hasAttribute("kit-launch") ){
1462 $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
1464 if( i.hasAttribute("kit-close") ){
1465 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1467 if( i.hasAttribute("kit-text") ){
1468 $(i).text( eval(i.getAttribute("kit-text")) );
1470 if( i.hasAttribute("kit-html") ){
1471 $(i).html( eval(i.getAttribute("kit-html")) );
1473 if( i.hasAttribute("kit:bind") ){
1474 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1475 $(i).on('keydown keyup keypress change', () => {
1476 let _name = i.getAttribute("kit:bind");
1477 App.d[_pid][_name] = i.value;
1478 S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1479 if( i.value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1480 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1483 if( i.hasAttribute("kit:observe") ){
1484 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1486 if( i.hasAttribute("kit:value") ){
1487 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1489 if( i.hasAttribute("kit-value") ){
1490 $(i).val( eval(i.getAttribute("kit-value")) );
1492 if( i.hasAttribute("kit-color") ){
1493 $(i).css('color', i.getAttribute("kit-color"));
1495 if( i.hasAttribute("kit:if") ){
1496 if( App.d[_pid][i.getAttribute("kit:if")] ){
1501 if( i.hasAttribute("kit-if") ){
1502 if( eval( i.getAttribute("kit-if")) ){
1510 static load( _pid, _path ) {
1511 if( String(_path)[0] != '/' ) _path = '/' + _path;
1512 _path = System.launchpath[_pid] + _path;
1513 S.dom(_pid).load( _path, () => {
1515 let _appcache = System.appCache[System.launchpath[_pid]];
1516 if( !KWS.fullscreen.pid && !_appcache.size.height ) {
1517 System.qs(_pid)[0].style.height = "auto";
1523 static preventClose( _pid, _bool = true ) {
1524 process[_pid].preventclose = _bool || true;
1529 App.d = new Object();
1530 App.e = new Object();
1531 App.version = "2.1.1";
1533 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;