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) {
516 if(data.support && data.support.multiple == false){
517 if( Object.values(process).map(p => p.id).includes(data.id) ){
518 Notification.push('多重起動エラー', `アプリケーション「${data.name}」の多重起動は許可されていません。`, 'system');
519 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 if( data.support && data.support['fullscreen'] == true ) $( `#wt${_pid}` ).on("dblclick", () => KWS.max( _pid ));
624 $( `#wm${_pid}` ).addClass("wm fa fa-window-minimize").on("click", () => KWS.min( _pid ));
625 $( `#wz${_pid}` ).addClass("wz fas fa-square").on("click", () => KWS.max( _pid ));
626 $( `#wx${_pid}` ).addClass("wx fa fa-times").on("click", () => System.close( _pid ));
627 $( "#winc" + _pid ).resizable( {
629 } ).load( System.launchpath[_pid] + "/" + data.view, (r, s, x) => {
631 Notification.push("起動に失敗:" + x.status, x.statusText);
634 if( !data.script || data.script != "none" ) $.getScript( System.launchpath[_pid] + "/" + data.script, () => {
635 if( !data.support || data.support['kaf'] != false ) App.kaf(_pid);
641 else if( !data.support || data.support['kaf'] != false ){
646 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
647 $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
649 localStorage.setItem( "kit-pid", pid );
650 System.launchLock = false;
654 const System = new function() {
655 this.version = "0.2.1";
656 this.username = localStorage.getItem("kit-username");
657 this.appdir = localStorage.getItem("kit-appdir");
658 this.loc = { ...location };
660 this.bootopt = new URLSearchParams(location.search);
666 "width": window.innerWidth,
667 "height": window.innerHeight
670 this.selectedElement = null;
671 this.selectedText = null;
673 this.dom = function(_pid, ..._elems) {
675 if( !_elems.length ) q = ",#winc" + _pid;
676 else for( let i of _elems ){
677 q += ",#winc" + _pid + " " + i;
679 return $( q.substring(1) );
682 this.qs = ( _pid, ..._elems ) => {
684 if( !_elems.length ) q = ",#winc" + _pid;
685 else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
686 return document.querySelectorAll( q.substring(1) )
689 this.userarea = new Object();
690 this.recycle = new Object();
696 this.launchpath = {};
698 this.support = $.support;
699 this.debugmode = false;
703 this.log = new Array();
706 this.launchLock = false;
708 this.waitLaunchUnlock = (callback) => {
711 this.waitLaunchUnlock(callback);
718 this.ajaxWait = () =>{
719 return new Promise(resolve =>{
720 System.waitLaunchUnlock(resolve);
724 this.setBattery = function(){
725 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
726 let _lv = e.level * 100;
727 System.battery = _lv;
732 this.screenshot = function( _pid, _popup ){
733 let _elem = document.querySelector("body");
734 if( _pid ) _elem = document.querySelector("#w"+_pid);
735 html2canvas( _elem ).then(canvas => {
737 canvas.style.border = "1px solid #909090";
738 S.save( canvas.toDataURL("image/png"), "image" );
744 this.obj2img = function( _obj, _popup ){
746 html2canvas( _elem ).then(canvas => {
748 canvas.style.border = "1px solid #909090";
749 S.save( canvas.toDataURL("image/png"), "image" );
755 this.save = function(data, type){
756 System.launch("fivr", { "save" : data, "type" : type });
759 this.open = function(filename){
760 System.launch("fivr", { "open" : filename });
763 this.preventClose = function( _pid ){
764 if( !process[_pid] ) return false;
765 process[_pid].preventclose = true;
769 this.shutdown = function(_opt) {
770 $( "#last-notification-close" ).click();
771 $( "#kit-power-back" ).click();
772 for( let i in process ) {
773 if( process[i].preventclose == true ){
774 S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
775 process[i].preventclose = false;
780 else System.close( i );
782 $( "section" ).hide();
783 $( "body" ).css( "background-color", "black" );
784 $( "header, footer" ).fadeOut( 300 );
785 $( "#kit-wallpaper" ).fadeOut( 1500 );
786 if( _opt == "reboot" ) location.href = "autorun.html";
787 localStorage.setItem("kit-shutted-down", true);
790 this.reboot = function() {
791 System.shutdown("reboot");
794 this.lock = function(){
795 System.moveDesktop( "l" );
797 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
798 $( "section, header, footer" ).css( "filter", "none" );
799 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
800 $( "header, footer, #kit-power" ).hide();
802 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
803 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
804 else $( "#lock-password" ).hide();
807 this.alert = function( title, content, wtitle ) {
808 System.launch("alert", [title, content, wtitle]);
811 this.dialog = function( title, content, func ){
812 System.launch("dialog", {
819 this.appInfo = function( _pid ){
820 let _title = "", _content = "";
821 let ac = System.appCache[S.launchpath[_pid]];
822 let _lp = System.launchpath[_pid];
824 _title = ac.name + " " + ac.version;
825 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
827 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
829 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
831 else _title = "取得に失敗しました";
832 System.alert( _title, _content );
835 this.apps = new Object();
836 this.installed = new Array();
838 this.close = function( _str ) {
839 let _pid = String( _str );
840 $( "#w" + _pid ).remove();
841 $( "#t" + _pid ).remove();
842 $( "#task-ctx" ).hide();
843 delete process[_pid];
844 KWS.refreshWindowIndex();
847 this.kill = function( _str ){
848 for( let _pid in process ) {
849 if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
853 this.vacuum = function( _left, _top ){
854 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
868 this.clock = function() {
871 let Year = DD.getFullYear();
872 S.time.day = DD.getDay();
874 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
876 let DateN = ( "00" + DD.getDate() ).slice( -2 );
878 let Hour = ( "00" + DD.getHours() ).slice( -2 );
880 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
882 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
884 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
885 let MS = DD.getMilliseconds();
888 outer: { radius: .9, color: "transparent" },
889 inner: { radius: .85, color: "transparent" }
892 long: { from: .8, to: .7, width: 2, color: "#303030" },
893 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
896 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
897 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
898 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
900 let canvas = $(".dropdown-clock-canvas")[0];
901 canvas.width = "200", canvas.height = "200";
902 let context = canvas.getContext("2d");
903 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
904 let radius = Math.min(center.x, center.y), angle, len;
905 context.beginPath();context.fillStyle = circle.outer.color;
906 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
907 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
908 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
910 for( let i=0; i<60; i++ ){
911 angle = Math.PI * i / 30;
913 let line = ( i%5 == 0 ) ? lines.long : lines.short;
914 context.lineWidth = line.width, context.strokeStyle = line.color;
915 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
916 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
919 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
920 context.beginPath(), context.lineWidth = hands.hour.width;
921 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
922 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
923 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
924 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
925 context.beginPath(), context.lineWidth = hands.minute.width;
926 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
927 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
928 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
929 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
930 context.beginPath(), context.lineWidth = hands.second.width;
931 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
932 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
933 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
936 this.changeWallpaper = function( str ) {
937 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
938 localStorage.setItem( "kit-wallpaper", str )
941 this.moveDesktop = function( str ) {
943 $( "section" ).hide();
944 $( "#desktop-" + str ).show();
945 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
946 currentDesktop = str;
949 this.avoidMultiple = function( _pid, _alert ) {
950 let _id = process[_pid].id;
952 for( let i in process ) {
953 if( process[i].id == _id ) _cnt += 1;
955 Notification.push( "debug", _cnt );
957 System.close( _pid );
959 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
965 this.resizable = function( _pid, _elem, _width, _height ){
967 if( _elem ) E = String( _elem );
968 if( !_width ) _width = null;
969 if( !_height ) _height = "100";
970 $("#w" + _pid).resizable({
971 alsoResize: "#w" + _pid + " " + E,
977 this.initLauncher = function(data){
978 $("#launcher-apps").html("");
980 for( let i in data ){
981 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
983 if( !System.bootopt.get('safe') ){
984 for( let i of System.installed ){
985 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
988 $('.launcher-app').on('click', function(){
989 $('#launch').click();
990 System.launch( $(this).attr('data-launch') );
994 this.launch = async function(path, args) {
995 while(this.launchLock) await this.ajaxWait();
996 this.launchLock = true;
999 System.args[_pid] = args;
1001 if(_path.lastIndexOf('/') == _path.length - 1) {
1002 _path = _path.substring(0, _path.length - 1);
1004 else if(_path.indexOf('/') == -1) {
1005 _path = System.appdir + _path;
1008 System.launchpath[_pid] = _path;
1010 if( System.appCache[_path] ) {
1011 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
1012 appData( System.appCache[_path] );
1016 $.getJSON( _path + '/define.json', appData ).fail( () => {
1017 Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
1021 Notification.push( "System Error", error, "system" );
1026 this.clip = new function(){
1027 this.content = null;
1028 this.history = new Array();
1030 this.set = function( content ){
1031 this.content = content;
1032 this.history.push(content);
1035 this.get = ()=>{ return this.content }
1038 this.config = new function(){
1039 this.apps = new Object();
1042 this.audio = new function(){
1043 this.level = localStorage["kit-audio-level"] || 100;
1044 this.silent = false;
1046 this.list = new Array();
1048 this.volume = function( _level ){
1049 $("#dropdown-sound-slider").slider("value", _level);
1052 this.play = function( _audioid, _src ){
1053 if( !System.audio.list[_audioid] ){
1054 System.audio.list[_audioid] = new Audio(_src);
1055 System.audio.list[_audioid].volume = System.audio.level / 100;
1057 System.audio.list[_audioid].play();
1060 this.get = function( _audioid ){
1061 return System.audio.list[_audioid];
1064 this.pause = function( _audioid ){
1065 System.audio.list[_audioid].pause();
1068 this.stop = function( _audioid ){
1069 System.audio.list[_audioid].pause();
1070 System.audio.list[_audioid] = null;
1073 this.seek = function( _audioid, _time ){
1074 System.audio.list[_audioid].fastSeek(_time);
1077 this.mute = function( _audioid, _bool ){
1078 System.audio.list[_audioid].muted = _bool;
1083 const KWS = new function(){
1084 this.version = "3.2.3";
1087 this.darkmode = false;
1089 this.changeWindowTitle = function( _pid, _str ){
1090 $("#tname"+_pid).text( _str );
1091 $("#wtname"+_pid).text( _str );
1094 this.min = function( _str ) {
1095 let _pid = String( _str );
1096 if( $( "#w" + _pid ).is( ":visible" ) ) {
1097 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
1098 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1099 $( "#t" + _pid ).addClass( "task-min" );
1102 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1103 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1104 $( "#t" + _pid ).removeClass( "task-min" );
1116 this.max = function( _pid ){
1117 let _appcache = System.appCache[System.launchpath[_pid]];
1118 if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
1119 Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
1122 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1123 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1124 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1125 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1126 KWS.fullscreen.pid = _pid;
1127 $( "#wt"+_pid ).addClass("wtmaximize");
1128 $( "#w"+_pid ).css({
1132 .addClass("windowmaximize")
1133 .css("z-index", KWS.windowIndex + 1);
1134 KWS.refreshWindowIndex();
1135 KWS.resize( _pid, System.display.width, System.display.height - 30 );
1137 $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
1140 this.unmax = function( _pid ){
1141 if( _pid != KWS.fullscreen.pid ){
1142 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1145 $('#wt'+_pid).removeClass("wtmaximize");
1147 "top": KWS.fullscreen.prevTop,
1148 "left": KWS.fullscreen.prevLeft
1150 .removeClass("windowmaximize");
1152 $("#kit-header-fullscreen").hide().off();
1153 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1154 KWS.fullscreen.pid = null;
1155 KWS.fullscreen.prevWidth = null;
1156 KWS.fullscreen.prevHeight = null;
1157 KWS.fullscreen.prevTop = null;
1158 KWS.fullscreen.prevLeft = null;
1160 if( !System.appCache[System.launchpath[_pid]].size.height ) {
1161 System.qs(_pid)[0].style.height = "auto";
1165 this.vacuum = function( _left, _top ){
1166 for( let i in process ){
1167 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1170 $(".window").css("transition", "none");
1175 this.windowIndex = 1;
1177 this.refreshWindowIndex = function(){
1178 let num = $(".window").length;
1179 let array = new Array();
1180 let obj = new Object();
1181 for( let i = 0; i < num; i++ ){
1182 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1185 array.sort( (a,b) => {
1186 return Number(a.zindex - b.zindex);
1188 for( let i in array ){
1189 document.getElementById(array[i].id).style.zIndex = i;
1190 let _pid = String(array[i].id).substring(1);
1192 $("#"+array[i].id).addClass("windowactive");
1193 $("#t"+_pid).addClass("t-active");
1195 process[_pid].isactive = true;
1196 KWS.screenPrevSwitched = new Date();
1197 localStorage.setItem('kit-screentime', JSON.stringify(KWS.screenTime));
1200 $("#"+array[i].id).removeClass("windowactive");
1201 $("#t"+_pid).removeClass("t-active");
1202 process[_pid].isactive = false;
1203 if( KWS.active == _pid ){
1204 let _diff = (new Date() - KWS.screenPrevSwitched);
1205 let _appid = process[_pid].id
1206 if( !KWS.screenTime[_appid] ) KWS.screenTime[_appid] = new Number();
1207 if( _diff < 0 ) Notification.push('debug', 'スクリーンタイムの記録に失敗しました。', 'system')
1208 else KWS.screenTime[_appid] += _diff;
1212 KWS.windowIndex = num;
1215 this.front = function( _pid ) {
1216 $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1217 KWS.refreshWindowIndex();
1220 this.resize = function( _pid, _width, _height ){
1221 if( _width ) $("#winc"+_pid).css("width", _width)
1222 if( _height ) $("#winc"+_pid).css("height", _height);
1225 this.setTheme = function(_name){
1226 localStorage.setItem('kit-theme', _name);
1227 if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
1228 else $('#kit-theme-file').attr('href', '');
1229 System.moveDesktop(currentDesktop);
1232 this.screenTime = new Object();
1234 this.screenPrevSwitched = new Date();
1236 this.fusen = new function(){
1238 this.list = new Object();
1240 this.add = function(_text){
1241 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1242 $("#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>");
1243 $("#kit-f"+KWS.fusen.fid).css({
1244 "left": Number(KWS.fusen.fid)*40 + 20,
1245 "top": Number(KWS.fusen.fid)*10 + 100,
1247 elementsWithInteraction: ".kit-fusen-textarea",
1248 useCSSTranslation: false,
1249 disableSelect: false,
1251 initiate: function(){
1252 $(this.el).css("ui-opacity", "0.7");
1255 this.el.style.transition = "none";
1256 $(this.el).css("ui-opacity", "1.0");
1259 $(".kit-fusen-textarea").off().on("change",function(){
1260 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1261 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1263 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1267 this.remove = function(_fid){
1268 delete KWS.fusen.list[_fid];
1269 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1270 $("#kit-f"+_fid).remove();
1274 this.addCustomContext = function( _elem, _contextid, _obj ){
1275 KWS.context[_contextid] = _obj;
1283 "icon" : "fa-trash-alt",
1284 "function" : function(){
1285 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1291 "function" : function(){
1292 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1299 const Notification = new function() {
1301 this.list = new Object();
1303 this.goodnight = false;
1306 this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1307 let _nid = this.nid;
1308 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1311 Notification.list[_nid] = {
1315 time: System.time.obj.toLocaleString(),
1318 if( typeof _action == 'function' ) _action();
1319 else if( _pid ) KWS.front(_pid);
1320 $('#notifications').hide('drop', {direction: 'right'}, 300);
1324 if( _pid && System.appCache[System.launchpath[_pid]] ){
1325 _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
1327 if( !this.goodnight ){
1328 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1329 $('#last-notification-title').text('').text( _title );
1330 $('#last-notification-content').text('').text( _content );
1331 $('#last-notification-app').text('').html( _app );
1332 $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1333 if( _img ) $('#last-notification-img').attr('src', _img).show();
1334 else $('#last-notification-img').attr('src', '').hide();
1337 if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1338 $(`<div class='notis' id='nt${_nid}'>
1340 <span class='notis_close' id='nc${_nid}'></span>
1341 <div class='notis_app'>${_app}</div>
1342 <span>${_title}</span>
1344 <div class='notis_buttons'></div>
1345 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1346 </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1347 $(`#nc${_nid}`).on('click', (e) => {
1348 e.stopPropagation();
1349 $(`#nt${_nid}`).fadeOut(300);
1351 $('#last-notification-buttons').html('');
1353 for( let b of _buttons ){
1354 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1355 e.stopPropagation();
1358 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1359 e.stopPropagation();
1365 return (this.nid - 1);
1371 App.e[_pid] = new Object();
1372 App.d[_pid] = new Object();
1374 this.process = process[_pid];
1375 this.cache = System.appCache[System.launchpath[_pid]];
1377 this.args = System.args[_pid];
1378 this.close = () => System.close(_pid);
1379 this.d = App.d[_pid];
1380 this.dom = (..._args) => System.dom(_pid, ..._args);
1381 this.e = App.e[_pid];
1382 this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1383 this.qs = (...args) => System.qs(_pid, ...args);
1384 this.front = () => KWS.front(_pid);
1386 this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1387 this.data = (_name, _value) => App.data(_pid, _name, _value);
1388 this.event = (_name, _event) => App.event(_pid, _name, _event);
1389 this.getPath = _path => App.getPath(_pid, _path);
1390 this.kaf = () => App.kaf(_pid);
1391 this.load = _path => App.load(_pid, _path);
1392 this.preventClose = _bool => App.preventClose(_pid, _bool);
1395 static changeWindowTitle( _pid, _t ) {
1396 $( "#tname"+_pid ).text( _t );
1397 $( "#wtname"+_pid ).text( _t );
1398 process[_pid].title = _t;
1402 static context( _cid, _obj ) {
1403 KWS.context[ _cid ] = _obj;
1407 static data( _pid, _name, _value ) {
1408 if( _value !== undefined ) {
1409 S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1410 S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1411 if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1412 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1413 return App.d[_pid][_name] = _value;
1415 else if( _name ) return App.d[_pid][_name];
1416 else return App.d[_pid];
1419 static event( _pid, _name, _event ) {
1420 if( !App.e[_pid] ) App.e[_pid] = new Object();
1421 if( !_event && App.e[_pid][_name] ) App.e[_pid][_name].call();
1422 else App.e[_pid][_name] = _event;
1426 static getPath( _pid, _path ) {
1427 if( String(_path)[0] != '/' ) _path = '/' + _path;
1428 return System.launchpath[_pid] + _path;
1431 static kaf( _pid ) {
1450 const DATA = App.data(_pid);
1451 const ARGS = System.args[_pid];
1452 for( let i of S.qs(_pid, ...attrs) ){
1453 if( i.hasAttribute("kit-ref") ){
1454 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1456 if( i.hasAttribute("kit-e") ){
1457 let _eqs = i.getAttribute("kit-e").split(",");
1458 for( let k of _eqs ){
1459 let _eq = k.split(" ");
1460 $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1463 if( i.hasAttribute("kit-src") ){
1464 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1466 if( i.hasAttribute("kit-alert") ){
1467 $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
1469 if( i.hasAttribute("kit-launch") ){
1470 $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
1472 if( i.hasAttribute("kit-close") ){
1473 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1475 if( i.hasAttribute("kit-text") ){
1476 $(i).text( eval(i.getAttribute("kit-text")) );
1478 if( i.hasAttribute("kit-html") ){
1479 $(i).html( eval(i.getAttribute("kit-html")) );
1481 if( i.hasAttribute("kit:bind") ){
1482 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1483 $(i).on('keydown keyup keypress change', () => {
1484 let _name = i.getAttribute("kit:bind");
1485 App.d[_pid][_name] = i.value;
1486 S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1487 if( i.value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1488 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1491 if( i.hasAttribute("kit:observe") ){
1492 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1494 if( i.hasAttribute("kit:value") ){
1495 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1497 if( i.hasAttribute("kit-value") ){
1498 $(i).val( eval(i.getAttribute("kit-value")) );
1500 if( i.hasAttribute("kit-color") ){
1501 $(i).css('color', i.getAttribute("kit-color"));
1503 if( i.hasAttribute("kit:if") ){
1504 if( App.d[_pid][i.getAttribute("kit:if")] ){
1509 if( i.hasAttribute("kit-if") ){
1510 if( eval( i.getAttribute("kit-if")) ){
1518 static load( _pid, _path ) {
1519 if( String(_path)[0] != '/' ) _path = '/' + _path;
1520 _path = System.launchpath[_pid] + _path;
1521 S.dom(_pid).load( _path, () => {
1523 let _appcache = System.appCache[System.launchpath[_pid]];
1524 if( !KWS.fullscreen.pid && !_appcache.size.height ) {
1525 System.qs(_pid)[0].style.height = "auto";
1531 static preventClose( _pid, _bool = true ) {
1532 process[_pid].preventclose = _bool || true;
1537 App.d = new Object();
1538 App.e = new Object();
1539 App.version = "2.1.1";
1541 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;