9 // THIS IS THE KIT KERNEL 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" ) ) processID = 0;
20 else processID = localStorage.getItem( "kit-pid" );
22 if( !localStorage.getItem( "kit-username" ) ) localStorage.setItem( "kit-username", "ユーザー" );
23 $( "#kit-header-username" ).text( localStorage.getItem( "kit-username" ) );
25 if( localStorage.getItem( "kit-lock" ) == null ) localStorage.setItem( "kit-lock", "false" );
27 if( System.bootopt.get("safe") ) $( "#kit-wallpaper" ).css( "background","#404040" );
28 else if( localStorage.getItem( "kit-wallpaper" ) ) $( "#kit-wallpaper" ).css( "background", localStorage.getItem( "kit-wallpaper" ) ).css( "background-size", "cover" ).css( "background-position", "center" );
30 if( !localStorage.getItem( "kit-default-browser" ) ) localStorage.setItem( "kit-default-browser", "browser" );
32 if( localStorage.getItem("kit-fusen") ){
33 this.list = JSON.parse(localStorage.getItem("kit-fusen"));
34 for( let i in this.list ){
35 KWS.fusen.add(this.list[i]);
39 if( localStorage.getItem("kit-darkmode") == "true" ){
41 $("#kit-darkmode").attr("href", "system/theme/kit-darkmode.css");
42 $(".winc-darkmode").addClass("kit-darkmode");
45 if( System.bootopt.get("safe") ){
46 $("#kit-theme-file").attr("href", "./system/theme/theme-light.css" );
49 if( !localStorage.getItem( "kit-theme" ) ) localStorage.setItem( "kit-theme", "theme-default.css" );
50 $("#kit-theme-file").attr("href", "./system/theme/" + localStorage.getItem("kit-theme") );
53 if( !localStorage.getItem( "kit-appdir" ) ) localStorage.setItem( "kit-appdir", "./app/" );
54 S.appdir = localStorage.getItem( "kit-appdir" );
56 if( localStorage.getItem( "kit-installed" ) ) System.installed = JSON.parse( localStorage.getItem( "kit-installed" ) );
58 if( localStorage["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
59 if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
61 System.moveDesktop( "1" );
64 if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
65 else clockmove = setInterval( System.clock, 10 );
67 Notification.push( "kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system" );
69 if( localStorage.getItem( "kit-startup" ) == undefined ) {
70 localStorage.setItem( "kit-startup", new Array( "welcome" ) );
72 System.startup = localStorage.getItem( "kit-startup" ).split( "," );
73 if( System.bootopt.get("safe") ){
74 Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
75 System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='System.reboot()'>通常モードで再起動</a>", "system" );
77 else for( let i of System.startup ) if( i != "" ) launch( i );
79 $("#kit-header-fullscreen").hide();
82 $( "#desktops" ).click( function() {
83 $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
84 } ).mousedown( function() {
85 $( ".window" ).css( "opacity", "0.6" );
86 } ).mouseup( function() {
87 $( ".window" ).css( "opacity", "1.0" );
90 $( "#footer-tasks" ).click( function() {
91 if( $( "#kit-tasks" ).is( ":visible" ) ) {
92 $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
95 $( "#task-ctx" ).fadeOut( 200 );
96 $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
100 $.getJSON("config/desktop.json", (data) => {
101 for( let i in data ){
102 $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
104 $(".desktop-icon").on("click", function(){
105 launch( $(this).attr("data-launch") );
107 }).fail( function() {
108 Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", "system" );
111 $.getJSON("config/apps.json", System.initLauncher).fail( function() {
112 Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", "system" );
114 $( "#kit-tasks" ).delegate( ".task", "click", function() {
115 System.close( this.id.slice( 1 ) );
119 $( "#footer-noti" ).click( function() {
120 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
121 if( $( "#notifications" ).is( ":visible" ) ) {
122 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
125 $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
128 $( "#last-notification-close" ).click( function() {
129 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
131 $("#notifications-dnp").prop("checked", false).on("change", ()=>{
132 if( $("#notifications-dnp").is(":checked") ){
133 Notification.goodnight = true;
135 else Notification.goodnight = false;
138 $( ".power-button" ).click( function() {
139 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
140 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
141 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" );
142 $( "footer, header, #launcher, #task-ctx, .dropdown, #desktop-" + currentDesktop ).hide();
143 $( "#kit-power" ).show();
145 $( "#kit-power-back" ).click( function() {
146 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
147 $( "footer, header, #desktop-" + currentDesktop ).show();
148 $( "#kit-power" ).hide();
150 $( "#kit-power-shutdown" ).click( function() {
153 $( "#kit-power-reboot" ).click( function() {
156 $( "#kit-power-suspend" ).click( function() {
157 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
158 $( "#kit-power" ).fadeOut( 300 );
159 System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
161 $( "#kit-power-lock" ).click( function() {
164 $( "#lock-password" ).keypress( function( e ) {
165 if( e.which == 13 ) $( "#lock-unl" ).click();
167 $( "#lock-unl" ).click( function() {
168 if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
169 $( "header, footer" ).show();
170 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
171 $( "#lock-password" ).val( "" );
172 System.moveDesktop(1);
174 else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
175 } ).hover( function() {
176 $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
178 $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
181 $( "#launch" ).click( function() {
182 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
183 if( $( "#launcher" ).is( ":visible" ) ) {
184 $( "#kit-wallpaper" ).css( "filter", "none" );
185 $( "#desktop-" + currentDesktop ).show();
186 $( "#launcher" ).hide();
189 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
190 $( "section, #task-ctx" ).hide();
191 $( "#launcher" ).show();
196 $( "#milp" ).val( "" ).on( "focus", function() {
197 $( "#kit-milp" ).show();
198 } ).on( "blur", function() {
199 $( "#kit-milp" ).fadeOut( 200 );
200 } ).on( 'keydown keyup keypress change', function() {
201 $( "#kit-milp-text" ).text( $( this ).val() );
202 } ).keypress( function( e ) {
203 if( e.which == 13 ) $( "#kit-milp-launch" ).click();
205 $( "#kit-milp-launch" ).click( function() {
206 if( $("#milp").val() == "kit" ){
207 System.alert("", "<div style='text-align:left;'> _ _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>| 〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
210 let _app = $( "#milp" ).val().split(",")[0];
213 if( $( "#milp" ).val().split(",")[1] ){
214 _args = JSON.parse( $( "#milp" ).val().split(",").slice(1).join() );
218 Notification.push("引数の解釈に失敗", error, "system");
220 launch( _app, _args );
222 $( "#kit-milp-search" ).click( function() {
223 launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#milp" ).val() } );
225 $( "#kit-milp-wikipedia" ).click( function() {
226 launch( "browser", { "url" : "https://ja.wikipedia.org/wiki/" + $( "#milp" ).val() } );
230 $("#dropdown-sound-slider").slider({
231 min: 0, max: 100, step: 1, value: 100,
233 System.audio.level = ui.value;
234 $("#dropdown-sound-level").text(ui.value);
235 localStorage.setItem("kit-audio-level", ui.value);
236 for( let i in System.audio.list ){
237 System.audio.list[i].volume = System.audio.level / 100;
239 if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
240 else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
243 if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
245 $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
246 if( $("#dropdown-sound-silent").is(":checked") ){
247 System.audio.silent = true;
248 $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
251 System.audio.silent = false;
252 $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
256 $("#kit-header-user").on("click", ()=>{
261 $(":root section:not(#desktop-l)").on("contextmenu", function() {
262 let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
263 S.selectedElement = _ptelem;
264 S.selectedText = window.getSelection();
265 $( "#kit-context-input" ).val( S.selectedText );
266 if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
267 else $("#kit-contextgroup-text").show();
268 if( _ptelem[0].id == "desktop-" + currentDesktop ){
269 $("#kit-contextgroup-desktop").show();
270 $("#kit-contextgroup-elem").hide();
273 $("#kit-contextgroup-desktop").hide();
274 $("#kit-contextgroup-elem").show();
276 $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
277 $("#kit-contextgroup-custom").hide();
279 let _ctxid = _ptelem.attr("data-kit-contextid") || _ptelem.attr("kit-context");
281 $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
282 let _ctxname = KWS.context[_ctxid].name || _ctxid;
283 $("#kit-context-custom").text( _ctxname );
284 for( let i in KWS.context[_ctxid]){
285 if( i == "name" ) continue;
286 $("#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>");
287 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
288 KWS.context[_ctxid][i].function();
289 $("#kit-context").fadeOut(300);
293 if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
294 $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
295 $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
298 $("#kit-context-open").on("click", function(){
299 S.alert("要素", S.selectedElement.clone());
301 $("#kit-context-save").on("click", function(){
302 S.obj2img( S.selectedElement , true );
304 $( "#kit-context-search" ).on("click", function(){
305 $("#kit-context").fadeOut(300);
306 launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#kit-context-input" ).val() } );
308 $( "#kit-context-input" ).keypress( function( e ) {
309 if( e.which == 13 ) $( "#kit-context-search" ).click();
311 $("#kit-context a").on("click", function(){
312 $("#kit-context").fadeOut(300);
314 $("#kit-context-vacuum").on("click", function(){
315 for( let i in process ){
316 KWS.vacuum( S.mouseX, S.mouseY );
319 $(".window").css("transition", "none");
322 $("#kit-context-fusen").on("click", function(){
327 $("section").on("click", function(){
328 $("#kit-context").fadeOut(300);
331 $( document ).delegate( "a", "click", function() {
333 launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
336 } ).on("mousemove", function(event){
337 System.mouseX = event.clientX;
338 System.mouseY = event.clientY;
339 }).delegate( ".textbox", "keypress", function( e ) {
340 if( e.which == 13 && this.id ){
341 if( $("#" + this.id + " + .kit-button").length ){
342 Notification.push("debug", this.id, "system");
343 $("#" + this.id + " + .kit-button").click();
345 else if( $("#" + this.id + " + kit-button").length ){
346 Notification.push("debug", this.id, "system");
347 $("#" + this.id + " + kit-button").click();
352 window.onresize = () => {
353 System.display.width = window.innerWidth;
354 System.display.height = window.innerWidth;
356 if( KWS.fullscreen.pid ){
357 KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
361 if( localStorage.getItem( "kit-lock" ) == "true" ){
363 setTimeout(() => System.lock(), 100);
367 function launch( str, args, dir ) {
369 System.args[pid] = args;
370 System.launchpath[pid] = dir || System.appdir + str;
372 if( System.appCache[str] ) {
373 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
375 appData( System.appCache[str] );
379 $.getJSON( S.launchpath[pid] + "/define.json", appData ).fail( function() {
380 Notification.push("kitアプリをロードできません", str + "を展開できませんでした。アプリが存在しないか、クロスオリジン要求がブロックされている可能性があります。詳細:https://kitdev.home.blog/", "system");
381 //System.alert( "起動エラー", "アプリケーションの起動に失敗しました<br>アプリケーション" + str + "は存在しないかアクセス権がありません(pid:" + processID + ")。ヘルプは<a class='kit-hyperlink' href='https://kitdev.home.blog/'>こちら</a>" );
385 Notification.push( "System Error", error, "system" );
390 function appData( data ) {
392 process[String( pid )] = {
394 time: System.time.obj.toLocaleString(),
399 System.appCache[data.id] = data;
400 let _taskAppend = "<span id='t" + pid + "'>";
401 if( data.icon && data.icon != "none" ) _taskAppend += "<img src='" + S.launchpath[pid] + "/" + data.icon + "'>";
402 _taskAppend += "<span id='tname" + pid + "'>" + data.name + "<span></span>";
403 $( "#tasks" ).append( _taskAppend );
405 $( "#t" + pid ).addClass( "task" ).click( function() {
406 if( $(this).hasClass("t-active") || $(this).hasClass("task-min") ) KWS.min( pid );
408 $("#w"+pid).css("z-index", KWS.windowIndex + 1);
409 KWS.refreshWindowIndex();
412 $( "#t" + pid ).addClass( "task" ).on( "mouseenter", function() {
413 $( "#task-ctx-name" ).text( data.name );
414 if( data.icon && data.icon != "none" ) $( "#task-ctx-img" ).attr( "src", System.launchpath[pid] + "/" + data.icon );
415 else $( "#task-ctx-img" ).hide();
416 $( "#task-ctx-ver" ).text( data.version + "/pid:" + pid );
417 $( "#task-ctx-info" ).off().on( "click", function() { System.appInfo( pid )} );
418 $( "#task-ctx-sshot" ).off().on( "click", function() { S.screenshot(pid, true) } );
419 $( "#task-ctx-min" ).off().on( "click", function() { KWS.min( String(pid) ) } );
420 if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
421 else $( "#task-ctx-front" ).show();
422 $( "#task-ctx-front" ).off().on( "click", function() {
423 $("#w"+pid).css("z-index", KWS.windowIndex + 1);
424 KWS.refreshWindowIndex();
426 $( "#task-ctx-close" ).off().on( "click", () => { System.close( String(pid) ) } );
427 $( "#task-ctx-kill" ).off().on( "click", () => { System.kill( String(data.id) ) } );
428 const _ctxleft = $( "#t" + pid ).offset().left;
429 const _ctxtop = window.innerHeight - $( "#t" + pid ).offset().top;
430 if( _ctxleft != $( "#task-ctx" ).offset().left ) {
431 $( "#task-ctx" ).hide();
433 $( "#task-ctx" ).css( "left", _ctxleft ).css( "bottom", _ctxtop ).show();
435 $( "section, #kit-tasks" ).on( "mouseenter", function() {
436 $( "#task-ctx" ).fadeOut( 200 );
438 $( "#t" + pid ).hover( function() {
439 prevWindowIndex = $( "#w" + pid ).css( "z-index" );
440 $( "#w" + pid ).addClass( "win-highlight" );
442 $( "#w" + pid ).removeClass( "win-highlight" );
444 let _windowAppend = "<div id='w" + pid + "'><div id='wt" + pid + "' class='wt'><i class='wmzx'><span id='wm" + pid + "'></span>";
445 if( data.support && data.support.fullscreen == true ) _windowAppend += "<span id='wz" + pid + "'></span>";
446 _windowAppend += "<span id='wx" + pid + "'></span></i>";
447 if( data.icon && data.icon != "none" ) _windowAppend += "<img src='" + S.launchpath[pid] + "/" + data.icon + "'>";
448 _windowAppend += "<span id='wtname" + pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + pid + "'></div></div>";
449 $( "#desktop-" + currentDesktop ).append( _windowAppend );
451 if( data.support && data.support.darkmode == true ) $("#winc"+pid).addClass("winc-darkmode");
452 if( KWS.darkmode ) $("#winc"+pid).addClass("kit-darkmode");
455 $("#winc"+pid).css("width", data.size.width).css("height", data.size.height);
458 let _minwidth = 200, _minheight = 40;
459 if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
460 if( data.resize.minHeight ) _minheight = data.resize.minHeight;
461 $("#winc"+pid).windowResizable({
463 minHeight: _minheight
467 var windowPos = 50 + ( pid % 10 ) * 20;
468 //$( "#w" + pid ).addClass( "window" ).draggable( {cancel: ".winc", stack: ".window"} ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", $( ".window" ).length + 1 );
470 $( "#w"+pid ).addClass( "window" ).pep({
471 elementsWithInteraction: ".winc, .ui-resizable-handle",
472 useCSSTranslation: false,
473 disableSelect: false,
475 initiate: function(){
476 $(this.el).addClass("ui-draggable-dragging");
478 this.el.style.zIndex = KWS.windowIndex;
479 KWS.refreshWindowIndex();
482 this.el.style.transition = "none";
483 $(this.el).removeClass("ui-draggable-dragging");
485 }).on( "mousedown", function(){
486 $(".window").css( "transition", "none" );
487 $(this).css("z-index", KWS.windowIndex + 1);
488 KWS.refreshWindowIndex();
489 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
490 KWS.refreshWindowIndex();
491 $( "#wm" + pid ).addClass( "wm fa fa-window-minimize" ).click( () => KWS.min( String(pid) ) );
492 $( "#wz" + pid ).addClass( "wz fas fa-square" ).click( () => KWS.max( String(pid) ) );
493 $( "#wx" + pid ).addClass( "wx fa fa-times" ).click( () => System.close( String(pid) ) );
494 $( "#winc" + pid ).resizable( {
496 } ).load( System.launchpath[pid] + "/" + data.view, (r, s, x) =>{
498 Notification.push("起動に失敗:" + x.status, x.statusText);
501 if( !data.script || data.script != "none" ) $.getScript( System.launchpath[pid] + "/" + data.script, () => App.kaf(pid) ).fail( () => App.kaf(pid) );
503 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
504 $( "head" ).append( '<link href="' + System.launchpath[pid] + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
505 //Notification.push("debug", "新規スタイルシートの読み込み", data.id);
508 localStorage.setItem( "kit-pid", processID );
513 function close( str ) {
518 function kill( str ) {
522 const System = new function() {
523 this.version = "0.2.0";
524 this.username = localStorage.getItem("kit-username");
525 this.appdir = localStorage.getItem("kit-appdir");
527 this.bootopt = new URLSearchParams(location.search);
533 "width": window.innerWidth,
534 "height": window.innerHeight
537 this.selectedElement = null;
538 this.selectedText = null;
540 this.dom = function(_pid, ..._elems) {
542 if( !_elems.length ) q = ",#winc" + _pid;
543 else for( let i of _elems ){
544 q += ",#winc" + _pid + " " + i;
546 return $( q.substring(1) );
549 this.userarea = new Object();
550 this.recycle = new Object();
556 this.launchpath = {};
558 this.support = $.support;
559 this.debugmode = false;
563 this.log = new Array();
566 this.setBattery = function(){
567 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
568 let _lv = e.level * 100;
569 System.battery = _lv;
574 this.screenshot = function( _pid, _popup ){
575 let _elem = document.querySelector("body");
576 if( _pid ) _elem = document.querySelector("#w"+_pid);
577 html2canvas( _elem ).then(canvas => {
579 canvas.style.border = "1px solid #909090";
580 S.save( canvas.toDataURL("image/png"), "image" );
586 this.obj2img = function( _obj, _popup ){
588 html2canvas( _elem ).then(canvas => {
590 canvas.style.border = "1px solid #909090";
591 S.save( canvas.toDataURL("image/png"), "image" );
597 this.save = function(data, type){
598 launch("fivr", { "save" : data, "type" : type });
601 this.open = function(filename){
602 launch("fivr", { "open" : filename });
605 this.preventClose = function( _pid ){
606 if( !process[_pid] ) return false;
607 process[_pid].preventclose = true;
611 this.shutdown = function(_opt) {
612 $( "#last-notification-close" ).click();
613 $( "#kit-power-back" ).click();
614 for( let i in process ) {
615 if( process[i].preventclose == true ){
616 S.dialog( "シャットダウンの中断", "pid" + System.appCache[process[i].id].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
617 process[i].preventclose = false;
622 else System.close( i );
624 $( "section" ).hide();
625 $( "body" ).css( "background-color", "black" );
626 $( "header, footer" ).fadeOut( 300 );
627 $( "#kit-wallpaper" ).fadeOut( 1500 );
628 if( _opt == "reboot" ) location.href = "autorun.html";
631 this.reboot = function() {
632 System.shutdown("reboot");
635 this.lock = function(){
636 System.moveDesktop( "l" );
638 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
639 $( "section, header, footer" ).css( "filter", "none" );
640 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
641 $( "header, footer, #kit-power" ).hide();
643 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
644 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
645 else $( "#lock-password" ).hide();
648 this.alert = function( title, content, winname ) {
649 launch( "alert", [title, content, winname] );
652 this.dialog = function( title, content, func ){
660 this.appInfo = function( _pid ){
661 let _title = "", _content = "";
662 let ac = System.appCache[process[_pid].id];
663 let _lp = System.launchpath[_pid];
665 _title = ac.name + " " + ac.version;
666 if( ac.icon && ac.icon != "none" ) _content = "<img style='height: 96px' src='" + _lp + "/" + ac.icon + "'><br>";
668 if( typeof ac[i] != "object" ) _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
670 _content += "<br><span style='font-weight: 100'>起動パス " + _lp + "</span><br><br>"
672 else _title = "取得に失敗しました";
673 System.alert( _title, _content );
676 this.installed = new Array();
679 this.min = function( _str ) {
683 this.close = function( _str ) {
684 let _pid = String( _str );
685 $( "#w" + _pid ).remove();
686 $( "#t" + _pid ).remove();
687 $( "#task-ctx" ).hide();
688 delete process[_pid];
689 KWS.refreshWindowIndex();
692 this.kill = function( _str ){
693 for( let pid in process ) {
694 if( process[pid] && process[pid].id == _str ) System.close( pid );
698 this.vacuum = function( _left, _top ){
699 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
713 this.clock = function() {
716 let Year = DD.getFullYear();
717 S.time.day = DD.getDay();
719 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
721 let DateN = ( "00" + DD.getDate() ).slice( -2 );
723 let Hour = ( "00" + DD.getHours() ).slice( -2 );
725 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
727 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
729 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
730 let MS = DD.getMilliseconds();
733 outer: { radius: .9, color: "transparent" },
734 inner: { radius: .85, color: "transparent" }
737 long: { from: .8, to: .7, width: 2, color: "#303030" },
738 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
741 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
742 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
743 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
745 let canvas = $(".dropdown-clock-canvas")[0];
746 canvas.width = "200", canvas.height = "200";
747 let context = canvas.getContext("2d");
748 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
749 let radius = Math.min(center.x, center.y), angle, len;
750 context.beginPath();context.fillStyle = circle.outer.color;
751 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
752 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
753 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
755 for( let i=0; i<60; i++ ){
756 angle = Math.PI * i / 30;
758 let line = ( i%5 == 0 ) ? lines.long : lines.short;
759 context.lineWidth = line.width, context.strokeStyle = line.color;
760 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
761 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
764 angle = Math.PI * ( Number(Hour)+Number(Min)/60 ) / 6, len = radius * hands.hour.length;
765 context.beginPath(), context.lineWidth = hands.hour.width;
766 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
767 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
768 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
769 angle = Math.PI * ( Number(Min)+Number(Sec) / 60) / 30, len = radius * hands.minute.length;
770 context.beginPath(), context.lineWidth = hands.minute.width;
771 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
772 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
773 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
774 angle = Math.PI * Number(Sec) / 30, len = radius * hands.second.length;
775 context.beginPath(), context.lineWidth = hands.second.width;
776 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
777 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
778 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
781 this.changeWallpaper = function( str ) {
782 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
783 localStorage.setItem( "kit-wallpaper", str )
786 this.moveDesktop = function( str ) {
788 $( "section" ).hide();
789 $( "#desktop-" + str ).show();
790 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
791 currentDesktop = str;
794 this.avoidMultiple = function( _pid, _alert ) {
795 let _id = process[_pid].id;
797 for( let i in process ) {
798 if( process[i].id == _id ) _cnt += 1;
800 Notification.push( "debug", _cnt );
802 System.close( _pid );
804 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
810 this.resizable = function( _pid, _elem, _width, _height ){
812 if( _elem ) E = String( _elem );
813 if( !_width ) _width = null;
814 if( !_height ) _height = "100";
815 $("#w" + _pid).resizable({
816 alsoResize: "#w" + _pid + " " + E,
822 this.initLauncher = function(data){
823 $("#launcher-apps").html("");
824 for( let i in data ){
825 $("#launcher-apps").append("<div class='launcher-app' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
827 if( !System.bootopt.get("safe") ){
828 for( let i of System.installed ){
829 $("#launcher-apps").append("<div class='launcher-app' data-define-path='" + i.path + "' data-define-id='" + i.id + "'><img src='" + i.icon + "'>" + i.name + "</div>");
832 $(".launcher-app").on("click", function(){
833 $("#launch").click();
834 if( $(this).attr("data-launch") ) launch( $(this).attr("data-launch") );
835 else if( $(this).attr("data-define-path") ){
836 launch( $(this).attr("data-define-id"), null, $(this).attr("data-define-path") );
841 this.clip = new function(){
843 this.history = new Array();
845 this.set = function( content ){
846 this.content = content;
847 this.history.push(content);
850 this.get = ()=>{ return this.content }
853 this.config = new function(){
854 this.apps = new Object();
857 this.audio = new function(){
858 this.level = localStorage["kit-audio-level"] || 100;
861 this.list = new Array();
863 this.volume = function( _level ){
864 $("#dropdown-sound-slider").slider("value", _level);
867 this.play = function( _audioid, _src ){
868 if( !System.audio.list[_audioid] ){
869 System.audio.list[_audioid] = new Audio(_src);
870 System.audio.list[_audioid].volume = System.audio.level / 100;
872 System.audio.list[_audioid].play();
875 this.get = function( _audioid ){
876 return System.audio.list[_audioid];
879 this.pause = function( _audioid ){
880 System.audio.list[_audioid].pause();
883 this.stop = function( _audioid ){
884 System.audio.list[_audioid].pause();
885 System.audio.list[_audioid] = null;
888 this.seek = function( _audioid, _time ){
889 System.audio.list[_audioid].fastSeek(_time);
892 this.mute = function( _audioid, _bool ){
893 System.audio.list[_audioid].muted = _bool;
898 const KWS = new function(){
899 this.version = "3.2.2";
902 this.darkmode = false;
904 this.changeWindowTitle = function( _pid, _str ){
905 $("#tname"+_pid).text( _str );
906 $("#wtname"+_pid).text( _str );
909 this.min = function( _str ) {
910 let _pid = String( _str );
911 if( $( "#w" + _pid ).is( ":visible" ) ) {
912 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
913 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
914 $( "#t" + _pid ).addClass( "task-min" );
917 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
918 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
919 $( "#t" + _pid ).removeClass( "task-min" );
931 this.max = function( _pid ){
932 if( KWS.fullscreen.pid ){
933 Notification.push("最大化に失敗", "最大化しているウィンドウがあります。");
936 $( "#wt"+_pid ).addClass("wtmaximize");
941 .addClass("windowmaximize")
942 .css("z-index", KWS.windowIndex + 1);
943 KWS.refreshWindowIndex();
945 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
946 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
947 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
948 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
950 KWS.resize( _pid, System.display.width, System.display.height - 30 );
952 $("#kit-header-fullscreen").show().on("click", () => {
955 KWS.fullscreen.pid = _pid;
958 this.unmax = function( _pid ){
959 if( _pid != KWS.fullscreen.pid ){
960 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
963 $( "#wt"+_pid ).removeClass("wtmaximize");
965 "top": KWS.fullscreen.prevTop,
966 "left": KWS.fullscreen.prevLeft
968 .removeClass("windowmaximize");
970 $("#kit-header-fullscreen").hide().off();
971 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
972 KWS.fullscreen.pid = null;
973 KWS.fullscreen.prevWidth = null;
974 KWS.fullscreen.prevHeight = null;
975 KWS.fullscreen.prevTop = null;
976 KWS.fullscreen.prevLeft = null;
979 this.vacuum = function( _left, _top ){
980 for( let i in process ){
981 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
984 $(".window").css("transition", "none");
989 this.windowIndex = 1;
991 this.refreshWindowIndex = function(){
992 let num = $(".window").length;
993 let array = new Array();
994 let obj = new Object();
995 for( let i = 0; i < num; i++ ){
996 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
999 array.sort( (a,b) => {
1000 return Number(a.zindex - b.zindex);
1002 for( let i in array ){
1003 document.getElementById(array[i].id).style.zIndex = i;
1005 $("#"+array[i].id).addClass("windowactive");
1006 $("#t"+String(array[i].id).substring(1)).addClass("t-active");
1007 KWS.active = String(array[i].id).substring(1);
1008 process[array[i].id.substring(1)].isactive = true;
1011 $("#"+array[i].id).removeClass("windowactive");
1012 $("#t"+String(array[i].id).substring(1)).removeClass("t-active");
1013 process[array[i].id.substring(1)].isactive = false;
1016 KWS.windowIndex = num;
1019 this.resize = function( _pid, _width, _height ){
1020 if( _width ) $("#winc"+_pid).css("width", _width)
1021 if( _height ) $("#winc"+_pid).css("height", _height);
1024 this.fusen = new function(){
1026 this.list = new Object();
1028 this.add = function(_text){
1029 KWS.fusen.list[KWS.fusen.fid] = String(_text);
1030 $("#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>");
1031 $("#kit-f"+KWS.fusen.fid).css({
1032 "left": Number(KWS.fusen.fid)*40 + 20,
1033 "top": Number(KWS.fusen.fid)*10 + 100,
1035 elementsWithInteraction: ".kit-fusen-textarea",
1036 useCSSTranslation: false,
1037 disableSelect: false,
1039 initiate: function(){
1040 $(this.el).css("ui-opacity", "0.7");
1043 this.el.style.transition = "none";
1044 $(this.el).css("ui-opacity", "1.0");
1047 $(".kit-fusen-textarea").off().on("change",function(){
1048 Notification.push($(this).attr("data-fid"), $(this).val(), "debug");
1049 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1050 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1052 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1056 this.remove = function(_fid){
1057 delete KWS.fusen.list[_fid];
1058 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1059 $("#kit-f"+_fid).remove();
1063 this.addCustomContext = function( _elem, _contextid, _obj ){
1064 KWS.context[_contextid] = _obj;
1072 "icon" : "fa-trash-alt",
1073 "function" : function(){
1074 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1080 "function" : function(){
1081 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1088 const Notification = new function() {
1090 this.list = new Object();
1092 this.goodnight = false;
1095 this.push = function( _title, _content, _app ) {
1096 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1099 this.list[this.nid] = {
1101 "content" : _content,
1103 "time" : System.time.obj.toLocaleString()
1105 if( !this.goodnight ){
1106 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1107 $( "#last-notification-title" ).text("").text( _title );
1108 $( "#last-notification-content" ).text("").text( _content );
1109 $( "#last-notification-app" ).text("").text( _app );
1110 $( "#last-notification" ).hide().show( "drop", {direction: "right"}, 300 );
1112 $( "#notifications" ).append( "<div class='notis' id='nt" + this.nid + "'><span class='notis_close' id='nc" + this.nid + "'></span><span><span class='fas fa-comment-alt'></span>" + _title + "</span>" + _content + "<div class='notis_time'>" + System.time.obj.toLocaleString() + "</div></div>" );
1113 $("#nc" + this.nid).on("click", function(){
1114 let _nid = this.id.slice(2);
1115 $("#nt" + _nid).fadeOut(300);
1118 $("#nt" + this.nid).on("click", function(){
1119 let _nid = this.id.slice(2);
1120 if( Notification.list[ _nid ].app != "system" ){
1121 launch(Notification.list[ _nid ].app);
1125 return (this.nid - 1);
1129 const App = new function() {
1130 this.changeWindowTitle = ( _pid, _t ) => {
1131 $( "#tname"+_pid ).text( _t );
1132 $( "#wtname"+_pid ).text( _t );
1133 process[_pid].title = _t;
1137 this.context = ( _cid, _obj ) => {
1138 KWS.context[ _cid ] = _obj;
1142 this.d = new Object();
1144 this.data = ( _pid, _name ) => {
1146 if( _name ) _r = App.d[_pid][_name];
1147 else _r = App.d[_pid];
1151 this.e = new Object();
1153 this.event = ( _pid, _name, _event ) => {
1154 if( !App.e[_pid] ) App.e[_pid] = new Object();
1155 App.e[_pid][_name] = _event;
1159 this.getPath = ( _pid, _path ) => System.launchpath[_pid] + _path;
1161 this.kaf = ( _pid ) => {
1162 for( let i of S.dom(_pid, ".kaf", "kaf", "[kaf]") ){
1163 if( i.hasAttribute("kit-ref") ){
1164 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
1166 if( i.hasAttribute("kit-e") ){
1167 let _eqs = i.getAttribute("kit-e").split(",");
1168 for( let k of _eqs ){
1169 let _eq = k.split(" ");
1170 $(i).on( _eq[1]||"click", App.e[_pid][_eq[0]] );
1173 if( i.hasAttribute("kit-src") ){
1174 $(i).attr("src", System.launchpath[_pid] +"/"+ i.getAttribute("kit-ref") )
1176 if( i.hasAttribute("kit-alert") ){
1177 $(i).on("click", ()=> System.alert( System.appCache[ process[_pid].id ].name, i.getAttribute("kit-alert") ) );
1179 if( i.hasAttribute("kit-launch") ){
1180 $(i).on("click", ()=> launch( i.getAttribute("kit-launch") ) );
1182 if( i.hasAttribute("kit-close") ){
1183 $(i).on("click", ()=> System.close( i.getAttribute("kit-close") || _pid ) );
1185 if( i.hasAttribute("kit-text") ){
1186 $(i).text( eval(i.getAttribute("kit-text")) );
1188 if( i.hasAttribute("kit-html") ){
1189 $(i).html( eval(i.getAttribute("kit-html")) );
1191 if( i.hasAttribute("kit-bind") ){
1192 if( App.d[_pid] == undefined ) App.d[_pid] = new Object();
1193 $(i).on("change", () => App.d[_pid][i.getAttribute("kit-bind")] = $(i).val() );
1198 this.load = ( _pid, _path ) => {
1199 S.dom(_pid).load( System.launchpath[_pid] +"/"+ _path, () => {
1205 this.preventClose = ( _pid, _bool ) => {
1206 process[_pid].preventclose = _bool || true;
1211 var process = {}, processID = 0, pid, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;