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["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
58 if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
60 System.moveDesktop( "1" );
63 if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
64 else clockmove = setInterval( System.clock, 10 );
66 if ( localStorage.getItem("kit-shutted-down") == "false" ) {
67 Notification.push("お知らせ", "kitは前回終了時、正しくシャットダウンされませんでした。", "system");
69 localStorage.setItem("kit-shutted-down", false);
71 Notification.push("kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system", null, null, 'documents/icon.png', [
74 func: () => System.launch( 'settings', {'view': 'about'} )
78 if( localStorage.getItem( "kit-startup" ) == undefined ) {
79 localStorage.setItem( "kit-startup", new Array( "welcome" ) );
81 System.startup = localStorage.getItem( "kit-startup" ).split( "," );
82 if( System.bootopt.get("safe") ){
83 Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
84 System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
86 else for( let i of System.startup ) if( i != "" ) System.launch(i);
88 $("#kit-header-fullscreen").hide();
91 $( "#desktops" ).click( function() {
92 $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
93 } ).mousedown( function() {
94 $( ".window" ).css( "opacity", "0.6" );
95 } ).mouseup( function() {
96 $( ".window" ).css( "opacity", "1.0" );
99 $( "#footer-tasks" ).click( function() {
100 if( $( "#kit-tasks" ).is( ":visible" ) ) {
101 $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
104 $( "#task-ctx" ).fadeOut( 200 );
105 $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
108 $.getJSON("system/testload.json").fail( () => {
109 $('#body').append(`<div id='wcors' class="window windowactive" style="top: 70px; left: 50px; width: calc(100% - 100px)">
110 <div class="wt">問題が発生しました</div>
111 <div class="winc">JSONデータ読み込みに失敗しました。<br>
112 クロスオリジン制約によりkitアプリケーションの動作が制限されている場合があります。<br>
113 詳細は<a class="kit-hyperlink" onclick="location.href = 'https://mtsgi.github.io/kitdocs/#/cors'">こちらの記事</a>をご確認ください。</div>
115 $('<kit-button-alt class="kit-block kit-text-c m">閉じる</kit-button-alt>').appendTo('#wcors .winc').on('click', ()=>{
116 $('#wcors').remove();
120 $.getJSON("config/desktop.json", (data) => {
121 for( let i in data ){
122 $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
124 $(".desktop-icon").on("click", function(){
125 System.launch( $(this).attr("data-launch") );
127 }).fail( function() {
128 Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
131 $.getJSON("config/apps.json", System.initLauncher).fail( function() {
132 Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
134 $( "#kit-tasks" ).delegate( ".task", "click", function() {
135 System.close( this.id.slice( 1 ) );
139 $( "#footer-noti" ).click( function() {
140 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
141 if( $( "#notifications" ).is( ":visible" ) ) {
142 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
145 $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
148 $( "#last-notification-close" ).click( function() {
149 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
151 $("#notifications-dnp").prop("checked", false).on("change", ()=>{
152 if( $("#notifications-dnp").is(":checked") ){
153 Notification.goodnight = true;
155 else Notification.goodnight = false;
158 $( ".power-button" ).click( function() {
159 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
160 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
161 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" );
162 $( "footer, header, #launcher, #task-ctx, #kit-sightre, .dropdown, #desktop-" + currentDesktop ).hide();
163 $( "#kit-power" ).show();
165 $( "#kit-power-back" ).click( function() {
166 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
167 $( "footer, header, #desktop-" + currentDesktop ).show();
168 $( "#kit-power" ).hide();
170 $( "#kit-power-shutdown" ).click( function() {
173 $( "#kit-power-reboot" ).click( function() {
176 $( "#kit-power-suspend" ).click( function() {
178 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
179 $( "#kit-power" ).fadeOut( 300 );
180 System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
182 $( "#kit-power-lock" ).click( function() {
185 $( "#lock-password" ).on( 'keypress', function( e ) {
186 if( e.which == 13 ) $( "#lock-unl" ).click();
188 $( "#lock-unl" ).on( 'click', function() {
189 if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
190 $( "header, footer" ).show();
191 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
192 $( "#lock-password" ).val( "" );
193 System.moveDesktop(1);
195 else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
196 } ).hover( function() {
197 $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
199 $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
202 $( "#launch" ).click( function() {
203 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
204 if( $( "#launcher" ).is( ":visible" ) ) {
205 $( "#kit-wallpaper" ).css( "filter", "none" );
206 $( "#desktop-" + currentDesktop ).show();
207 $( "#launcher" ).hide();
210 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
211 $( "section, #task-ctx" ).hide();
212 $( "#launcher" ).show();
217 $('#kit-header-sightre').on('click', () => {
218 if($('#kit-sightre').is( ":visible" )) {
219 $('#kit-sightre').fadeOut(300);
222 $('#kit-sightre-results').html('');
223 $('#kit-sightre').show();
224 $('#kit-sightre-form').val('').focus();
227 let sightrePrevWord = '';
228 $('#kit-sightre-form').on('keypress', (e) => {
229 let _word = $('#kit-sightre-form').val();
230 if( e.which == 13 && _word ) {
231 if( _word == "kit" ){
232 S.alert("", "<div style='text-align:left;'> _ _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>| 〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
235 $('.kit-sightre-result.-first').click();
236 sightrePrevWord = '';
237 $('#kit-sightre-form').val('');
238 $('#kit-sightre-results').html('');
239 $('#kit-sightre').fadeOut(300);
241 }).on('keydown keyup change', (e) => {
242 let _word = $('#kit-sightre-form').val();
243 if( e.which == 27 ) $('#kit-sightre').fadeOut(300);
245 if( _word == sightrePrevWord ) return;
246 $('#kit-sightre-results').html('');
248 sightrePrevWord = _word;
249 if( _word.indexOf('kish ') == 0 || _word.indexOf('🥧 ') == 0 ){
250 let _cmd = _word.substring( _word.indexOf(" ") + 1 );
252 $(`<div class='kit-sightre-result -first'>
253 <img class='--icon' src='app/kish/icon.png'/>
255 <div class='--name'>${_cmd}</div>
256 <div class='--desc'>kishでコマンドを実行</div>
258 <div class='--open fa fa-arrow-right'></div>
259 </div>`).appendTo('#kit-sightre-results').on('click', () => {
260 System.launch('kish', { 'rc': [ _cmd ] });
264 else if( _word.indexOf('http://') == 0 || _word.indexOf('https://') == 0 || _word.indexOf('localhost') == 0 ){
265 $(`<div class='kit-sightre-result -first'>
266 <img class='--icon' src='app/browser/icon.png'/>
268 <div class='--name'>${_word}</div>
269 <div class='--desc'>ブラウザでURLを開く</div>
271 <div class='--open fa fa-arrow-right'></div>
272 </div>`).appendTo('#kit-sightre-results').on('click', () => {
273 System.launch( localStorage.getItem('kit-default-browser'), { "url" : _word } );
277 $(`<div class='kit-sightre-result -first'>
278 <img class='--icon' src='system/icons/q.png'/>
280 <div class='--name'>${_word}</div>
281 <div class='--desc'>アプリを起動する</div>
283 <div class='--open fa fa-arrow-right'></div>
284 </div>`).appendTo('#kit-sightre-results').on('click', () => {
287 if( _word.split(",")[1] ) _args = JSON.parse( _word.split(",").slice(1).join().trim() );
290 Notification.push("引数の解釈に失敗", error, "system");
292 System.launch( _word.split(",")[0], _args );
295 for( let i in System.apps ){
296 if( i.indexOf(_word) == 0 || S.apps[i].name.indexOf(_word) == 0 ){
297 $(`<div class='kit-sightre-result -app'>
298 <img class='--icon' src='${S.apps[i].icon}'/>
300 <div class='--name'>${S.apps[i].name}</div>
301 <div class='--desc'>kitアプリケーション - ${i}</div>
303 <div class='--open fa fa-arrow-right'></div>
304 </div>`).appendTo('#kit-sightre-results').on('click', () => {
306 $('#kit-sightre-results').html('');
307 $('#kit-sightre').fadeOut(300);
311 for( let i in System.userarea ){
312 if( i.indexOf(_word) == 0 || i.indexOf(_word) == 0 ){
313 $(`<div class='kit-sightre-result -file'>
314 <i class="fa fa-file --icon"></i>
316 <div class='--name'>${i}</div>
317 <div class='--desc'>ファイル - 種類:${S.userarea[i].type} - ユーザー:${System.username}</div>
319 <div class='--open fa fa-arrow-right'></div>
320 </div>`).appendTo('#kit-sightre-results').on('click', () => {
322 $('#kit-sightre-results').html('');
323 $('#kit-sightre').fadeOut(300);
327 $(`<div class='kit-sightre-result -link'>
328 <i class="fa fa-search --icon"></i>
330 <div class='--name'>${_word}</div>
331 <div class='--desc'>をWebで検索</div>
333 <div class='--open fa fa-arrow-right'></div>
334 </div>`).appendTo('#kit-sightre-results').on('click', () => {
335 System.launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
336 $('#kit-sightre-results').html('');
337 $('#kit-sightre').fadeOut(300);
339 $(`<div class='kit-sightre-result -link'>
340 <i class="fab fa-wikipedia-w --icon"></i>
342 <div class='--name'>${_word}</div>
343 <div class='--desc'>wikipediaの記事を表示</div>
345 <div class='--open fa fa-arrow-right'></div>
346 </div>`).appendTo('#kit-sightre-results').on('click', () => {
347 System.launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
348 $('#kit-sightre-results').html('');
349 $('#kit-sightre').fadeOut(300);
354 $("#dropdown-sound-slider").slider({
355 min: 0, max: 100, step: 1, value: 100,
357 System.audio.level = ui.value;
358 $("#dropdown-sound-level").text(ui.value);
359 localStorage.setItem("kit-audio-level", ui.value);
360 for( let i in System.audio.list ){
361 System.audio.list[i].volume = System.audio.level / 100;
363 if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
364 else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
367 if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
369 $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
370 if( $("#dropdown-sound-silent").is(":checked") ){
371 System.audio.silent = true;
372 $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
375 System.audio.silent = false;
376 $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
380 $('#kit-header-user').on('click', () => System.launch('user') );
382 $(":root section:not(#desktop-l)").on("contextmenu", function() {
383 let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
384 S.selectedElement = _ptelem;
385 S.selectedText = window.getSelection();
386 $( "#kit-context-input" ).val( S.selectedText );
387 if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
388 else $("#kit-contextgroup-text").show();
389 if( _ptelem[0].id == "desktop-" + currentDesktop ){
390 $("#kit-contextgroup-desktop").show();
391 $("#kit-contextgroup-elem").hide();
394 $("#kit-contextgroup-desktop").hide();
395 $("#kit-contextgroup-elem").show();
397 $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
398 $("#kit-contextgroup-custom").hide();
400 let _ctxid = _ptelem.attr("data-kit-contextid") || _ptelem.attr("kit-context");
402 $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
403 let _ctxname = KWS.context[_ctxid].name || _ctxid;
404 $("#kit-context-custom").text( _ctxname );
405 for( let i in KWS.context[_ctxid]){
406 if( i == "name" ) continue;
407 $("#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>");
408 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
409 KWS.context[_ctxid][i].function();
410 $("#kit-context").fadeOut(300);
414 if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
415 $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
416 $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
419 $("#kit-context-open").on("click", function(){
420 S.alert("要素", S.selectedElement.clone());
422 $("#kit-context-save").on("click", function(){
423 S.obj2img( S.selectedElement , true );
425 $( "#kit-context-search" ).on("click", function(){
426 $("#kit-context").fadeOut(300);
427 System.launch( 'browser', {'url': `https://www.bing.com/search?q=${$('#kit-context-input').val()}`} );
429 $( "#kit-context-input" ).keypress( function( e ) {
430 if( e.which == 13 ) $( "#kit-context-search" ).click();
432 $("#kit-context a").on("click", function(){
433 $("#kit-context").fadeOut(300);
435 $("#kit-context-vacuum").on("click", function(){
436 for( let i in process ){
437 KWS.vacuum( S.mouseX, S.mouseY );
440 $(".window").css("transition", "none");
443 $("#kit-context-fusen").on("click", function(){
448 $("section").on("click", function(){
449 $("#kit-context").fadeOut(300);
452 $( document ).delegate('a', 'click', function() {
454 System.launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
457 } ).on("mousemove", function(e){
458 System.mouseX = e.clientX;
459 System.mouseY = e.clientY;
460 }).delegate('.textbox', 'keypress', function(e) {
461 if( e.which == 13 && this.id ){
462 if( $("#" + this.id + " + .kit-button").length ){
463 Notification.push("debug", this.id, "system");
464 $("#" + this.id + " + .kit-button").click();
466 else if( $("#" + this.id + " + kit-button").length ){
467 Notification.push("debug", this.id, "system");
468 $("#" + this.id + " + kit-button").click();
473 window.onresize = () => {
474 System.display.width = window.innerWidth;
475 System.display.height = window.innerWidth;
477 if( KWS.fullscreen.pid ){
478 KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
482 if( localStorage.getItem( "kit-lock" ) == "true" ){
484 setTimeout(() => System.lock(), 100);
488 async function launch( str, args, dir ) {
489 while(System.launchLock) await System.ajaxWait();
490 System.launchLock = true;
493 System.args[_pid] = args;
494 let _path = dir || System.appdir + str;
495 System.launchpath[_pid] = _path;
497 if( System.appCache[_path] ) {
498 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
499 appData( System.appCache[_path] );
503 $.getJSON( S.launchpath[_pid] + '/define.json', appData ).fail( () => {
504 Notification.push('kitアプリをロードできません。', `${str}を展開できませんでした。`, 'system');
508 Notification.push( "System Error", error, "system" );
513 async function appData( data ) {
514 if( data.support && data.support.multiple == false ){
515 for( let p in process ){
516 if( process[p].id === data.id ){
517 Notification.push('多重起動エラー', `アプリケーション「${data.name}」の多重起動は許可されていません。`, 'system');
518 System.launchLock = false;
524 process[String( _pid )] = {
526 time: System.time.obj.toLocaleString(),
531 System.appCache[System.launchpath[pid]] = data;
533 let _taskAppend = `<span id='t${_pid}'>`;
534 if( data.icon && data.icon != "none" ) _taskAppend += `<img src='${S.launchpath[_pid]}/${data.icon}'>`;
535 _taskAppend += `<span id='tname${_pid}'>${data.name}<span></span>`;
536 $( "#tasks" ).append( _taskAppend );
537 $( "#t" + _pid ).addClass( "task" ).on({
539 if( process[_pid].isactive || $(this).hasClass("task-min") ) KWS.min( _pid );
541 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
542 KWS.refreshWindowIndex();
545 mouseenter: function() {
546 $("#task-ctx-name").text(data.name || 'アプリ名なし');
547 if( data.icon && data.icon != "none" ) $("#task-ctx-img").attr( "src", System.launchpath[_pid] + "/" + data.icon );
548 else $( "#task-ctx-img" ).hide();
549 $("#task-ctx-ver").text(data.version + "/pid:" + _pid);
550 $("#task-ctx-info").off().on("click", function() { System.appInfo( _pid )});
551 $("#task-ctx-sshot").off().on("click", function() { S.screenshot(_pid, true) });
552 $("#task-ctx-min").off().on("click", function() { KWS.min( String(_pid) ) });
553 if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
554 else $( "#task-ctx-front" ).show();
555 $("#task-ctx-front").off().on('click', function() {
556 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
557 KWS.refreshWindowIndex();
559 $("#task-ctx-close").off().on("click", () => System.close(_pid));
560 $("#task-ctx-kill").off().on("click", () => System.kill( data.id));
561 const _ctxleft = $(this).offset().left, _ctxtop = window.innerHeight - $(this).offset().top;
562 if( _ctxleft != $("#task-ctx").offset().left ) $("#task-ctx").hide();
563 $("#task-ctx").css("left", _ctxleft).css("bottom", _ctxtop).show();
566 $( "section, #kit-tasks" ).on( "mouseenter", function() {
567 $( "#task-ctx" ).fadeOut( 200 );
569 $( "#t" + _pid ).on({
571 prevWindowIndex = $( "#w" + _pid ).css( "z-index" );
572 $( "#w" + _pid ).addClass( "win-highlight" );
574 mouseleave: () => $( "#w" + _pid ).removeClass( "win-highlight" )
577 let _windowAppend = "<div id='w" + _pid + "'><div id='wt" + _pid + "' class='wt'><i class='wmzx'><span id='wm" + _pid + "'></span>";
578 if( data.support && data.support['fullscreen'] == true ) _windowAppend += "<span id='wz" + _pid + "'></span>";
579 _windowAppend += "<span id='wx" + _pid + "'></span></i>";
580 if( data.icon && data.icon != "none" ) _windowAppend += "<img src='" + S.launchpath[_pid] + "/" + data.icon + "'>";
581 _windowAppend += "<span id='wtname" + _pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + _pid + "'></div></div>";
582 $( "#desktop-" + currentDesktop ).append( _windowAppend );
584 if( data.support && data.support['darkmode'] == true ) $("#winc"+_pid).addClass("winc-darkmode");
585 if( KWS.darkmode ) $("#winc"+_pid).addClass("kit-darkmode");
588 $("#winc"+_pid).css("width", data.size.width).css("height", data.size.height);
591 let _minwidth = 200, _minheight = 40;
592 if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
593 if( data.resize.minHeight ) _minheight = data.resize.minHeight;
594 $("#winc"+_pid).windowResizable({
596 minHeight: _minheight
600 let windowPos = 50 + ( _pid % 10 ) * 20;
602 $( "#w"+_pid ).addClass( "window" ).pep({
603 elementsWithInteraction: ".winc, .ui-resizable-handle",
604 useCSSTranslation: false,
605 disableSelect: false,
607 initiate: function(){
608 $(this.el).addClass("ui-draggable-dragging");
610 this.el.style.zIndex = KWS.windowIndex;
611 KWS.refreshWindowIndex();
614 this.el.style.transition = "none";
615 $(this.el).removeClass("ui-draggable-dragging");
617 }).on( "mousedown", function(){
618 $(".window").css( "transition", "none" );
619 $(this).css("z-index", KWS.windowIndex + 1);
620 KWS.refreshWindowIndex();
621 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
622 KWS.refreshWindowIndex();
623 $( `#wm${_pid}` ).addClass( "wm fa fa-window-minimize" ).on("click", () => KWS.min( _pid ) );
624 $( `#wz${_pid}` ).addClass( "wz fas fa-square" ).on("click", () => KWS.max( _pid ) );
625 $( `#wx${_pid}` ).addClass( "wx fa fa-times" ).on("click", () => System.close( _pid ) );
626 $( "#winc" + _pid ).resizable( {
628 } ).load( System.launchpath[_pid] + "/" + data.view, (r, s, x) => {
630 Notification.push("起動に失敗:" + x.status, x.statusText);
633 if( !data.script || data.script != "none" ) $.getScript( System.launchpath[_pid] + "/" + data.script, () => {
634 if( !data.support || data.support['kaf'] != false ) App.kaf(_pid);
640 else if( !data.support || data.support['kaf'] != false ){
645 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
646 $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
648 localStorage.setItem( "kit-pid", pid );
649 System.launchLock = false;
653 const System = new function() {
654 this.version = "0.2.1";
655 this.username = localStorage.getItem("kit-username");
656 this.appdir = localStorage.getItem("kit-appdir");
657 this.loc = { ...location };
659 this.bootopt = new URLSearchParams(location.search);
665 "width": window.innerWidth,
666 "height": window.innerHeight
669 this.selectedElement = null;
670 this.selectedText = null;
672 this.dom = function(_pid, ..._elems) {
674 if( !_elems.length ) q = ",#winc" + _pid;
675 else for( let i of _elems ){
676 q += ",#winc" + _pid + " " + i;
678 return $( q.substring(1) );
681 this.qs = ( _pid, ..._elems ) => {
683 if( !_elems.length ) q = ",#winc" + _pid;
684 else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
685 return document.querySelectorAll( q.substring(1) )
688 this.userarea = new Object();
689 this.recycle = new Object();
695 this.launchpath = {};
697 this.support = $.support;
698 this.debugmode = false;
702 this.log = new Array();
705 this.launchLock = false;
707 this.waitLaunchUnlock = (callback) => {
710 this.waitLaunchUnlock(callback);
717 this.ajaxWait = () =>{
718 return new Promise(resolve =>{
719 System.waitLaunchUnlock(resolve);
723 this.setBattery = function(){
724 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
725 let _lv = e.level * 100;
726 System.battery = _lv;
731 this.screenshot = function( _pid, _popup ){
732 let _elem = document.querySelector("body");
733 if( _pid ) _elem = document.querySelector("#w"+_pid);
734 html2canvas( _elem ).then(canvas => {
736 canvas.style.border = "1px solid #909090";
737 S.save( canvas.toDataURL("image/png"), "image" );
743 this.obj2img = function( _obj, _popup ){
745 html2canvas( _elem ).then(canvas => {
747 canvas.style.border = "1px solid #909090";
748 S.save( canvas.toDataURL("image/png"), "image" );
754 this.save = function(data, type){
755 System.launch("fivr", { "save" : data, "type" : type });
758 this.open = function(filename){
759 System.launch("fivr", { "open" : filename });
762 this.preventClose = function( _pid ){
763 if( !process[_pid] ) return false;
764 process[_pid].preventclose = true;
768 this.shutdown = function(_opt) {
769 $( "#last-notification-close" ).click();
770 $( "#kit-power-back" ).click();
771 for( let i in process ) {
772 if( process[i].preventclose == true ){
773 S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
774 process[i].preventclose = false;
779 else System.close( i );
781 $( "section" ).hide();
782 $( "body" ).css( "background-color", "black" );
783 $( "header, footer" ).fadeOut( 300 );
784 $( "#kit-wallpaper" ).fadeOut( 1500 );
785 if( _opt == "reboot" ) location.href = "autorun.html";
786 localStorage.setItem("kit-shutted-down", true);
789 this.reboot = function() {
790 System.shutdown("reboot");
793 this.lock = function(){
794 System.moveDesktop( "l" );
796 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
797 $( "section, header, footer" ).css( "filter", "none" );
798 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
799 $( "header, footer, #kit-power" ).hide();
801 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
802 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
803 else $( "#lock-password" ).hide();
806 this.alert = function( title, content, wtitle ) {
807 System.launch("alert", [title, content, wtitle]);
810 this.dialog = function( title, content, func ){
811 System.launch("dialog", {
818 this.appInfo = function( _pid ){
819 let _title = "", _content = "";
820 let ac = System.appCache[S.launchpath[_pid]];
821 let _lp = System.launchpath[_pid];
823 _title = ac.name + " " + ac.version;
824 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
826 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
828 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
830 else _title = "取得に失敗しました";
831 System.alert( _title, _content );
834 this.apps = new Object();
835 this.installed = new Array();
837 this.close = function( _str ) {
838 let _pid = String( _str );
839 $( "#w" + _pid ).remove();
840 $( "#t" + _pid ).remove();
841 $( "#task-ctx" ).hide();
842 delete process[_pid];
843 KWS.refreshWindowIndex();
846 this.kill = function( _str ){
847 for( let _pid in process ) {
848 if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
852 this.vacuum = function( _left, _top ){
853 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
867 this.clock = function() {
870 let Year = DD.getFullYear();
871 S.time.day = DD.getDay();
873 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
875 let DateN = ( "00" + DD.getDate() ).slice( -2 );
877 let Hour = ( "00" + DD.getHours() ).slice( -2 );
879 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
881 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
883 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
884 let MS = DD.getMilliseconds();
887 outer: { radius: .9, color: "transparent" },
888 inner: { radius: .85, color: "transparent" }
891 long: { from: .8, to: .7, width: 2, color: "#303030" },
892 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
895 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
896 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
897 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
899 let canvas = $(".dropdown-clock-canvas")[0];
900 canvas.width = "200", canvas.height = "200";
901 let context = canvas.getContext("2d");
902 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
903 let radius = Math.min(center.x, center.y), angle, len;
904 context.beginPath();context.fillStyle = circle.outer.color;
905 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
906 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
907 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
909 for( let i=0; i<60; i++ ){
910 angle = Math.PI * i / 30;
912 let line = ( i%5 == 0 ) ? lines.long : lines.short;
913 context.lineWidth = line.width, context.strokeStyle = line.color;
914 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
915 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
918 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
919 context.beginPath(), context.lineWidth = hands.hour.width;
920 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
921 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
922 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
923 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
924 context.beginPath(), context.lineWidth = hands.minute.width;
925 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
926 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
927 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
928 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
929 context.beginPath(), context.lineWidth = hands.second.width;
930 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
931 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
932 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
935 this.changeWallpaper = function( str ) {
936 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
937 localStorage.setItem( "kit-wallpaper", str )
940 this.moveDesktop = function( str ) {
942 $( "section" ).hide();
943 $( "#desktop-" + str ).show();
944 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
945 currentDesktop = str;
948 this.avoidMultiple = function( _pid, _alert ) {
949 let _id = process[_pid].id;
951 for( let i in process ) {
952 if( process[i].id == _id ) _cnt += 1;
954 Notification.push( "debug", _cnt );
956 System.close( _pid );
958 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
964 this.resizable = function( _pid, _elem, _width, _height ){
966 if( _elem ) E = String( _elem );
967 if( !_width ) _width = null;
968 if( !_height ) _height = "100";
969 $("#w" + _pid).resizable({
970 alsoResize: "#w" + _pid + " " + E,
976 this.initLauncher = function(data){
977 $("#launcher-apps").html("");
979 for( let i in data ){
980 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
982 if( !System.bootopt.get('safe') ){
983 for( let i of System.installed ){
984 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
987 $('.launcher-app').on('click', function(){
988 $('#launch').click();
989 System.launch( $(this).attr('data-launch') );
993 this.launch = async function(path, args) {
994 while(this.launchLock) await this.ajaxWait();
995 this.launchLock = true;
998 System.args[_pid] = args;
1000 if(_path.lastIndexOf('/') == _path.length - 1) {
1001 _path = _path.substring(0, _path.length - 1);
1003 else if(_path.indexOf('/') == -1) {
1004 _path = System.appdir + _path;
1007 System.launchpath[_pid] = _path;
1009 if( System.appCache[_path] ) {
1010 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
1011 appData( System.appCache[_path] );
1015 $.getJSON( _path + '/define.json', appData ).fail( () => {
1016 Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
1020 Notification.push( "System Error", error, "system" );
1025 this.clip = new function(){
1026 this.content = null;
1027 this.history = new Array();
1029 this.set = function( content ){
1030 this.content = content;
1031 this.history.push(content);
1034 this.get = ()=>{ return this.content }
1037 this.config = new function(){
1038 this.apps = new Object();
1041 this.audio = new function(){
1042 this.level = localStorage["kit-audio-level"] || 100;
1043 this.silent = false;
1045 this.list = new Array();
1047 this.volume = function( _level ){
1048 $("#dropdown-sound-slider").slider("value", _level);
1051 this.play = function( _audioid, _src ){
1052 if( !System.audio.list[_audioid] ){
1053 System.audio.list[_audioid] = new Audio(_src);
1054 System.audio.list[_audioid].volume = System.audio.level / 100;
1056 System.audio.list[_audioid].play();
1059 this.get = function( _audioid ){
1060 return System.audio.list[_audioid];
1063 this.pause = function( _audioid ){
1064 System.audio.list[_audioid].pause();
1067 this.stop = function( _audioid ){
1068 System.audio.list[_audioid].pause();
1069 System.audio.list[_audioid] = null;
1072 this.seek = function( _audioid, _time ){
1073 System.audio.list[_audioid].fastSeek(_time);
1076 this.mute = function( _audioid, _bool ){
1077 System.audio.list[_audioid].muted = _bool;
1082 const KWS = new function(){
1083 this.version = "3.2.3";
1086 this.darkmode = false;
1088 this.changeWindowTitle = function( _pid, _str ){
1089 $("#tname"+_pid).text( _str );
1090 $("#wtname"+_pid).text( _str );
1093 this.min = function( _str ) {
1094 let _pid = String( _str );
1095 if( $( "#w" + _pid ).is( ":visible" ) ) {
1096 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
1097 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1098 $( "#t" + _pid ).addClass( "task-min" );
1101 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1102 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1103 $( "#t" + _pid ).removeClass( "task-min" );
1115 this.max = function( _pid ){
1116 let _appcache = System.appCache[System.launchpath[_pid]];
1117 if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
1118 Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
1121 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1122 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1123 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1124 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1125 KWS.fullscreen.pid = _pid;
1126 $( "#wt"+_pid ).addClass("wtmaximize");
1127 $( "#w"+_pid ).css({
1131 .addClass("windowmaximize")
1132 .css("z-index", KWS.windowIndex + 1);
1133 KWS.refreshWindowIndex();
1134 KWS.resize( _pid, System.display.width, System.display.height - 30 );
1136 $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
1139 this.unmax = function( _pid ){
1140 if( _pid != KWS.fullscreen.pid ){
1141 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1144 $('#wt'+_pid).removeClass("wtmaximize");
1146 "top": KWS.fullscreen.prevTop,
1147 "left": KWS.fullscreen.prevLeft
1149 .removeClass("windowmaximize");
1151 $("#kit-header-fullscreen").hide().off();
1152 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1153 KWS.fullscreen.pid = null;
1154 KWS.fullscreen.prevWidth = null;
1155 KWS.fullscreen.prevHeight = null;
1156 KWS.fullscreen.prevTop = null;
1157 KWS.fullscreen.prevLeft = null;
1159 if( !System.appCache[System.launchpath[_pid]].size.height ) {
1160 System.qs(_pid)[0].style.height = "auto";
1164 this.vacuum = function( _left, _top ){
1165 for( let i in process ){
1166 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1169 $(".window").css("transition", "none");
1174 this.windowIndex = 1;
1176 this.refreshWindowIndex = function(){
1177 let num = $(".window").length;
1178 let array = new Array();
1179 let obj = new Object();
1180 for( let i = 0; i < num; i++ ){
1181 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1184 array.sort( (a,b) => {
1185 return Number(a.zindex - b.zindex);
1187 for( let i in array ){
1188 document.getElementById(array[i].id).style.zIndex = i;
1190 $("#"+array[i].id).addClass("windowactive");
1191 $("#t"+String(array[i].id).substring(1)).addClass("t-active");
1192 KWS.active = String(array[i].id).substring(1);
1193 process[array[i].id.substring(1)].isactive = true;
1196 $("#"+array[i].id).removeClass("windowactive");
1197 $("#t"+String(array[i].id).substring(1)).removeClass("t-active");
1198 process[array[i].id.substring(1)].isactive = false;
1201 KWS.windowIndex = num;
1204 this.front = function( _pid ) {
1205 $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1206 KWS.refreshWindowIndex();
1209 this.resize = function( _pid, _width, _height ){
1210 if( _width ) $("#winc"+_pid).css("width", _width)
1211 if( _height ) $("#winc"+_pid).css("height", _height);
1214 this.setTheme = function(_name){
1215 localStorage.setItem('kit-theme', _name);
1216 if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
1217 else $('#kit-theme-file').attr('href', '');
1218 System.moveDesktop(currentDesktop);
1221 this.fusen = new function(){
1223 this.list = new Object();
1225 this.add = function(_text){
1226 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1227 $("#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>");
1228 $("#kit-f"+KWS.fusen.fid).css({
1229 "left": Number(KWS.fusen.fid)*40 + 20,
1230 "top": Number(KWS.fusen.fid)*10 + 100,
1232 elementsWithInteraction: ".kit-fusen-textarea",
1233 useCSSTranslation: false,
1234 disableSelect: false,
1236 initiate: function(){
1237 $(this.el).css("ui-opacity", "0.7");
1240 this.el.style.transition = "none";
1241 $(this.el).css("ui-opacity", "1.0");
1244 $(".kit-fusen-textarea").off().on("change",function(){
1245 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1246 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1248 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1252 this.remove = function(_fid){
1253 delete KWS.fusen.list[_fid];
1254 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1255 $("#kit-f"+_fid).remove();
1259 this.addCustomContext = function( _elem, _contextid, _obj ){
1260 KWS.context[_contextid] = _obj;
1268 "icon" : "fa-trash-alt",
1269 "function" : function(){
1270 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1276 "function" : function(){
1277 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1284 const Notification = new function() {
1286 this.list = new Object();
1288 this.goodnight = false;
1291 this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1292 let _nid = this.nid;
1293 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1296 Notification.list[_nid] = {
1300 time: System.time.obj.toLocaleString(),
1303 if( typeof _action == 'function' ) _action();
1304 else if( _pid ) KWS.front(_pid);
1305 $('#notifications').hide('drop', {direction: 'right'}, 300);
1309 if( _pid && System.appCache[System.launchpath[_pid]] ){
1310 _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
1312 if( !this.goodnight ){
1313 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1314 $('#last-notification-title').text('').text( _title );
1315 $('#last-notification-content').text('').text( _content );
1316 $('#last-notification-app').text('').html( _app );
1317 $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1318 if( _img ) $('#last-notification-img').attr('src', _img).show();
1319 else $('#last-notification-img').attr('src', '').hide();
1322 if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1323 $(`<div class='notis' id='nt${_nid}'>
1325 <span class='notis_close' id='nc${_nid}'></span>
1326 <div class='notis_app'>${_app}</div>
1327 <span>${_title}</span>
1329 <div class='notis_buttons'></div>
1330 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1331 </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1332 $(`#nc${_nid}`).on('click', (e) => {
1333 e.stopPropagation();
1334 $(`#nt${_nid}`).fadeOut(300);
1336 $('#last-notification-buttons').html('');
1338 for( let b of _buttons ){
1339 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1340 e.stopPropagation();
1343 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1344 e.stopPropagation();
1350 return (this.nid - 1);
1356 App.e[_pid] = new Object();
1357 App.d[_pid] = new Object();
1359 this.process = process[_pid];
1360 this.cache = System.appCache[System.launchpath[_pid]];
1362 this.args = System.args[_pid];
1363 this.close = () => System.close(_pid);
1364 this.d = App.d[_pid];
1365 this.dom = (..._args) => System.dom(_pid, ..._args);
1366 this.e = App.e[_pid];
1367 this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1368 this.qs = (...args) => System.qs(_pid, ...args);
1369 this.front = () => KWS.front(_pid);
1371 this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1372 this.data = (_name, _value) => App.data(_pid, _name, _value);
1373 this.event = (_name, _event) => App.event(_pid, _name, _event);
1374 this.getPath = _path => App.getPath(_pid, _path);
1375 this.kaf = () => App.kaf(_pid);
1376 this.load = _path => App.load(_pid, _path);
1377 this.preventClose = _bool => App.preventClose(_pid, _bool);
1380 static changeWindowTitle( _pid, _t ) {
1381 $( "#tname"+_pid ).text( _t );
1382 $( "#wtname"+_pid ).text( _t );
1383 process[_pid].title = _t;
1387 static context( _cid, _obj ) {
1388 KWS.context[ _cid ] = _obj;
1392 static data( _pid, _name, _value ) {
1393 if( _value !== undefined ) {
1394 S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1395 S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1396 if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1397 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1398 return App.d[_pid][_name] = _value;
1400 else if( _name ) return App.d[_pid][_name];
1401 else return App.d[_pid];
1404 static event( _pid, _name, _event ) {
1405 if( !App.e[_pid] ) App.e[_pid] = new Object();
1406 if( !_event && App.e[_pid][_name] ) App.e[_pid][_name].call();
1407 else App.e[_pid][_name] = _event;
1411 static getPath( _pid, _path ) {
1412 if( String(_path)[0] != '/' ) _path = '/' + _path;
1413 return System.launchpath[_pid] + _path;
1416 static kaf( _pid ) {
1435 const DATA = App.data(_pid);
1436 const ARGS = System.args[_pid];
1437 for( let i of S.qs(_pid, ...attrs) ){
1438 if( i.hasAttribute("kit-ref") ){
1439 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1441 if( i.hasAttribute("kit-e") ){
1442 let _eqs = i.getAttribute("kit-e").split(",");
1443 for( let k of _eqs ){
1444 let _eq = k.split(" ");
1445 $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1448 if( i.hasAttribute("kit-src") ){
1449 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1451 if( i.hasAttribute("kit-alert") ){
1452 $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
1454 if( i.hasAttribute("kit-launch") ){
1455 $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
1457 if( i.hasAttribute("kit-close") ){
1458 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1460 if( i.hasAttribute("kit-text") ){
1461 $(i).text( eval(i.getAttribute("kit-text")) );
1463 if( i.hasAttribute("kit-html") ){
1464 $(i).html( eval(i.getAttribute("kit-html")) );
1466 if( i.hasAttribute("kit:bind") ){
1467 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1468 $(i).on('keydown keyup keypress change', () => {
1469 let _name = i.getAttribute("kit:bind");
1470 App.d[_pid][_name] = i.value;
1471 S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1472 if( i.value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1473 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1476 if( i.hasAttribute("kit:observe") ){
1477 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1479 if( i.hasAttribute("kit:value") ){
1480 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1482 if( i.hasAttribute("kit-value") ){
1483 $(i).val( eval(i.getAttribute("kit-value")) );
1485 if( i.hasAttribute("kit-color") ){
1486 $(i).css('color', i.getAttribute("kit-color"));
1488 if( i.hasAttribute("kit:if") ){
1489 if( App.d[_pid][i.getAttribute("kit:if")] ){
1494 if( i.hasAttribute("kit-if") ){
1495 if( eval( i.getAttribute("kit-if")) ){
1503 static load( _pid, _path ) {
1504 if( String(_path)[0] != '/' ) _path = '/' + _path;
1505 _path = System.launchpath[_pid] + _path;
1506 S.dom(_pid).load( _path, () => {
1508 let _appcache = System.appCache[System.launchpath[_pid]];
1509 if( !KWS.fullscreen.pid && !_appcache.size.height ) {
1510 System.qs(_pid)[0].style.height = "auto";
1516 static preventClose( _pid, _bool = true ) {
1517 process[_pid].preventclose = _bool || true;
1522 App.d = new Object();
1523 App.e = new Object();
1524 App.version = "2.1.1";
1526 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;