9 // THIS IS THE KIT KERNEL, KIT APPS FRAMEWORK AND KIT WINDOW SYSTEM
10 // http://web.kitit.ml/
11 // https://github.com/mtsgi/kit
13 // Copyright 2020 mtsgi
15 // Licensed under the Apache License, Version 2.0 (the "License");
16 // you may not use this file except in compliance with the License.
17 // You may obtain a copy of the License at
19 // http://www.apache.org/licenses/LICENSE-2.0
21 // Unless required by applicable law or agreed to in writing, software
22 // distributed under the License is distributed on an "AS IS" BASIS,
23 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 // See the License for the specific language governing permissions and
25 // limitations under the License.
27 $( document ).ready( kit );
32 if( localStorage.getItem( "kit-pid" ) ) pid = localStorage.getItem( "kit-pid" );
34 if( !localStorage.getItem( "kit-username" ) ) localStorage.setItem( "kit-username", "ユーザー" );
35 $( "#kit-header-username" ).text( localStorage.getItem( "kit-username" ) );
37 if( localStorage.getItem( "kit-lock" ) == null ) localStorage.setItem( "kit-lock", "false" );
39 if( System.bootopt.get("safe") ) $( "#kit-wallpaper" ).css( "background","#404040" );
40 else if( localStorage.getItem( "kit-wallpaper" ) ) $( "#kit-wallpaper" ).css( "background", localStorage.getItem( "kit-wallpaper" ) ).css( "background-size", "cover" ).css( "background-position", "center" );
42 if( !localStorage.getItem( "kit-default-browser" ) ) localStorage.setItem( "kit-default-browser", "browser" );
44 if( localStorage.getItem("kit-fusen") ){
45 this.list = JSON.parse(localStorage.getItem("kit-fusen"));
46 for( let i in this.list ){
47 KWS.fusen.add(this.list[i]);
51 if( localStorage.getItem("kit-darkmode") == "true" ){
53 $("#kit-darkmode").attr("href", "system/theme/kit-darkmode.css");
54 $(".winc-darkmode").addClass("kit-darkmode");
57 if( System.bootopt.get("safe") ){
58 $("#kit-theme-file").attr("href", "./system/theme/theme-light.css" );
61 if( !localStorage.getItem( "kit-theme" ) ) localStorage.setItem( "kit-theme", "theme-default.css" );
62 $("#kit-theme-file").attr("href", "./system/theme/" + localStorage.getItem("kit-theme") );
65 if( !localStorage.getItem( "kit-appdir" ) ) localStorage.setItem( "kit-appdir", "./app/" );
66 S.appdir = localStorage.getItem( "kit-appdir" );
68 if( localStorage.getItem('kit-installed') ) System.installed = JSON.parse( localStorage.getItem('kit-installed') );
70 if( localStorage.getItem('kit-screentime') ) KWS.screenTime = JSON.parse( localStorage.getItem('kit-screentime') );
72 if( localStorage["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
73 if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
75 System.moveDesktop( "1" );
78 if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
79 else clockmove = setInterval( System.clock, 10 );
81 if ( localStorage.getItem("kit-shutted-down") == "false" ) {
82 Notification.push("お知らせ", "kitは前回終了時、正しくシャットダウンされませんでした。", "system");
84 localStorage.setItem("kit-shutted-down", false);
86 Notification.push("kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system", null, null, 'documents/icon.png', [
89 func: () => System.launch( 'settings', {'view': 'about'} )
93 if( localStorage.getItem( "kit-startup" ) == undefined ) {
94 localStorage.setItem( "kit-startup", new Array( "welcome" ) );
96 System.startup = localStorage.getItem( "kit-startup" ).split( "," );
97 if( System.bootopt.get("safe") ){
98 Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
99 System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
101 else for( let i of System.startup ) if( i != "" ) System.launch(i);
103 $("#kit-header-fullscreen").hide();
106 $( "#desktops" ).click( function() {
107 $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
108 } ).mousedown( function() {
109 $( ".window" ).css( "opacity", "0.6" );
110 } ).mouseup( function() {
111 $( ".window" ).css( "opacity", "1.0" );
114 $( "#footer-tasks" ).click( function() {
115 if( $( "#kit-tasks" ).is( ":visible" ) ) {
116 $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
119 $( "#task-ctx" ).fadeOut( 200 );
120 $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
123 $.getJSON("system/testload.json").fail( () => {
124 $('#body').append(`<div id='wcors' class="window windowactive" style="top: 70px; left: 50px; width: calc(100% - 100px)">
125 <div class="wt">問題が発生しました</div>
126 <div class="winc">JSONデータ読み込みに失敗しました。<br>
127 クロスオリジン制約によりkitアプリケーションの動作が制限されている場合があります。<br>
128 詳細は<a class="kit-hyperlink" onclick="location.href = 'https://mtsgi.github.io/kitdocs/#/cors'">こちらの記事</a>をご確認ください。</div>
130 $('<kit-button-alt class="kit-block kit-text-c m">閉じる</kit-button-alt>').appendTo('#wcors .winc').on('click', ()=>{
131 $('#wcors').remove();
135 $.getJSON("config/desktop.json", (data) => {
136 for( let i in data ){
137 $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
139 $(".desktop-icon").on("click", function(){
140 System.launch( $(this).attr("data-launch") );
142 }).fail( function() {
143 Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
146 $.getJSON("config/apps.json", System.initLauncher).fail( function() {
147 Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
149 $( "#kit-tasks" ).delegate( ".task", "click", function() {
150 System.close( this.id.slice( 1 ) );
154 $( "#footer-noti" ).click( function() {
155 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
156 if( $( "#notifications" ).is( ":visible" ) ) {
157 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
160 $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
163 $( "#last-notification-close" ).click( function() {
164 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
166 $("#notifications-dnp").prop("checked", false).on("change", ()=>{
167 if( $("#notifications-dnp").is(":checked") ){
168 Notification.goodnight = true;
170 else Notification.goodnight = false;
173 $( ".power-button" ).click( function() {
174 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
175 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
176 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" );
177 $( "footer, header, #launcher, #task-ctx, #kit-sightre, .dropdown, #desktop-" + currentDesktop ).hide();
178 $( "#kit-power" ).show();
180 $( "#kit-power-back" ).click( function() {
181 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
182 $( "footer, header, #desktop-" + currentDesktop ).show();
183 $( "#kit-power" ).hide();
185 $( "#kit-power-shutdown" ).click( function() {
188 $( "#kit-power-reboot" ).click( function() {
191 $( "#kit-power-suspend" ).click( function() {
193 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
194 $( "#kit-power" ).fadeOut( 300 );
195 System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
197 $( "#kit-power-lock" ).click( function() {
200 $( "#lock-password" ).on( 'keypress', function( e ) {
201 if( e.which == 13 ) $( "#lock-unl" ).click();
203 $( "#lock-unl" ).on( 'click', function() {
204 if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
205 $( "header, footer" ).show();
206 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
207 $( "#lock-password" ).val( "" );
208 System.moveDesktop(1);
210 else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
211 } ).hover( function() {
212 $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
214 $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
217 $( "#launch" ).click( function() {
218 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
219 if( $( "#launcher" ).is( ":visible" ) ) {
220 $( "#kit-wallpaper" ).css( "filter", "none" );
221 $( "#desktop-" + currentDesktop ).show();
222 $( "#launcher" ).hide();
225 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
226 $( "section, #task-ctx" ).hide();
227 $( "#launcher" ).show();
232 $('#kit-header-sightre').on('click', () => {
233 if($('#kit-sightre').is( ":visible" )) {
234 $('#kit-sightre').fadeOut(300);
237 $('#kit-sightre-results').html('');
238 $('#kit-sightre').show();
239 $('#kit-sightre-form').val('').focus();
242 let sightrePrevWord = '';
243 $('#kit-sightre-form').on('keypress', (e) => {
244 let _word = $('#kit-sightre-form').val();
245 if( e.which == 13 && _word ) {
246 if( _word == "kit" ){
247 S.alert("", "<div style='text-align:left;'> _ _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>| 〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
250 $('.kit-sightre-result.-first').click();
251 sightrePrevWord = '';
252 $('#kit-sightre-form').val('');
253 $('#kit-sightre-results').html('');
254 $('#kit-sightre').fadeOut(300);
256 }).on('keydown keyup change', (e) => {
257 let _word = $('#kit-sightre-form').val();
258 if( e.which == 27 ) $('#kit-sightre').fadeOut(300);
260 if( _word == sightrePrevWord ) return;
261 $('#kit-sightre-results').html('');
263 sightrePrevWord = _word;
264 if( _word.indexOf('kish ') == 0 || _word.indexOf('🥧 ') == 0 ){
265 let _cmd = _word.substring( _word.indexOf(" ") + 1 );
267 $(`<div class='kit-sightre-result -first'>
268 <img class='--icon' src='app/kish/icon.png'/>
270 <div class='--name'>${_cmd}</div>
271 <div class='--desc'>kishでコマンドを実行</div>
273 <div class='--open fa fa-arrow-right'></div>
274 </div>`).appendTo('#kit-sightre-results').on('click', () => {
275 System.launch('kish', { 'rc': [ _cmd ] });
279 else if( _word.indexOf('http://') == 0 || _word.indexOf('https://') == 0 || _word.indexOf('localhost') == 0 ){
280 $(`<div class='kit-sightre-result -first'>
281 <img class='--icon' src='app/browser/icon.png'/>
283 <div class='--name'>${_word}</div>
284 <div class='--desc'>ブラウザでURLを開く</div>
286 <div class='--open fa fa-arrow-right'></div>
287 </div>`).appendTo('#kit-sightre-results').on('click', () => {
288 System.launch( localStorage.getItem('kit-default-browser'), { "url" : _word } );
292 $(`<div class='kit-sightre-result -first'>
293 <img class='--icon' src='system/icons/q.png'/>
295 <div class='--name'>${_word}</div>
296 <div class='--desc'>アプリを起動する</div>
298 <div class='--open fa fa-arrow-right'></div>
299 </div>`).appendTo('#kit-sightre-results').on('click', () => {
302 if( _word.split(",")[1] ) _args = JSON.parse( _word.split(",").slice(1).join().trim() );
305 Notification.push("引数の解釈に失敗", error, "system");
307 System.launch( _word.split(",")[0], _args );
310 for( let i in System.apps ){
311 if( i.indexOf(_word) == 0 || S.apps[i].name.indexOf(_word) == 0 ){
312 $(`<div class='kit-sightre-result -app'>
313 <img class='--icon' src='${S.apps[i].icon}'/>
315 <div class='--name'>${S.apps[i].name}</div>
316 <div class='--desc'>kitアプリケーション - ${i}</div>
318 <div class='--open fa fa-arrow-right'></div>
319 </div>`).appendTo('#kit-sightre-results').on('click', () => {
321 $('#kit-sightre-results').html('');
322 $('#kit-sightre').fadeOut(300);
326 for( let i in System.userarea ){
327 if( i.indexOf(_word) == 0 || i.indexOf(_word) == 0 ){
328 $(`<div class='kit-sightre-result -file'>
329 <i class="fa fa-file --icon"></i>
331 <div class='--name'>${i}</div>
332 <div class='--desc'>ファイル - 種類:${S.userarea[i].type} - ユーザー:${System.username}</div>
334 <div class='--open fa fa-arrow-right'></div>
335 </div>`).appendTo('#kit-sightre-results').on('click', () => {
337 $('#kit-sightre-results').html('');
338 $('#kit-sightre').fadeOut(300);
342 $(`<div class='kit-sightre-result -link'>
343 <i class="fa fa-search --icon"></i>
345 <div class='--name'>${_word}</div>
346 <div class='--desc'>をWebで検索</div>
348 <div class='--open fa fa-arrow-right'></div>
349 </div>`).appendTo('#kit-sightre-results').on('click', () => {
350 System.launch( 'browser', { 'url' : 'https://www.bing.com/search?q=' + _word } );
351 $('#kit-sightre-results').html('');
352 $('#kit-sightre').fadeOut(300);
354 $(`<div class='kit-sightre-result -link'>
355 <i class="fab fa-wikipedia-w --icon"></i>
357 <div class='--name'>${_word}</div>
358 <div class='--desc'>wikipediaの記事を表示</div>
360 <div class='--open fa fa-arrow-right'></div>
361 </div>`).appendTo('#kit-sightre-results').on('click', () => {
362 System.launch( 'browser', { 'url' : 'https://ja.wikipedia.org/wiki/' + _word } );
363 $('#kit-sightre-results').html('');
364 $('#kit-sightre').fadeOut(300);
369 $("#dropdown-sound-slider").slider({
370 min: 0, max: 100, step: 1, value: 100,
372 System.audio.level = ui.value;
373 $("#dropdown-sound-level").text(ui.value);
374 localStorage.setItem("kit-audio-level", ui.value);
375 for( let i in System.audio.list ){
376 System.audio.list[i].volume = System.audio.level / 100;
378 if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
379 else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
382 if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
384 $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
385 if( $("#dropdown-sound-silent").is(":checked") ){
386 System.audio.silent = true;
387 $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
390 System.audio.silent = false;
391 $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
395 $('#kit-header-user').on('click', () => System.launch('user') );
397 $(":root section:not(#desktop-l)").on("contextmenu", function() {
398 let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
399 S.selectedElement = _ptelem;
400 S.selectedText = window.getSelection();
401 $( "#kit-context-input" ).val( S.selectedText );
402 if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
403 else $("#kit-contextgroup-text").show();
404 if( _ptelem[0].id == "desktop-" + currentDesktop ){
405 $("#kit-contextgroup-desktop").show();
406 $("#kit-contextgroup-elem").hide();
409 $("#kit-contextgroup-desktop").hide();
410 $("#kit-contextgroup-elem").show();
412 $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
413 $("#kit-contextgroup-custom").hide();
415 let _ctxid = _ptelem.attr("data-kit-contextid") || _ptelem.attr("kit-context");
417 $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
418 let _ctxname = KWS.context[_ctxid].name || _ctxid;
419 $("#kit-context-custom").text( _ctxname );
420 for( let i in KWS.context[_ctxid]){
421 if( i == "name" ) continue;
422 $("#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>");
423 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
424 KWS.context[_ctxid][i].function();
425 $("#kit-context").fadeOut(300);
429 if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
430 $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
431 $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
434 $("#kit-context-open").on("click", function(){
435 S.alert("要素", S.selectedElement.clone());
437 $("#kit-context-save").on("click", function(){
438 S.obj2img( S.selectedElement , true );
440 $( "#kit-context-search" ).on("click", function(){
441 $("#kit-context").fadeOut(300);
442 System.launch( 'browser', {'url': `https://www.bing.com/search?q=${$('#kit-context-input').val()}`} );
444 $( "#kit-context-input" ).keypress( function( e ) {
445 if( e.which == 13 ) $( "#kit-context-search" ).click();
447 $("#kit-context a").on("click", function(){
448 $("#kit-context").fadeOut(300);
450 $("#kit-context-vacuum").on("click", function(){
451 for( let i in process ){
452 KWS.vacuum( S.mouseX, S.mouseY );
455 $(".window").css("transition", "none");
458 $("#kit-context-fusen").on("click", function(){
463 $("section").on("click", function(){
464 $("#kit-context").fadeOut(300);
467 $( document ).delegate('a', 'click', function() {
469 System.launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
472 } ).on("mousemove", function(e){
473 System.mouseX = e.clientX;
474 System.mouseY = e.clientY;
475 }).delegate('.textbox', 'keypress', function(e) {
476 if( e.which == 13 && this.id ){
477 if( $("#" + this.id + " + .kit-button").length ){
478 Notification.push("debug", this.id, "system");
479 $("#" + this.id + " + .kit-button").click();
481 else if( $("#" + this.id + " + kit-button").length ){
482 Notification.push("debug", this.id, "system");
483 $("#" + this.id + " + kit-button").click();
488 window.onresize = () => {
489 System.display.width = window.innerWidth;
490 System.display.height = window.innerWidth;
492 if( KWS.fullscreen.pid ){
493 KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
497 if( localStorage.getItem( "kit-lock" ) == "true" ){
499 setTimeout(() => System.lock(), 100);
503 async function launch( str, args, dir ) {
504 while(System.launchLock) await System.ajaxWait();
505 System.launchLock = true;
508 System.args[_pid] = args;
509 let _path = dir || System.appdir + str;
510 System.launchpath[_pid] = _path;
512 if( System.appCache[_path] ) {
513 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
514 appData( System.appCache[_path] );
518 $.getJSON( S.launchpath[_pid] + '/define.json', appData ).fail( () => {
519 Notification.push('kitアプリをロードできません。', `${str}を展開できませんでした。`, 'system');
520 System.launchLock = false;
525 Notification.push( "System Error", error, "system" );
526 System.launchLock = false;
531 async function appData(data) {
538 }, _size = {}, _resize = false;
539 if (data.support) _support = {
540 fullscreen: typeof data.support.fullscreen == "undefined" ? false : data.support.fullscreen,
541 resize: typeof data.support.resize == "undefined" ? false : data.support.resize,
542 darkmode: typeof data.support.darkmode == "undefined" ? false : data.support.darkmode,
543 kaf: typeof data.support.kaf == "undefined" ? true : data.support.kaf,
544 multiple: typeof data.support.multiple == "undefined" ? true : data.support.multiple
546 if (data.size) _size = {
547 width: data.size.width || 'auto',
548 height: data.size.height || 'auto'
550 if (data.resize) _resize = data.resize;
553 name: data.name || 'アプリ名なし',
554 icon: data.icon || 'none',
555 version: data.version || null,
556 author: data.author || null,
560 view: data.view || 'default.html',
561 script: data.script || 'none',
562 css: data.css || 'none'
564 if (!data.id || !data.version || !data.author) {
565 Notification.push('起動エラー', '起動に失敗しました。詳細情報を得るためには、デバッグモードを有効化してください。', 'system');
566 Notification.push('debug', '起動エラー:id, version, authorは必須定義項目です。', 'system');
567 System.launchLock = false;
570 if (defobj.support.multiple == false) {
571 if (Object.values(process).map(p => p.id).includes(defobj.id)) {
572 Notification.push('多重起動エラー', `アプリケーション「${defobj.name}」の多重起動は許可されていません。`, 'system');
573 System.launchLock = false;
578 process[String(_pid)] = {
580 time: System.time.obj.toLocaleString(),
585 System.appCache[System.launchpath[pid]] = data;
587 let _taskAppend = `<span id='t${_pid}'>`;
588 const _iconPath = app.getPath(defobj.icon).toString();
589 const _viewPath = app.getPath(defobj.view).toString();
590 if(defobj.icon != 'none') _taskAppend += `<img src='${_iconPath}'>`;
591 _taskAppend += `<span id='tname${_pid}'>${defobj.name}<span></span>`;
592 $("#tasks").append(_taskAppend);
593 $("#t" + _pid).addClass("task").on({
595 if ( process[_pid].isactive || $(this).hasClass("task-min") ) KWS.min(_pid);
597 $("#w"+_pid).css("z-index", KWS.windowIndex + 1);
598 KWS.refreshWindowIndex();
601 mouseenter: function() {
602 $("#task-ctx-name").text(defobj.name);
603 if(defobj.icon != "none") $("#task-ctx-img").show().attr("src", _iconPath);
604 else $("#task-ctx-img").hide();
605 $("#task-ctx-ver").text(`v${defobj.version} pid${_pid}`);
606 $("#task-ctx-info").off().on("click", function() { System.appInfo(_pid)});
607 $("#task-ctx-sshot").off().on("click", function() { System.screenshot(_pid, true) });
608 $("#task-ctx-min").off().on("click", function() { KWS.min(String(_pid)) });
609 if($(this).hasClass('t-active')) $('#task-ctx-front').hide();
610 else $('#task-ctx-front').show();
611 $("#task-ctx-front").off().on('click', function() {
612 $("#w"+_pid).css("z-index", KWS.windowIndex+1);
613 KWS.refreshWindowIndex();
615 $("#task-ctx-close").off().on("click", () => System.close(_pid));
616 $("#task-ctx-kill").off().on("click", () => System.kill(defobj.id));
617 const _ctxleft = $(this).offset().left, _ctxtop = window.innerHeight - $(this).offset().top;
618 if( _ctxleft != $("#task-ctx").offset().left ) $("#task-ctx").hide();
619 $("#task-ctx").css("left", _ctxleft).css("bottom", _ctxtop).show();
622 $("section, #kit-tasks").on('mouseenter', function() { $('#task-ctx').fadeOut(200) });
625 prevWindowIndex = $("#w" + _pid).css('z-index');
626 $("#w" + _pid).addClass('win-highlight');
628 mouseleave: () => $("#w" + _pid).removeClass('win-highlight')
630 let _windowAppend = "<div id='w" + _pid + "'><div id='wt" + _pid + "' class='wt'><i class='wmzx'><span id='wm" + _pid + "'></span>";
631 if( defobj.support.fullscreen == true ) _windowAppend += "<span id='wz" + _pid + "'></span>";
632 _windowAppend += "<span id='wx" + _pid + "'></span></i>";
633 if( defobj.icon != "none" ) _windowAppend += "<img src='" + _iconPath + "'>";
634 _windowAppend += "<span id='wtname" + _pid + "'>" + defobj.name + "</span></div><div class='winc winc-" + defobj.id + "' id='winc" + _pid + "'></div></div>";
635 $("#desktop-" + currentDesktop).append(_windowAppend);
637 if( defobj.support.darkmode == true ) $("#winc"+_pid).addClass('winc-darkmode');
638 if( KWS.darkmode ) $("#winc"+_pid).addClass("kit-darkmode");
640 $("#winc"+_pid).css("width", defobj.size.width).css("height", defobj.size.height);
642 let _minwidth = defobj.resize.minWidth ? defobj.resize.minWidth : 200;
643 let _minheight = defobj.resize.minHeight ? defobj.resize.minHeight : 40;
644 $("#winc"+_pid).windowResizable({
646 minHeight: _minheight
650 let windowPos = 50 + ( _pid % 10 ) * 20;
652 $( "#w"+_pid ).addClass( "window" ).pep({
653 elementsWithInteraction: ".winc, .ui-resizable-handle",
654 useCSSTranslation: false,
655 disableSelect: false,
657 initiate: function(){
658 $(this.el).addClass("ui-draggable-dragging");
660 this.el.style.zIndex = KWS.windowIndex;
661 KWS.refreshWindowIndex();
664 this.el.style.transition = "none";
665 $(this.el).removeClass("ui-draggable-dragging");
667 }).on( "mousedown", function(){
668 $(".window").css( "transition", "none" );
669 $(this).css("z-index", KWS.windowIndex + 1);
670 KWS.refreshWindowIndex();
671 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
672 KWS.refreshWindowIndex();
673 if(defobj.support.fullscreen == true) $(`#wt${_pid}`).on("dblclick", () => KWS.max(_pid));
674 $( `#wm${_pid}` ).addClass("wm fa fa-window-minimize").on("click", () => KWS.min( _pid ));
675 $( `#wz${_pid}` ).addClass("wz fas fa-square").on("click", () => KWS.max( _pid ));
676 $( `#wx${_pid}` ).addClass("wx fa fa-times").on("click", () => System.close( _pid ));
677 $( "#winc" + _pid ).resizable().load(app.getPath(defobj.view), (r, s, x) => {
679 Notification.push("起動に失敗しました " + x.status, 'テンプレートにアクセスできません。' + x.statusText, 'system');
680 System.launchLock = false;
684 if( defobj.css != "none" && !document.querySelector(`#kit-style-${defobj.id}`) ){
685 $("head").append('<link href="' + app.getPath(defobj.css) + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>');
687 if(defobj.script != "none") $.getScript(app.getPath(defobj.script), () => {
688 if( defobj.support.kaf == true ) App.kaf(_pid);
691 if( defobj.support.kaf == true ) App.kaf(_pid)
694 else if( defobj.support.kaf == true ){
699 localStorage.setItem( "kit-pid", pid );
700 System.launchLock = false;
704 const System = new function() {
705 this.version = "0.2.1";
706 this.username = localStorage.getItem("kit-username");
707 this.appdir = localStorage.getItem("kit-appdir");
708 this.loc = { ...location };
710 this.bootopt = new URLSearchParams(location.search);
716 "width": window.innerWidth,
717 "height": window.innerHeight
720 this.selectedElement = null;
721 this.selectedText = null;
723 this.dom = function(_pid, ..._elems) {
725 if( !_elems.length ) q = ",#winc" + _pid;
726 else for( let i of _elems ){
727 q += ",#winc" + _pid + " " + i;
729 return $( q.substring(1) );
732 this.qs = ( _pid, ..._elems ) => {
734 if( !_elems.length ) q = ",#winc" + _pid;
735 else for( let i of _elems ) q += ",#winc" + _pid + " " + i;
736 return document.querySelectorAll( q.substring(1) )
739 this.userarea = new Object();
740 this.recycle = new Object();
746 this.launchpath = {};
748 this.support = $.support;
749 this.debugmode = false;
753 this.log = new Array();
756 this.launchLock = false;
758 this.ajaxWait = () =>{
759 return new Promise(resolve =>{
760 let interval = setInterval(()=>{
761 if(this.launchLock === false) {
762 clearInterval(interval);
769 this.setBattery = function(){
770 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
771 let _lv = e.level * 100;
772 System.battery = _lv;
777 this.screenshot = function( _pid, _popup ){
778 let _elem = document.querySelector("body");
779 if( _pid ) _elem = document.querySelector("#w"+_pid);
780 html2canvas( _elem ).then(canvas => {
782 canvas.style.border = "1px solid #909090";
783 S.save( canvas.toDataURL("image/png"), "image" );
789 this.obj2img = function( _obj, _popup ){
791 html2canvas( _elem ).then(canvas => {
793 canvas.style.border = "1px solid #909090";
794 S.save( canvas.toDataURL("image/png"), "image" );
800 this.save = function(data, type){
801 System.launch("fivr", { "save" : data, "type" : type });
804 this.open = function(filename){
805 System.launch("fivr", { "open" : filename });
808 this.preventClose = function( _pid ){
809 if( !process[_pid] ) return false;
810 process[_pid].preventclose = true;
814 this.shutdown = function(_opt) {
815 $( "#last-notification-close" ).click();
816 $( "#kit-power-back" ).click();
817 for( let i in process ) {
818 if( process[i].preventclose == true ){
819 S.dialog( "シャットダウンの中断", "pid" + System.appCache[System.launchpath[i]].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
820 process[i].preventclose = false;
825 else System.close( i );
827 $( "section" ).hide();
828 $( "body" ).css( "background-color", "black" );
829 $( "header, footer" ).fadeOut( 300 );
830 $( "#kit-wallpaper" ).fadeOut( 1500 );
831 if( _opt == "reboot" ) location.href = "autorun.html";
832 localStorage.setItem("kit-shutted-down", true);
835 this.reboot = function() {
836 System.shutdown("reboot");
839 this.lock = function(){
840 System.moveDesktop( "l" );
842 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
843 $( "section, header, footer" ).css( "filter", "none" );
844 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
845 $( "header, footer, #kit-power" ).hide();
847 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
848 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
849 else $( "#lock-password" ).hide();
852 this.alert = function( title, content, wtitle ) {
853 System.launch("alert", [title, content, wtitle]);
856 this.dialog = function( title, content, func ){
857 System.launch("dialog", {
864 this.appInfo = function( _pid ){
865 let _title = "", _content = "";
866 let ac = System.appCache[S.launchpath[_pid]];
867 let _lp = System.launchpath[_pid];
869 _title = ac.name + " " + ac.version;
870 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
872 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
874 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
876 else _title = "取得に失敗しました";
877 System.alert( _title, _content );
880 this.apps = new Object();
881 this.installed = new Array();
883 this.close = function( _str ) {
884 let _pid = String( _str );
885 $( "#w" + _pid ).remove();
886 $( "#t" + _pid ).remove();
887 $( "#task-ctx" ).hide();
888 delete process[_pid];
889 KWS.refreshWindowIndex();
892 this.kill = function( _str ){
893 for( let _pid in process ) {
894 if( process[_pid] && process[_pid].id == _str ) System.close( _pid );
898 this.vacuum = function( _left, _top ){
899 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
913 this.clock = function() {
916 let Year = DD.getFullYear();
917 S.time.day = DD.getDay();
919 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
921 let DateN = ( "00" + DD.getDate() ).slice( -2 );
923 let Hour = ( "00" + DD.getHours() ).slice( -2 );
925 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
927 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
929 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
930 let MS = DD.getMilliseconds();
933 outer: { radius: .9, color: "transparent" },
934 inner: { radius: .85, color: "transparent" }
937 long: { from: .8, to: .7, width: 2, color: "#303030" },
938 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
941 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
942 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
943 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
945 let canvas = $(".dropdown-clock-canvas")[0];
946 canvas.width = "200", canvas.height = "200";
947 let context = canvas.getContext("2d");
948 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
949 let radius = Math.min(center.x, center.y), angle, len;
950 context.beginPath();context.fillStyle = circle.outer.color;
951 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
952 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
953 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
955 for( let i=0; i<60; i++ ){
956 angle = Math.PI * i / 30;
958 let line = ( i%5 == 0 ) ? lines.long : lines.short;
959 context.lineWidth = line.width, context.strokeStyle = line.color;
960 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
961 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
964 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
965 context.beginPath(), context.lineWidth = hands.hour.width;
966 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
967 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
968 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
969 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
970 context.beginPath(), context.lineWidth = hands.minute.width;
971 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
972 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
973 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
974 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
975 context.beginPath(), context.lineWidth = hands.second.width;
976 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
977 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
978 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
981 this.changeWallpaper = function( str ) {
982 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
983 localStorage.setItem( "kit-wallpaper", str )
986 this.moveDesktop = function( str ) {
988 $( "section" ).hide();
989 $( "#desktop-" + str ).show();
990 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
991 currentDesktop = str;
994 this.avoidMultiple = function( _pid, _alert ) {
995 let _id = process[_pid].id;
997 for( let i in process ) {
998 if( process[i].id == _id ) _cnt += 1;
1000 Notification.push( "debug", _cnt );
1002 System.close( _pid );
1004 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
1010 this.resizable = function( _pid, _elem, _width, _height ){
1012 if( _elem ) E = String( _elem );
1013 if( !_width ) _width = null;
1014 if( !_height ) _height = "100";
1015 $("#w" + _pid).resizable({
1016 alsoResize: "#w" + _pid + " " + E,
1022 this.initLauncher = function(data){
1023 $("#launcher-apps").html("");
1025 for( let i in data ){
1026 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i}'><img src='${data[i].icon}'>${data[i].name}</div>`);
1028 if( !System.bootopt.get('safe') ){
1029 for( let i of System.installed ){
1030 $('#launcher-apps').append(`<div class='launcher-app' data-launch='${i.path}' data-define-id='${i.id}'><img src='${i.icon}'>${i.name}</div>`);
1033 $('.launcher-app').on('click', function(){
1034 $('#launch').click();
1035 System.launch( $(this).attr('data-launch') );
1039 this.launch = async function(path, args) {
1040 while(this.launchLock) await this.ajaxWait();
1041 this.launchLock = true;
1044 System.args[_pid] = args;
1046 if(_path.lastIndexOf('/') == _path.length - 1) {
1047 _path = _path.substring(0, _path.length - 1);
1049 else if(_path.indexOf('/') == -1) {
1050 _path = System.appdir + _path;
1053 System.launchpath[_pid] = _path;
1055 if( System.appCache[_path] ) {
1056 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
1057 appData( System.appCache[_path] );
1061 $.getJSON( _path + '/define.json', appData ).fail( () => {
1062 Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
1063 System.launchLock = false;
1067 Notification.push( "System Error", error, "system" );
1068 System.launchLock = false;
1073 this.clip = new function(){
1074 this.content = null;
1075 this.history = new Array();
1077 this.set = function( content ){
1078 this.content = content;
1079 this.history.push(content);
1082 this.get = ()=>{ return this.content }
1085 this.config = new function(){
1086 this.apps = new Object();
1089 this.audio = new function(){
1090 this.level = localStorage["kit-audio-level"] || 100;
1091 this.silent = false;
1093 this.list = new Array();
1095 this.volume = function( _level ){
1096 $("#dropdown-sound-slider").slider("value", _level);
1099 this.play = function( _audioid, _src ){
1100 if( !System.audio.list[_audioid] ){
1101 System.audio.list[_audioid] = new Audio(_src);
1102 System.audio.list[_audioid].volume = System.audio.level / 100;
1104 System.audio.list[_audioid].play();
1107 this.get = function( _audioid ){
1108 return System.audio.list[_audioid];
1111 this.pause = function( _audioid ){
1112 System.audio.list[_audioid].pause();
1115 this.stop = function( _audioid ){
1116 System.audio.list[_audioid].pause();
1117 System.audio.list[_audioid] = null;
1120 this.seek = function( _audioid, _time ){
1121 System.audio.list[_audioid].fastSeek(_time);
1124 this.mute = function( _audioid, _bool ){
1125 System.audio.list[_audioid].muted = _bool;
1130 const KWS = new function(){
1131 this.version = "3.2.3";
1134 this.darkmode = false;
1136 this.changeWindowTitle = function( _pid, _str ){
1137 $("#tname"+_pid).text( _str );
1138 $("#wtname"+_pid).text( _str );
1141 this.min = function( _str ) {
1142 let _pid = String( _str );
1143 if( $( "#w" + _pid ).is( ":visible" ) ) {
1144 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
1145 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1146 $( "#t" + _pid ).addClass( "task-min" );
1149 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
1150 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
1151 $( "#t" + _pid ).removeClass( "task-min" );
1163 this.max = function( _pid ){
1164 let _appcache = System.appCache[System.launchpath[_pid]];
1165 if( KWS.fullscreen.pid || _appcache.support.fullscreen != true ){
1166 Notification.push('最大化に失敗', 'ウィンドウの最大化に失敗しました。', 'system');
1169 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
1170 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
1171 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
1172 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
1173 KWS.fullscreen.pid = _pid;
1174 $( "#wt"+_pid ).addClass("wtmaximize");
1175 $( "#w"+_pid ).css({
1179 .addClass("windowmaximize")
1180 .css("z-index", KWS.windowIndex + 1);
1181 KWS.refreshWindowIndex();
1182 KWS.resize( _pid, System.display.width, System.display.height - 30 );
1184 $("#kit-header-fullscreen").show().on('click', () => KWS.unmax( _pid ));
1187 this.unmax = function( _pid ){
1188 if( _pid != KWS.fullscreen.pid ){
1189 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
1192 $('#wt'+_pid).removeClass("wtmaximize");
1194 "top": KWS.fullscreen.prevTop,
1195 "left": KWS.fullscreen.prevLeft
1197 .removeClass("windowmaximize");
1199 $("#kit-header-fullscreen").hide().off();
1200 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
1201 KWS.fullscreen.pid = null;
1202 KWS.fullscreen.prevWidth = null;
1203 KWS.fullscreen.prevHeight = null;
1204 KWS.fullscreen.prevTop = null;
1205 KWS.fullscreen.prevLeft = null;
1207 if( !System.appCache[System.launchpath[_pid]].size.height ) {
1208 System.qs(_pid)[0].style.height = "auto";
1212 this.vacuum = function( _left, _top ){
1213 for( let i in process ){
1214 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
1217 $(".window").css("transition", "none");
1222 this.windowIndex = 1;
1224 this.refreshWindowIndex = function(){
1225 let num = $(".window").length;
1226 let array = new Array();
1227 let obj = new Object();
1228 for( let i = 0; i < num; i++ ){
1229 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
1232 array.sort( (a,b) => {
1233 return Number(a.zindex - b.zindex);
1235 for( let i in array ){
1236 document.getElementById(array[i].id).style.zIndex = i;
1237 let _pid = String(array[i].id).substring(1);
1239 $("#"+array[i].id).addClass("windowactive");
1240 $("#t"+_pid).addClass("t-active");
1242 process[_pid].isactive = true;
1243 KWS.screenPrevSwitched = new Date();
1244 localStorage.setItem('kit-screentime', JSON.stringify(KWS.screenTime));
1247 $("#"+array[i].id).removeClass("windowactive");
1248 $("#t"+_pid).removeClass("t-active");
1249 process[_pid].isactive = false;
1250 if( KWS.active == _pid ){
1251 let _diff = (new Date() - KWS.screenPrevSwitched);
1252 let _appid = process[_pid].id
1253 if( !KWS.screenTime[_appid] ) KWS.screenTime[_appid] = new Number();
1254 if( _diff < 0 ) Notification.push('debug', 'スクリーンタイムの記録に失敗しました。', 'system')
1255 else KWS.screenTime[_appid] += _diff;
1259 KWS.windowIndex = num;
1262 this.front = function( _pid ) {
1263 $(`#w${_pid}`).css("z-index", KWS.windowIndex + 1);
1264 KWS.refreshWindowIndex();
1267 this.resize = function( _pid, _width, _height ){
1268 if( _width ) $("#winc"+_pid).css("width", _width)
1269 if( _height ) $("#winc"+_pid).css("height", _height);
1272 this.setTheme = function(_name){
1273 localStorage.setItem('kit-theme', _name);
1274 if(_name != 'none') $('#kit-theme-file').attr('href', `./system/theme/${localStorage.getItem('kit-theme')}`);
1275 else $('#kit-theme-file').attr('href', '');
1276 System.moveDesktop(currentDesktop);
1279 this.screenTime = new Object();
1281 this.screenPrevSwitched = new Date();
1283 this.fusen = new function(){
1285 this.list = new Object();
1287 this.add = function(_text){
1288 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1289 $("#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>");
1290 $("#kit-f"+KWS.fusen.fid).css({
1291 "left": Number(KWS.fusen.fid)*40 + 20,
1292 "top": Number(KWS.fusen.fid)*10 + 100,
1294 elementsWithInteraction: ".kit-fusen-textarea",
1295 useCSSTranslation: false,
1296 disableSelect: false,
1298 initiate: function(){
1299 $(this.el).css("ui-opacity", "0.7");
1302 this.el.style.transition = "none";
1303 $(this.el).css("ui-opacity", "1.0");
1306 $(".kit-fusen-textarea").off().on("change",function(){
1307 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1308 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1310 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1314 this.remove = function(_fid){
1315 delete KWS.fusen.list[_fid];
1316 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1317 $("#kit-f"+_fid).remove();
1321 this.addCustomContext = function( _elem, _contextid, _obj ){
1322 KWS.context[_contextid] = _obj;
1330 "icon" : "fa-trash-alt",
1331 "function" : function(){
1332 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1338 "function" : function(){
1339 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1346 const Notification = new function() {
1348 this.list = new Object();
1350 this.goodnight = false;
1353 this.push = function( _title, _content, _app, _pid, _action, _img, _buttons ) {
1354 let _nid = this.nid;
1355 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1358 Notification.list[_nid] = {
1362 time: System.time.obj.toLocaleString(),
1365 if( typeof _action == 'function' ) _action();
1366 else if( _pid ) KWS.front(_pid);
1367 $('#notifications').hide('drop', {direction: 'right'}, 300);
1371 if( _pid && System.appCache[System.launchpath[_pid]] ){
1372 _app = `<img src='${System.launchpath[_pid]}/${System.appCache[System.launchpath[_pid]].icon}'>${System.appCache[System.launchpath[_pid]].name}`;
1374 if( !this.goodnight ){
1375 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1376 $('#last-notification-title').text('').text( _title );
1377 $('#last-notification-content').text('').text( _content );
1378 $('#last-notification-app').text('').html( _app );
1379 $('#last-notification').hide().show('drop', {direction: "right"}, 300).off().on('click', Notification.list[this.nid].action);
1380 if( _img ) $('#last-notification-img').attr('src', _img).show();
1381 else $('#last-notification-img').attr('src', '').hide();
1384 if( _img ) imgtag = `<img src='${_img }' alt='' class='notis_img'>`;
1385 $(`<div class='notis' id='nt${_nid}'>
1387 <span class='notis_close' id='nc${_nid}'></span>
1388 <div class='notis_app'>${_app}</div>
1389 <span>${_title}</span>
1391 <div class='notis_buttons'></div>
1392 <div class='notis_time'>${System.time.obj.toTimeString()}</div>
1393 </div>`).appendTo('#notifications').on('click', Notification.list[this.nid].action);
1394 $(`#nc${_nid}`).on('click', (e) => {
1395 e.stopPropagation();
1396 $(`#nt${_nid}`).fadeOut(300);
1398 $('#last-notification-buttons').html('');
1400 for( let b of _buttons ){
1401 $(`<a>${b.label}</a>`).appendTo('#last-notification-buttons').on('click', (e) => {
1402 e.stopPropagation();
1405 $(`<a>${b.label}</a>`).appendTo(`#nt${_nid} .notis_buttons`).on('click', (e) => {
1406 e.stopPropagation();
1412 return (this.nid - 1);
1418 App.e[_pid] = new Object();
1419 App.d[_pid] = new Object();
1421 this.process = process[_pid];
1422 this.cache = System.appCache[System.launchpath[_pid]];
1424 this.args = System.args[_pid];
1425 this.close = () => System.close(_pid);
1426 this.d = App.d[_pid];
1427 this.dom = (..._args) => System.dom(_pid, ..._args);
1428 this.e = App.e[_pid];
1429 this.ntf = (_title, _content, _action, _img, _buttons) => Notification.push(_title, _content, this.info.id, _pid, _action, _img, _buttons);
1430 this.qs = (...args) => System.qs(_pid, ...args);
1431 this.front = () => KWS.front(_pid);
1433 this.changeWindowTitle = _t => App.changeWindowTitle( _pid, _t );
1434 this.data = (...args) => App.data(_pid, ...args);
1435 this.event = (...args) => App.event(_pid, ...args);
1436 this.getPath = _path => App.getPath(_pid, _path);
1437 this.kaf = () => App.kaf(_pid);
1438 this.load = _path => App.load(_pid, _path);
1439 this.preventClose = _bool => App.preventClose(_pid, _bool);
1442 static changeWindowTitle( _pid, _t ) {
1443 $( "#tname"+_pid ).text( _t );
1444 $( "#wtname"+_pid ).text( _t );
1445 process[_pid].title = _t;
1449 static context( _cid, _obj ) {
1450 KWS.context[ _cid ] = _obj;
1454 static data( _pid, _name, _value ) {
1455 if ( _value !== undefined ) {
1456 S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
1457 S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
1458 S.dom(_pid, `template[kit\\:for=${_name}] + kit-for`).text('');
1459 if (typeof _value == 'object'){
1460 for(let elem of S.qs(_pid, `template[kit\\:for=${_name}] + kit-for`)){
1461 let _rep = App.d[_pid][`__kaf_node_id_${elem.getAttribute('kaf-node-id')}`], _result = '';
1462 for(let i in _value) {
1463 _result += _rep.replace(/{{\s*key\s*}}/g, i).replace(/{{\s*value\s*}}/g, _value[i]);
1465 elem.innerHTML = _result;
1469 S.dom(_pid, `[kit\\:if=${_name}]`).show();
1470 S.dom(_pid, `[kit\\:unless=${_name}]`).hide();
1471 S.dom(_pid, `[kit\\:disabled=${_name}]`).prop('disabled', true);
1474 S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1475 S.dom(_pid, `[kit\\:unless=${_name}]`).show();
1476 S.dom(_pid, `[kit\\:disabled=${_name}]`).prop('disabled', false).removeClass('-disabled');
1478 return App.d[_pid][_name] = _value;
1480 else if(typeof _name === 'object'){
1481 for (const key in _name) {
1482 if (_name.hasOwnProperty(key)) App.data(_pid, key, _name[key]);
1485 else if( _name ) return App.d[_pid][_name];
1486 else return Object.fromEntries( Object.entries(App.d[_pid] || {}).filter(d => d[0].indexOf("__") != 0) );
1489 static event( _pid, _name, _event ) {
1490 if (!App.e[_pid]) App.e[_pid] = new Object();
1491 if (_event !== undefined) App.e[_pid][_name] = _event;
1492 else if (typeof _name === 'object') {
1493 for (const key in _name) {
1494 if (_name.hasOwnProperty(key)) App.event(_pid, key, _name[key]);
1497 else if (App.e[_pid][_name]) App.e[_pid][_name].call();
1498 else if (_name === undefined && _pid) return App.e[_pid];
1502 static getPath( _pid, _path ) {
1503 if( String(_path)[0] != '/' ) _path = '/' + _path;
1504 return System.launchpath[_pid] + _path;
1507 static kaf( _pid ) {
1528 const DATA = App.data(_pid);
1529 const ARGS = System.args[_pid];
1530 let _kaf_node_id = 0;
1531 for( let i of S.qs(_pid, ...attrs) ){
1532 if( i.hasAttribute("kit-ref") ){
1533 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1535 if( i.hasAttribute("kit-e") ){
1536 let _eqs = i.getAttribute("kit-e").split(",");
1537 for( let k of _eqs ){
1538 let _eq = k.split(" ");
1539 $(i).on( _eq[1]||'click', (e) => {
1540 if(e.target.classList.contains('-disabled') === false) App.e[_pid][_eq[0]].call(this, e);
1544 if( i.hasAttribute("kit-src") ){
1545 $(i).attr("src", `${System.launchpath[_pid]}/${i.getAttribute("kit-src")}` );
1547 if( i.hasAttribute("kit-alert") ){
1548 $(i).on("click", ()=> System.alert( System.appCache[System.launchpath[_pid]].name, i.getAttribute("kit-alert") ) );
1550 if( i.hasAttribute("kit-launch") ){
1551 $(i).on("click", ()=> System.launch( i.getAttribute("kit-launch") ) );
1553 if( i.hasAttribute("kit-close") ){
1554 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1556 if( i.hasAttribute("kit-text") ){
1557 $(i).text( eval(i.getAttribute("kit-text")) );
1559 if( i.hasAttribute("kit-html") ){
1560 $(i).html( eval(i.getAttribute("kit-html")) );
1562 if( i.hasAttribute("kit:bind") ){
1563 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1564 $(i).on('keydown keyup keypress change', () => {
1565 let _name = i.getAttribute("kit:bind");
1566 App.d[_pid][_name] = i.value;
1567 S.dom(_pid, `[kit\\:observe=${_name}]`).text( i.value );
1569 S.dom(_pid, `[kit\\:if=${_name}]`).show();
1570 S.dom(_pid, `[kit\\:unless=${_name}]`).hide();
1571 S.dom(_pid, `[kit\\:disabled=${_name}]`).prop('disabled', true).addClass('-disabled');
1574 S.dom(_pid, `[kit\\:if=${_name}]`).hide();
1575 S.dom(_pid, `[kit\\:unless=${_name}]`).show();
1576 S.dom(_pid, `[kit\\:disabled=${_name}]`).prop('disabled', false).removeClass('-disabled');
1580 if( i.hasAttribute("kit:observe") ){
1581 $(i).text( App.d[_pid][i.getAttribute("kit:observe")] );
1583 if( i.hasAttribute("kit:value") ){
1584 $(i).val( App.d[_pid][i.getAttribute("kit:value")] );
1586 if( i.hasAttribute("kit-value") ){
1587 $(i).val( eval(i.getAttribute("kit-value")) );
1589 if( i.hasAttribute("kit-color") ){
1590 $(i).css('color', i.getAttribute("kit-color"));
1592 if( i.hasAttribute("kit:if") ){
1593 if( App.d[_pid][i.getAttribute("kit:if")] ){
1598 if( i.hasAttribute("kit:unless") ){
1599 if( App.d[_pid][i.getAttribute("kit:unless")] ){
1604 if( i.hasAttribute("kit:disabled") ){
1605 if( App.d[_pid][i.getAttribute("kit:if")] ){
1607 i.classList.add('-disabled');
1609 else i.disabled = false;
1611 if( i.hasAttribute("kit-if") ){
1612 if( eval( i.getAttribute("kit-if")) ){
1617 if( i.hasAttribute("kit:for") ){
1618 if ('content' in document.createElement('template')) {
1619 i.setAttribute('kaf-node-id', _kaf_node_id);
1620 App.d[_pid][`__kaf_node_id_${_kaf_node_id}`] = i.innerHTML;
1621 i.insertAdjacentHTML('afterend', `<kit-for kaf-node-id="${_kaf_node_id}"></kit-for>`);
1623 else i.style.display = 'none';
1629 static load( _pid, _path ) {
1630 if( String(_path)[0] != '/' ) _path = '/' + _path;
1631 _path = System.launchpath[_pid] + _path;
1632 S.dom(_pid).load( _path, () => {
1634 let _appcache = System.appCache[System.launchpath[_pid]];
1635 if( !KWS.fullscreen.pid && !_appcache.size.height ) {
1636 System.qs(_pid)[0].style.height = "auto";
1642 static preventClose( _pid, _bool = true ) {
1643 process[_pid].preventclose = _bool || true;
1648 App.d = new Object();
1649 App.e = new Object();
1650 App.version = "2.1.1";
1652 var process = {}, pid = 0, app, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;