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 for( let p in process ){
518 if( process[p].id === data.id ){
519 Notification.push('多重起動エラー', `アプリケーション「${data.name}」の多重起動は許可されていません。`, 'system');
520 System.launchLock = false;
526 process[String( _pid )] = {
528 time: System.time.obj.toLocaleString(),
533 System.appCache[System.launchpath[pid]] = data;
535 let _taskAppend = `<span id='t${_pid}'>`;
536 if( data.icon && data.icon != "none" ) _taskAppend += `<img src='${S.launchpath[_pid]}/${data.icon}'>`;
537 _taskAppend += `<span id='tname${_pid}'>${data.name}<span></span>`;
538 $( "#tasks" ).append( _taskAppend );
539 $( "#t" + _pid ).addClass( "task" ).on({
541 if( process[_pid].isactive || $(this).hasClass("task-min") ) KWS.min( _pid );
543 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
544 KWS.refreshWindowIndex();
547 mouseenter: function() {
548 $("#task-ctx-name").text(data.name || 'アプリ名なし');
549 if( data.icon && data.icon != "none" ) $("#task-ctx-img").attr( "src", System.launchpath[_pid] + "/" + data.icon );
550 else $( "#task-ctx-img" ).hide();
551 $("#task-ctx-ver").text(data.version + "/pid:" + _pid);
552 $("#task-ctx-info").off().on("click", function() { System.appInfo( _pid )});
553 $("#task-ctx-sshot").off().on("click", function() { S.screenshot(_pid, true) });
554 $("#task-ctx-min").off().on("click", function() { KWS.min( String(_pid) ) });
555 if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
556 else $( "#task-ctx-front" ).show();
557 $("#task-ctx-front").off().on('click', function() {
558 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
559 KWS.refreshWindowIndex();
561 $("#task-ctx-close").off().on("click", () => System.close(_pid));
562 $("#task-ctx-kill").off().on("click", () => System.kill( data.id));
563 const _ctxleft = $(this).offset().left, _ctxtop = window.innerHeight - $(this).offset().top;
564 if( _ctxleft != $("#task-ctx").offset().left ) $("#task-ctx").hide();
565 $("#task-ctx").css("left", _ctxleft).css("bottom", _ctxtop).show();
568 $( "section, #kit-tasks" ).on( "mouseenter", function() {
569 $( "#task-ctx" ).fadeOut( 200 );
571 $( "#t" + _pid ).on({
573 prevWindowIndex = $( "#w" + _pid ).css( "z-index" );
574 $( "#w" + _pid ).addClass( "win-highlight" );
576 mouseleave: () => $( "#w" + _pid ).removeClass( "win-highlight" )
579 let _windowAppend = "<div id='w" + _pid + "'><div id='wt" + _pid + "' class='wt'><i class='wmzx'><span id='wm" + _pid + "'></span>";
580 if( data.support && data.support['fullscreen'] == true ) _windowAppend += "<span id='wz" + _pid + "'></span>";
581 _windowAppend += "<span id='wx" + _pid + "'></span></i>";
582 if( data.icon && data.icon != "none" ) _windowAppend += "<img src='" + S.launchpath[_pid] + "/" + data.icon + "'>";
583 _windowAppend += "<span id='wtname" + _pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + _pid + "'></div></div>";
584 $( "#desktop-" + currentDesktop ).append( _windowAppend );
586 if( data.support && data.support['darkmode'] == true ) $("#winc"+_pid).addClass("winc-darkmode");
587 if( KWS.darkmode ) $("#winc"+_pid).addClass("kit-darkmode");
590 $("#winc"+_pid).css("width", data.size.width).css("height", data.size.height);
593 let _minwidth = 200, _minheight = 40;
594 if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
595 if( data.resize.minHeight ) _minheight = data.resize.minHeight;
596 $("#winc"+_pid).windowResizable({
598 minHeight: _minheight
602 let windowPos = 50 + ( _pid % 10 ) * 20;
604 $( "#w"+_pid ).addClass( "window" ).pep({
605 elementsWithInteraction: ".winc, .ui-resizable-handle",
606 useCSSTranslation: false,
607 disableSelect: false,
609 initiate: function(){
610 $(this.el).addClass("ui-draggable-dragging");
612 this.el.style.zIndex = KWS.windowIndex;
613 KWS.refreshWindowIndex();
616 this.el.style.transition = "none";
617 $(this.el).removeClass("ui-draggable-dragging");
619 }).on( "mousedown", function(){
620 $(".window").css( "transition", "none" );
621 $(this).css("z-index", KWS.windowIndex + 1);
622 KWS.refreshWindowIndex();
623 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
624 KWS.refreshWindowIndex();
625 $( `#wm${_pid}` ).addClass( "wm fa fa-window-minimize" ).on("click", () => KWS.min( _pid ) );
626 $( `#wz${_pid}` ).addClass( "wz fas fa-square" ).on("click", () => KWS.max( _pid ) );
627 $( `#wx${_pid}` ).addClass( "wx fa fa-times" ).on("click", () => System.close( _pid ) );
628 $( "#winc" + _pid ).resizable( {
630 } ).load( System.launchpath[_pid] + "/" + data.view, (r, s, x) => {
632 Notification.push("起動に失敗:" + x.status, x.statusText);
635 if( !data.script || data.script != "none" ) $.getScript( System.launchpath[_pid] + "/" + data.script, () => {
636 if( !data.support || data.support['kaf'] != false ) App.kaf(_pid);
642 else if( !data.support || data.support['kaf'] != false ){
647 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
648 $( "head" ).append( '<link href="' + System.launchpath[_pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
650 localStorage.setItem( "kit-pid", pid );
651 System.launchLock = false;
655 const System = new function() {
656 this.version = "0.2.1";
657 this.username = localStorage.getItem("kit-username");
658 this.appdir = localStorage.getItem("kit-appdir");
659 this.loc = { ...location };
661 this.bootopt = new URLSearchParams(location.search);
667 "width": window.innerWidth,
668 "height": window.innerHeight
671 this.selectedElement = null;
672 this.selectedText = null;
674 this.dom = function(_pid, ..._elems) {
676 if( !_elems.length ) q = ",#winc" + _pid;
677 else for( let i of _elems ){
678 q += ",#winc" + _pid + " " + i;
680 return $( q.substring(1) );
683 this.qs = ( _pid, ..._elems ) => {
685 if( !_elems.length ) q = ",#winc" + _pid;
686 else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
687 return document.querySelectorAll( q.substring(1) )
690 this.userarea = new Object();
691 this.recycle = new Object();
697 this.launchpath = {};
699 this.support = $.support;
700 this.debugmode = false;
704 this.log = new Array();
707 this.launchLock = false;
709 this.waitLaunchUnlock = (callback) => {
712 this.waitLaunchUnlock(callback);
719 this.ajaxWait = () =>{
720 return new Promise(resolve =>{
721 System.waitLaunchUnlock(resolve);
725 this.setBattery = function(){
726 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
727 let _lv = e.level * 100;
728 System.battery = _lv;
733 this.screenshot = function( _pid, _popup ){
734 let _elem = document.querySelector("body");
735 if( _pid ) _elem = document.querySelector("#w"+_pid);
736 html2canvas( _elem ).then(canvas => {
738 canvas.style.border = "1px solid #909090";
739 S.save( canvas.toDataURL("image/png"), "image" );
745 this.obj2img = function( _obj, _popup ){
747 html2canvas( _elem ).then(canvas => {
749 canvas.style.border = "1px solid #909090";
750 S.save( canvas.toDataURL("image/png"), "image" );
756 this.save = function(data, type){
757 System.launch("fivr", { "save" : data, "type" : type });
760 this.open = function(filename){
761 System.launch("fivr", { "open" : filename });
764 this.preventClose = function( _pid ){
765 if( !process[_pid] ) return false;
766 process[_pid].preventclose = true;
770 this.shutdown = function(_opt) {
771 $( "#last-notification-close" ).click();
772 $( "#kit-power-back" ).click();
773 for( let i in process ) {
774 if( process[i].preventclose == true ){
775 S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
776 process[i].preventclose = false;
781 else System.close( i );
783 $( "section" ).hide();
784 $( "body" ).css( "background-color", "black" );
785 $( "header, footer" ).fadeOut( 300 );
786 $( "#kit-wallpaper" ).fadeOut( 1500 );
787 if( _opt == "reboot" ) location.href = "autorun.html";
788 localStorage.setItem("kit-shutted-down", true);
791 this.reboot = function() {
792 System.shutdown("reboot");
795 this.lock = function(){
796 System.moveDesktop( "l" );
798 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
799 $( "section, header, footer" ).css( "filter", "none" );
800 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
801 $( "header, footer, #kit-power" ).hide();
803 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
804 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
805 else $( "#lock-password" ).hide();
808 this.alert = function( title, content, wtitle ) {
809 System.launch("alert", [title, content, wtitle]);
812 this.dialog = function( title, content, func ){
813 System.launch("dialog", {
820 this.appInfo = function( _pid ){
821 let _title = "", _content = "";
822 let ac = System.appCache[S.launchpath[_pid]];
823 let _lp = System.launchpath[_pid];
825 _title = ac.name + " " + ac.version;
826 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
828 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
830 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
832 else _title = "取得に失敗しました";
833 System.alert( _title, _content );
836 this.apps = new Object();
837 this.installed = new Array();
839 this.close = function( _str ) {
840 let _pid = String( _str );
841 $( "#w" + _pid ).remove();
842 $( "#t" + _pid ).remove();
843 $( "#task-ctx" ).hide();
844 delete process[_pid];
845 KWS.refreshWindowIndex();
848 this.kill = function( _str ){
849 for( let _pid in process ) {
850 if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
854 this.vacuum = function( _left, _top ){
855 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
869 this.clock = function() {
872 let Year = DD.getFullYear();
873 S.time.day = DD.getDay();
875 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
877 let DateN = ( "00" + DD.getDate() ).slice( -2 );
879 let Hour = ( "00" + DD.getHours() ).slice( -2 );
881 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
883 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
885 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
886 let MS = DD.getMilliseconds();
889 outer: { radius: .9, color: "transparent" },
890 inner: { radius: .85, color: "transparent" }
893 long: { from: .8, to: .7, width: 2, color: "#303030" },
894 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
897 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
898 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
899 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
901 let canvas = $(".dropdown-clock-canvas")[0];
902 canvas.width = "200", canvas.height = "200";
903 let context = canvas.getContext("2d");
904 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
905 let radius = Math.min(center.x, center.y), angle, len;
906 context.beginPath();context.fillStyle = circle.outer.color;
907 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
908 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
909 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
911 for( let i=0; i<60; i++ ){
912 angle = Math.PI * i / 30;
914 let line = ( i%5 == 0 ) ? lines.long : lines.short;
915 context.lineWidth = line.width, context.strokeStyle = line.color;
916 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
917 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
920 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
921 context.beginPath(), context.lineWidth = hands.hour.width;
922 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
923 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
924 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
925 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
926 context.beginPath(), context.lineWidth = hands.minute.width;
927 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
928 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
929 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
930 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
931 context.beginPath(), context.lineWidth = hands.second.width;
932 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
933 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
934 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
937 this.changeWallpaper = function( str ) {
938 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
939 localStorage.setItem( "kit-wallpaper", str )
942 this.moveDesktop = function( str ) {
944 $( "section" ).hide();
945 $( "#desktop-" + str ).show();
946 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
947 currentDesktop = str;
950 this.avoidMultiple = function( _pid, _alert ) {
951 let _id = process[_pid].id;
953 for( let i in process ) {
954 if( process[i].id == _id ) _cnt += 1;
956 Notification.push( "debug", _cnt );
958 System.close( _pid );
960 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
966 this.resizable = function( _pid, _elem, _width, _height ){
968 if( _elem ) E = String( _elem );
969 if( !_width ) _width = null;
970 if( !_height ) _height = "100";
971 $("#w" + _pid).resizable({
972 alsoResize: "#w" + _pid + " " + E,
978 this.initLauncher = function(data){
979 $("#launcher-apps").html("");
981 for( let i in data ){
982 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
984 if( !System.bootopt.get('safe') ){
985 for( let i of System.installed ){
986 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
989 $('.launcher-app').on('click', function(){
990 $('#launch').click();
991 System.launch( $(this).attr('data-launch') );
995 this.launch = async function(path, args) {
996 while(this.launchLock) await this.ajaxWait();
997 this.launchLock = true;
1000 System.args[_pid] = args;
1002 if(_path.lastIndexOf('/') == _path.length - 1) {
1003 _path = _path.substring(0, _path.length - 1);
1005 else if(_path.indexOf('/') == -1) {
1006 _path = System.appdir + _path;
1009 System.launchpath[_pid] = _path;
1011 if( System.appCache[_path] ) {
1012 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
1013 appData( System.appCache[_path] );
1017 $.getJSON( _path + '/define.json', appData ).fail( () => {
1018 Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
1022 Notification.push( "System Error", error, "system" );
1027 this.clip = new function(){
1028 this.content = null;
1029 this.history = new Array();
1031 this.set = function( content ){
1032 this.content = content;
1033 this.history.push(content);
1036 this.get = ()=>{ return this.content }
1039 this.config = new function(){
1040 this.apps = new Object();
1043 this.audio = new function(){
1044 this.level = localStorage["kit-audio-level"] || 100;
1045 this.silent = false;
1047 this.list = new Array();
1049 this.volume = function( _level ){
1050 $("#dropdown-sound-slider").slider("value", _level);
1053 this.play = function( _audioid, _src ){
1054 if( !System.audio.list[_audioid] ){
1055 System.audio.list[_audioid] = new Audio(_src);
1056 System.audio.list[_audioid].volume = System.audio.level / 100;
1058 System.audio.list[_audioid].play();
1061 this.get = function( _audioid ){
1062 return System.audio.list[_audioid];
1065 this.pause = function( _audioid ){
1066 System.audio.list[_audioid].pause();
1069 this.stop = function( _audioid ){
1070 System.audio.list[_audioid].pause();
1071 System.audio.list[_audioid] = null;
1074 this.seek = function( _audioid, _time ){
1075 System.audio.list[_audioid].fastSeek(_time);
1078 this.mute = function( _audioid, _bool ){
1079 System.audio.list[_audioid].muted = _bool;
1084 const KWS = new function(){
1085 this.version = "3.2.3";
1088 this.darkmode = false;
1090 this.changeWindowTitle = function( _pid, _str ){
1091 $("#tname"+_pid).text( _str );
1092 $("#wtname"+_pid).text( _str );
1095 this.min = function( _str ) {
1096 let _pid = String( _str );
1097 if( $( "#w" + _pid ).is( ":visible" ) ) {
1098 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
1099 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1100 $( "#t" + _pid ).addClass( "task-min" );
1103 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1104 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1105 $( "#t" + _pid ).removeClass( "task-min" );
1117 this.max = function( _pid ){
1118 let _appcache = System.appCache[System.launchpath[_pid]];
1119 if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
1120 Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
1123 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1124 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1125 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1126 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1127 KWS.fullscreen.pid = _pid;
1128 $( "#wt"+_pid ).addClass("wtmaximize");
1129 $( "#w"+_pid ).css({
1133 .addClass("windowmaximize")
1134 .css("z-index", KWS.windowIndex + 1);
1135 KWS.refreshWindowIndex();
1136 KWS.resize( _pid, System.display.width, System.display.height - 30 );
1138 $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
1141 this.unmax = function( _pid ){
1142 if( _pid != KWS.fullscreen.pid ){
1143 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1146 $('#wt'+_pid).removeClass("wtmaximize");
1148 "top": KWS.fullscreen.prevTop,
1149 "left": KWS.fullscreen.prevLeft
1151 .removeClass("windowmaximize");
1153 $("#kit-header-fullscreen").hide().off();
1154 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1155 KWS.fullscreen.pid = null;
1156 KWS.fullscreen.prevWidth = null;
1157 KWS.fullscreen.prevHeight = null;
1158 KWS.fullscreen.prevTop = null;
1159 KWS.fullscreen.prevLeft = null;
1161 if( !System.appCache[System.launchpath[_pid]].size.height ) {
1162 System.qs(_pid)[0].style.height = "auto";
1166 this.vacuum = function( _left, _top ){
1167 for( let i in process ){
1168 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1171 $(".window").css("transition", "none");
1176 this.windowIndex = 1;
1178 this.refreshWindowIndex = function(){
1179 let num = $(".window").length;
1180 let array = new Array();
1181 let obj = new Object();
1182 for( let i = 0; i < num; i++ ){
1183 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1186 array.sort( (a,b) => {
1187 return Number(a.zindex - b.zindex);
1189 for( let i in array ){
1190 document.getElementById(array[i].id).style.zIndex = i;
1191 let _pid = String(array[i].id).substring(1);
1193 $("#"+array[i].id).addClass("windowactive");
1194 $("#t"+_pid).addClass("t-active");
1196 process[_pid].isactive = true;
1197 KWS.screenPrevSwitched = new Date();
1198 localStorage.setItem('kit-screentime', JSON.stringify(KWS.screenTime));
1201 $("#"+array[i].id).removeClass("windowactive");
1202 $("#t"+_pid).removeClass("t-active");
1203 process[_pid].isactive = false;
1204 if( KWS.active == _pid ){
1205 let _diff = (new Date() - KWS.screenPrevSwitched);
1206 let _appid = process[_pid].id
1207 if( !KWS.screenTime[_appid] ) KWS.screenTime[_appid] = new Number();
1208 if( _diff < 0 ) Notification.push('debug', 'スクリーンタイムの記録に失敗しました。', 'system')
1209 else KWS.screenTime[_appid] += _diff;
1213 KWS.windowIndex = num;
1216 this.front = function( _pid ) {
1217 $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1218 KWS.refreshWindowIndex();
1221 this.resize = function( _pid, _width, _height ){
1222 if( _width ) $("#winc"+_pid).css("width", _width)
1223 if( _height ) $("#winc"+_pid).css("height", _height);
1226 this.setTheme = function(_name){
1227 localStorage.setItem('kit-theme', _name);
1228 if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
1229 else $('#kit-theme-file').attr('href', '');
1230 System.moveDesktop(currentDesktop);
1233 this.screenTime = new Object();
1235 this.screenPrevSwitched = new Date();
1237 this.fusen = new function(){
1239 this.list = new Object();
1241 this.add = function(_text){
1242 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1243 $("#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>");
1244 $("#kit-f"+KWS.fusen.fid).css({
1245 "left": Number(KWS.fusen.fid)*40 + 20,
1246 "top": Number(KWS.fusen.fid)*10 + 100,
1248 elementsWithInteraction: ".kit-fusen-textarea",
1249 useCSSTranslation: false,
1250 disableSelect: false,
1252 initiate: function(){
1253 $(this.el).css("ui-opacity", "0.7");
1256 this.el.style.transition = "none";
1257 $(this.el).css("ui-opacity", "1.0");
1260 $(".kit-fusen-textarea").off().on("change",function(){
1261 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1262 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1264 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1268 this.remove = function(_fid){
1269 delete KWS.fusen.list[_fid];
1270 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1271 $("#kit-f"+_fid).remove();
1275 this.addCustomContext = function( _elem, _contextid, _obj ){
1276 KWS.context[_contextid] = _obj;
1284 "icon" : "fa-trash-alt",
1285 "function" : function(){
1286 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1292 "function" : function(){
1293 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1300 const Notification = new function() {
1302 this.list = new Object();
1304 this.goodnight = false;
1307 this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1308 let _nid = this.nid;
1309 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1312 Notification.list[_nid] = {
1316 time: System.time.obj.toLocaleString(),
1319 if( typeof _action == 'function' ) _action();
1320 else if( _pid ) KWS.front(_pid);
1321 $('#notifications').hide('drop', {direction: 'right'}, 300);
1325 if( _pid && System.appCache[System.launchpath[_pid]] ){
1326 _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
1328 if( !this.goodnight ){
1329 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1330 $('#last-notification-title').text('').text( _title );
1331 $('#last-notification-content').text('').text( _content );
1332 $('#last-notification-app').text('').html( _app );
1333 $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1334 if( _img ) $('#last-notification-img').attr('src', _img).show();
1335 else $('#last-notification-img').attr('src', '').hide();
1338 if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1339 $(`<div class='notis' id='nt${_nid}'>
1341 <span class='notis_close' id='nc${_nid}'></span>
1342 <div class='notis_app'>${_app}</div>
1343 <span>${_title}</span>
1345 <div class='notis_buttons'></div>
1346 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1347 </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1348 $(`#nc${_nid}`).on('click', (e) => {
1349 e.stopPropagation();
1350 $(`#nt${_nid}`).fadeOut(300);
1352 $('#last-notification-buttons').html('');
1354 for( let b of _buttons ){
1355 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1356 e.stopPropagation();
1359 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1360 e.stopPropagation();
1366 return (this.nid - 1);
1372 App.e[_pid] = new Object();
1373 App.d[_pid] = new Object();
1375 this.process = process[_pid];
1376 this.cache = System.appCache[System.launchpath[_pid]];
1378 this.args = System.args[_pid];
1379 this.close = () => System.close(_pid);
1380 this.d = App.d[_pid];
1381 this.dom = (..._args) => System.dom(_pid, ..._args);
1382 this.e = App.e[_pid];
1383 this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1384 this.qs = (...args) => System.qs(_pid, ...args);
1385 this.front = () => KWS.front(_pid);
1387 this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1388 this.data = (_name, _value) => App.data(_pid, _name, _value);
1389 this.event = (_name, _event) => App.event(_pid, _name, _event);
1390 this.getPath = _path => App.getPath(_pid, _path);
1391 this.kaf = () => App.kaf(_pid);
1392 this.load = _path => App.load(_pid, _path);
1393 this.preventClose = _bool => App.preventClose(_pid, _bool);
1396 static changeWindowTitle( _pid, _t ) {
1397 $( "#tname"+_pid ).text( _t );
1398 $( "#wtname"+_pid ).text( _t );
1399 process[_pid].title = _t;
1403 static context( _cid, _obj ) {
1404 KWS.context[ _cid ] = _obj;
1408 static data( _pid, _name, _value ) {
1409 if( _value !== undefined ) {
1410 S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1411 S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1412 if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1413 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1414 return App.d[_pid][_name] = _value;
1416 else if( _name ) return App.d[_pid][_name];
1417 else return App.d[_pid];
1420 static event( _pid, _name, _event ) {
1421 if( !App.e[_pid] ) App.e[_pid] = new Object();
1422 if( !_event && App.e[_pid][_name] ) App.e[_pid][_name].call();
1423 else App.e[_pid][_name] = _event;
1427 static getPath( _pid, _path ) {
1428 if( String(_path)[0] != '/' ) _path = '/' + _path;
1429 return System.launchpath[_pid] + _path;
1432 static kaf( _pid ) {
1451 const DATA = App.data(_pid);
1452 const ARGS = System.args[_pid];
1453 for( let i of S.qs(_pid, ...attrs) ){
1454 if( i.hasAttribute("kit-ref") ){
1455 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1457 if( i.hasAttribute("kit-e") ){
1458 let _eqs = i.getAttribute("kit-e").split(",");
1459 for( let k of _eqs ){
1460 let _eq = k.split(" ");
1461 $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1464 if( i.hasAttribute("kit-src") ){
1465 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1467 if( i.hasAttribute("kit-alert") ){
1468 $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
1470 if( i.hasAttribute("kit-launch") ){
1471 $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
1473 if( i.hasAttribute("kit-close") ){
1474 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1476 if( i.hasAttribute("kit-text") ){
1477 $(i).text( eval(i.getAttribute("kit-text")) );
1479 if( i.hasAttribute("kit-html") ){
1480 $(i).html( eval(i.getAttribute("kit-html")) );
1482 if( i.hasAttribute("kit:bind") ){
1483 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1484 $(i).on('keydown keyup keypress change', () => {
1485 let _name = i.getAttribute("kit:bind");
1486 App.d[_pid][_name] = i.value;
1487 S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1488 if( i.value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
1489 else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1492 if( i.hasAttribute("kit:observe") ){
1493 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1495 if( i.hasAttribute("kit:value") ){
1496 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1498 if( i.hasAttribute("kit-value") ){
1499 $(i).val( eval(i.getAttribute("kit-value")) );
1501 if( i.hasAttribute("kit-color") ){
1502 $(i).css('color', i.getAttribute("kit-color"));
1504 if( i.hasAttribute("kit:if") ){
1505 if( App.d[_pid][i.getAttribute("kit:if")] ){
1510 if( i.hasAttribute("kit-if") ){
1511 if( eval( i.getAttribute("kit-if")) ){
1519 static load( _pid, _path ) {
1520 if( String(_path)[0] != '/' ) _path = '/' + _path;
1521 _path = System.launchpath[_pid] + _path;
1522 S.dom(_pid).load( _path, () => {
1524 let _appcache = System.appCache[System.launchpath[_pid]];
1525 if( !KWS.fullscreen.pid && !_appcache.size.height ) {
1526 System.qs(_pid)[0].style.height = "auto";
1532 static preventClose( _pid, _bool = true ) {
1533 process[_pid].preventclose = _bool || true;
1538 App.d = new Object();
1539 App.e = new Object();
1540 App.version = "2.1.1";
1542 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;