7 // THIS IS THE KIT KERNEL AND KIT WINDOW SYSTEM
8 // http://web.kitit.ml/
9 // https://github.com/mtsgi/kit
13 $( document ).ready( kit );
18 if( !localStorage.getItem( "kit-pid" ) ) processID = 0;
19 else processID = 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" );
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["kit-userarea"] ) System.userarea = JSON.parse(localStorage["kit-userarea"]);
56 if( localStorage["kit-recycle"] ) System.recycle = JSON.parse(localStorage["kit-recycle"]);
58 System.moveDesktop( "1" );
61 if( System.bootopt.get("safe") ) clockmove = setInterval( System.clock, 1000 );
62 else clockmove = setInterval( System.clock, 10 );
64 Notification.push( "kitへようこそ", localStorage["kit-username"] + "さん、こんにちは。", "system" );
66 if( localStorage.getItem( "kit-startup" ) == undefined ) {
67 localStorage.setItem( "kit-startup", new Array( "welcome" ) );
69 System.startup = localStorage.getItem( "kit-startup" ).split( "," );
70 if( System.bootopt.get("safe") ){
71 Notification.push( "セーフブート", "現在、kitをセーフモードで起動しています。", "system" );
72 System.alert( "セーフブート", "現在、kitをセーフモードで起動しています。<br><a class='kit-hyperlink' onclick='location.href=\"index.html\";'>通常モードで再起動</a>", "system" );
74 else for( let i of System.startup ) if( i != "" ) launch( i );
76 $("#kit-header-fullscreen").hide();
79 $( "#desktops" ).click( function() {
80 $( "#desktop-" + currentDesktop ).toggleClass( "selected-section" );
81 } ).mousedown( function() {
82 $( ".window" ).css( "opacity", "0.6" );
83 } ).mouseup( function() {
84 $( ".window" ).css( "opacity", "1.0" );
87 $( "#footer-tasks" ).click( function() {
88 if( $( "#kit-tasks" ).is( ":visible" ) ) {
89 $( "#kit-tasks" ).html( "" ).fadeOut( 300 );
92 $( "#task-ctx" ).fadeOut( 200 );
93 $( "#kit-tasks" ).html( $( "#tasks" ).html() ).fadeIn( 300 ).css( "z-index", "9997" );
97 $.getJSON("config/desktop.json", (data) => {
99 $(".desktop-icons").append("<div class='desktop-icon' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
101 $(".desktop-icon").on("click", function(){
102 launch( $(this).attr("data-launch") );
104 }).fail( function() {
105 Notification.push( "読み込みに失敗", "デスクトップ(config/desktop.json)の読み込みに失敗しました。", system );
108 $.getJSON("config/apps.json", System.initLauncher).fail( function() {
109 Notification.push( "ランチャー初期化失敗", "アプリケーション一覧(config/apps.json)の読み込みに失敗しました。", system );
111 $( "#kit-tasks" ).delegate( ".task", "click", function() {
112 System.close( this.id.slice( 1 ) );
116 $( "#footer-noti" ).click( function() {
117 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
118 if( $( "#notifications" ).is( ":visible" ) ) {
119 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
122 $( "#notifications" ).show( "drop", {direction: "right"}, 300 );
125 $( "#last-notification-close" ).click( function() {
126 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
128 $("#notifications-dnp").prop("checked", false).on("change", ()=>{
129 if( $("#notifications-dnp").is(":checked") ){
130 Notification.goodnight = true;
132 else Notification.goodnight = false;
135 $( ".power-button" ).click( function() {
136 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
137 $( "#last-notification" ).hide( "drop", {direction: "right"}, 300 );
138 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "blur(5px)" );
139 $( "#kit-power" ).fadeIn( 300 );
141 $( "#kit-power-back" ).click( function() {
142 $( "section, header, footer, #kit-wallpaper, .dropdown" ).css( "filter", "none" );
143 $( "#kit-power" ).fadeOut( 300 );
145 $( "#kit-power-shutdown" ).click( function() {
148 $( "#kit-power-reboot" ).click( function() {
151 $( "#kit-power-suspend" ).click( function() {
152 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
153 $( "#kit-power" ).fadeOut( 300 );
154 System.alert("サスペンド機能", "サスペンド機能はこのバージョンのkitではサポートされていません。");
156 $( "#kit-power-lock" ).click( function() {
159 $( "#lock-password" ).keypress( function( e ) {
160 if( e.which == 13 ) $( "#lock-unl" ).click();
162 $( "#lock-unl" ).click( function() {
163 if( !localStorage.getItem( "kit-password" ) || $( "#lock-password" ).val() == localStorage.getItem( "kit-password" ) ) {
164 $( "header, footer" ).show();
165 $( "section, header, footer, #kit-wallpaper" ).css( "filter", "none" );
166 $( "#lock-password" ).val( "" );
167 System.moveDesktop(1);
169 else $( "#lock-password" ).effect( "bounce", {distance: 12, times: 4}, 500 );
170 } ).hover( function() {
171 $( "#lock-unl span" ).removeClass( "fa-lock" ).addClass( "fa-lock-open" );
173 $( "#lock-unl span" ).removeClass( "fa-lock-open" ).addClass( "fa-lock" );
176 $( "#launch" ).click( function() {
177 $( "#notifications" ).hide( "drop", {direction: "right"}, 300 );
178 if( $( "#launcher" ).is( ":visible" ) ) {
179 $( "#kit-wallpaper" ).css( "filter", "none" );
180 $( "#desktop-" + currentDesktop ).show();
181 $( "#launcher" ).hide();
184 $( "#kit-wallpaper" ).css( "filter", "blur(5px)" )
185 $( "section" ).hide();
186 $( "#launcher" ).show();
191 $( "#milp" ).val( "" ).on( "focus", function() {
192 $( "#kit-milp" ).show();
193 } ).on( "blur", function() {
194 $( "#kit-milp" ).fadeOut( 200 );
195 } ).on( 'keydown keyup keypress change', function() {
196 $( "#kit-milp-text" ).text( $( this ).val() );
197 } ).keypress( function( e ) {
198 if( e.which == 13 ) $( "#kit-milp-launch" ).click();
200 $( "#kit-milp-launch" ).click( function() {
201 if( $("#milp").val() == "kit" ){
202 System.alert("", "<div style='text-align:left;'> _ _ _ <br>| | _(_) |_ <br>| |/ / | __|<br>| 〈| | |_ <br>|_|\_ \ _\__|</div><hr>", S.version);
205 let _app = $( "#milp" ).val().split(",")[0];
208 if( $( "#milp" ).val().split(",")[1] ){
209 _args = JSON.parse( $( "#milp" ).val().split(",").slice(1).join() );
213 Notification.push("引数の解釈に失敗", error, "system");
215 launch( _app, _args );
217 $( "#kit-milp-search" ).click( function() {
218 launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#milp" ).val() } );
220 $( "#kit-milp-wikipedia" ).click( function() {
221 launch( "browser", { "url" : "https://ja.wikipedia.org/wiki/" + $( "#milp" ).val() } );
225 $("#dropdown-sound-slider").slider({
226 min: 0, max: 100, step: 1, value: 100,
228 System.audio.level = ui.value;
229 $("#dropdown-sound-level").text(ui.value);
230 localStorage.setItem("kit-audio-level", ui.value);
231 for( let i in System.audio.list ){
232 System.audio.list[i].volume = System.audio.level / 100;
234 if( ui.value == 0 ) $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
235 else $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
238 if( localStorage["kit-audio-level"] ) System.audio.volume( localStorage["kit-audio-level"] );
240 $("#dropdown-sound-silent").prop("checked", false).on("change", ()=>{
241 if( $("#dropdown-sound-silent").is(":checked") ){
242 System.audio.silent = true;
243 $("#kit-header-sound-icon").removeClass("fa-volume-up").addClass("fa-volume-mute");
246 System.audio.silent = false;
247 $("#kit-header-sound-icon").removeClass("fa-volume-mute").addClass("fa-volume-up");
251 $("#kit-header-user").on("click", ()=>{
256 $(":root section:not(#desktop-l)").on("contextmenu", function() {
257 let _ptelem = $( document.elementFromPoint(S.mouseX, S.mouseY) );
258 S.selectedElement = _ptelem;
259 S.selectedText = window.getSelection();
260 $( "#kit-context-input" ).val( S.selectedText );
261 if( $( "#kit-context-input" ).val() == "" ) $("#kit-contextgroup-text").hide();
262 else $("#kit-contextgroup-text").show();
263 if( _ptelem[0].id == "desktop-" + currentDesktop ){
264 $("#kit-contextgroup-desktop").show();
265 $("#kit-contextgroup-elem").hide();
268 $("#kit-contextgroup-desktop").hide();
269 $("#kit-contextgroup-elem").show();
271 $( "#kit-context-elem" ).text( _ptelem.prop("tagName").toLowerCase() + "要素" );
272 $("#kit-contextgroup-custom").hide();
274 let _ctxid = _ptelem.attr("data-kit-contextid");
276 $("#kit-contextgroup-custom").show().html('<div id="kit-context-custom"></div>');
277 let _ctxname = KWS.context[_ctxid].name || _ctxid;
278 $("#kit-context-custom").text( _ctxname );
279 for( let i in KWS.context[_ctxid]){
280 if( i == "name" ) continue;
281 $("#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>");
282 $("#kit-context-" + _ctxid + "-" + i).on("click", () => {
283 KWS.context[_ctxid][i].function();
284 $("#kit-context").fadeOut(300);
288 if( _ptelem[0].id ) $( "#kit-context-elem" ).append( "#" + _ptelem[0].id );
289 $( "#kit-context-size" ).text( _ptelem[0].clientWidth + "✕" + _ptelem[0].clientHeight );
290 $("#kit-context").toggle().css("left", S.mouseX).css("top", S.mouseY);
293 $("#kit-context-open").on("click", function(){
294 S.alert("要素", S.selectedElement.clone());
296 $("#kit-context-save").on("click", function(){
297 S.obj2img( S.selectedElement , true );
299 $( "#kit-context-search" ).on("click", function(){
300 $("#kit-context").fadeOut(300);
301 launch( "browser", { "url" : "https://www.bing.com/search?q=" + $( "#kit-context-input" ).val() } );
303 $( "#kit-context-input" ).keypress( function( e ) {
304 if( e.which == 13 ) $( "#kit-context-search" ).click();
306 $("#kit-context a").on("click", function(){
307 $("#kit-context").fadeOut(300);
309 $("#kit-context-vacuum").on("click", function(){
310 for( let i in process ){
311 KWS.vacuum( S.mouseX, S.mouseY );
314 $(".window").css("transition", "none");
317 $("#kit-context-fusen").on("click", function(){
322 $("section").on("click", function(){
323 $("#kit-context").fadeOut(300);
326 $( document ).delegate( "a", "click", function() {
328 launch( localStorage.getItem( "kit-default-browser" ), { "url" : this.href } );
331 } ).on("mousemove", function(event){
332 System.mouseX = event.clientX;
333 System.mouseY = event.clientY;
334 }).delegate( ".textbox", "keypress", function( e ) {
335 if( e.which == 13 && this.id && $("#" + this.id + " + .kit-button") ){
336 Notification.push("debug", this.id, "system");
337 $("#" + this.id + " + .kit-button").click();
341 window.onresize = () => {
342 System.display.width = window.innerWidth;
343 System.display.height = window.innerWidth;
345 if( KWS.fullscreen.pid ){
346 KWS.resize( KWS.fullscreen.pid, System.display.width, System.display.height - 30 );
350 if( localStorage.getItem( "kit-lock" ) == "true" ){
352 setTimeout(() => System.lock(), 100);
356 function launch( str, args ) {
358 System.args[pid] = args;
359 if( System.appCache[str] ) {
360 if( KWS.fullscreen.pid ) KWS.unmax(KWS.fullscreen.pid);
362 appData( System.appCache[str] );
366 $.getJSON( S.appdir + str + "/define.json", appData ).fail( function() {
367 System.alert( "起動エラー", "アプリケーションの起動に失敗しました<br>アプリケーション" + str + "は存在しないかアクセス権がありません(pid:" + processID + ")。ヘルプは<a class='kit-hyperlink' href='https://kitdev.home.blog/'>こちら</a>" );
371 Notification.push( "System Error", error, "system" );
376 function appData( data ) {
378 process[String( pid )] = {
380 time: System.time.obj.toLocaleString(),
384 System.appCache[data.id] = data;
385 $( "#tasks" ).append( "<span id='t" + pid + "'><img src='./app/" + data.id + "/" + data.icon + "'><span id='tname" + pid + "'>" + data.name + "<span></span>" );
387 $( "#t" + pid ).addClass( "task" ).click( function() {
388 if( $(this).hasClass("t-active") || $(this).hasClass("task-min") ) KWS.min( pid );
390 $("#w"+pid).css("z-index", KWS.windowIndex + 1);
391 KWS.refreshWindowIndex();
394 $( "#t" + pid ).addClass( "task" ).on( "mouseenter", function() {
395 $( "#task-ctx-name" ).text( data.name );
396 $( "#task-ctx-img" ).attr( "src", "./app/" + data.id + "/" + data.icon );
397 $( "#task-ctx-ver" ).text( data.version + "/pid:" + pid );
398 $( "#task-ctx-info" ).off().on( "click", function() { System.appInfo( data.id )} );
399 $( "#task-ctx-sshot" ).off().on( "click", function() { S.screenshot(pid, true) } );
400 $( "#task-ctx-min" ).off().on( "click", function() { KWS.min( String(pid) ) } );
401 if( $(this).hasClass("t-active") ) $( "#task-ctx-front" ).hide();
402 else $( "#task-ctx-front" ).show();
403 $( "#task-ctx-front" ).off().on( "click", function() {
404 $("#w"+pid).css("z-index", KWS.windowIndex + 1);
405 KWS.refreshWindowIndex();
407 $( "#task-ctx-close" ).off().on( "click", () => { System.close( String(pid) ) } );
408 $( "#task-ctx-kill" ).off().on( "click", () => { System.kill( String(data.id) ) } );
409 const _ctxleft = $( "#t" + pid ).offset().left;
410 const _ctxtop = window.innerHeight - $( "#t" + pid ).offset().top;
411 if( _ctxleft != $( "#task-ctx" ).offset().left ) {
412 $( "#task-ctx" ).hide();
414 $( "#task-ctx" ).css( "left", _ctxleft ).css( "bottom", _ctxtop ).show();
416 $( "section, #kit-tasks" ).on( "mouseenter", function() {
417 $( "#task-ctx" ).fadeOut( 200 );
419 $( "#t" + pid ).hover( function() {
420 prevWindowIndex = $( "#w" + pid ).css( "z-index" );
421 $( "#w" + pid ).addClass( "win-highlight" );
423 $( "#w" + pid ).removeClass( "win-highlight" );
425 let WINDOWAPPEND = "<div id='w" + pid + "'><div id='wt" + pid + "' class='wt'><i class='wmzx'><span id='wm" + pid + "'></span>";
426 if( data.support && data.support.fullscreen == true ) WINDOWAPPEND += "<span id='wz" + pid + "'></span>";
427 WINDOWAPPEND += "<span id='wx" + pid + "'></span></i><img src='./app/" + data.id + "/" + data.icon + "'><span id='wtname" + pid + "'>" + data.name + "</span></div><div class='winc winc-" + data.id + "' id='winc" + pid + "'></div></div>";
428 $( "#desktop-" + currentDesktop ).append( WINDOWAPPEND );
429 if( data.support && data.support.darkmode == true ) $("#winc"+pid).addClass("winc-darkmode");
430 if( KWS.darkmode ) $("#winc"+pid).addClass("kit-darkmode");
433 $("#winc"+pid).css("width", data.size.width).css("height", data.size.height);
436 let _minwidth = 200, _minheight = 40;
437 if( data.resize.minWidth ) _minwidth = data.resize.minWidth;
438 if( data.resize.minHeight ) _minheight = data.resize.minHeight;
439 $("#winc"+pid).windowResizable({
441 minHeight: _minheight
445 var windowPos = 50 + ( pid % 10 ) * 20;
446 //$( "#w" + pid ).addClass( "window" ).draggable( {cancel: ".winc", stack: ".window"} ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", $( ".window" ).length + 1 );
448 $( "#w"+pid ).addClass( "window" ).pep({
449 elementsWithInteraction: ".winc, .ui-resizable-handle",
450 useCSSTranslation: false,
451 disableSelect: false,
453 initiate: function(){
454 $(this.el).addClass("ui-draggable-dragging");
456 this.el.style.zIndex = KWS.windowIndex;
457 KWS.refreshWindowIndex();
460 this.el.style.transition = "none";
461 $(this.el).removeClass("ui-draggable-dragging");
463 }).on( "mousedown", function(){
464 $(".window").css( "transition", "none" );
465 $(this).css("z-index", KWS.windowIndex + 1);
466 KWS.refreshWindowIndex();
467 } ).css( "left", windowPos + "px" ).css( "top", windowPos + "px" ).css( "z-index", KWS.windowIndex );
468 KWS.refreshWindowIndex();
469 $( "#wm" + pid ).addClass( "wm fa fa-window-minimize" ).click( () => KWS.min( String(pid) ) );
470 $( "#wz" + pid ).addClass( "wz fas fa-square" ).click( () => KWS.max( String(pid) ) );
471 $( "#wx" + pid ).addClass( "wx fa fa-times" ).click( () => System.close( String(pid) ) );
472 $( "#winc" + pid ).resizable( {
474 } ).load( "./app/" + data.id + "/" + data.view );
477 if( data.script != "none" ) $.getScript( "./app/" + data.id + "/" + data.script );
478 if( data.css != "none" && $("#kit-style-"+data.id).length == 0 ){
479 $( "head" ).append( '<link href="./app/' + data.id + '/' + data.css + '" rel="stylesheet" id="kit-style-' + data.id + '"></link>' );
480 Notification.push("debug", "新規スタイルシートの読み込み", data.id);
484 localStorage.setItem( "kit-pid", processID );
488 function appInfo( str ){
493 function close( str ) {
498 function kill( str ) {
502 const System = new function() {
503 this.version = "0.2.0";
504 this.username = localStorage.getItem("kit-username");
505 this.appdir = localStorage.getItem("kit-appdir");
507 this.bootopt = new URLSearchParams(location.search);
513 "width": window.innerWidth,
514 "height": window.innerHeight
517 this.selectedElement = null;
518 this.selectedText = null;
520 this.dom = function(_pid, _elements) {
521 _elements = _elements || "";
522 return $("#winc" + _pid + " " + _elements);
525 this.userarea = new Object();
526 this.recycle = new Object();
532 this.support = $.support;
533 this.debugmode = false;
537 this.log = new Array();
540 this.setBattery = function(){
541 if( navigator.getBattery ) navigator.getBattery().then((e)=>{
542 let _lv = e.level * 100;
543 System.battery = _lv;
548 this.screenshot = function( _pid, _popup ){
549 let _elem = document.querySelector("body");
550 if( _pid ) _elem = document.querySelector("#w"+_pid);
551 html2canvas( _elem ).then(canvas => {
553 canvas.style.border = "1px solid #909090";
554 S.save( canvas.toDataURL("image/png"), "image" );
560 this.obj2img = function( _obj, _popup ){
562 html2canvas( _elem ).then(canvas => {
564 canvas.style.border = "1px solid #909090";
565 S.save( canvas.toDataURL("image/png"), "image" );
571 this.save = function(data, type){
572 launch("fivr", { "save" : data, "type" : type });
575 this.open = function(filename){
576 launch("fivr", { "open" : filename });
579 this.preventClose = function( _pid ){
580 if( !process[_pid] ) return false;
581 process[_pid].preventclose = true;
585 this.shutdown = function(_opt) {
586 $( "#last-notification-close" ).click();
587 $( "#kit-power-back" ).click();
588 for( let i in process ) {
589 if( process[i].preventclose == true ){
590 S.dialog( "シャットダウンの中断", "pid" + System.appCache[process[i].id].name + "がシャットダウンを妨げています。<br>強制終了してシャットダウンを続行する場合は[OK]を押下してください。", () => {
591 process[i].preventclose = false;
596 else System.close( i );
598 $( "section" ).hide();
599 $( "body" ).css( "background-color", "black" );
600 $( "header, footer" ).fadeOut( 300 );
601 $( "#kit-wallpaper" ).fadeOut( 1500 );
602 if( _opt == "reboot" ) location.reload();
605 this.reboot = function() {
606 System.shutdown("reboot");
609 this.lock = function(){
610 System.moveDesktop( "l" );
612 $( "#lock-user-icon" ).css( "background", localStorage.getItem( "kit-user-color" ) );
613 $( "section, header, footer" ).css( "filter", "none" );
614 $( "#kit-wallpaper" ).css( "filter", "blur(20px)" );
615 $( "header, footer, #kit-power" ).hide();
617 $( "#lock-username" ).text( localStorage.getItem( "kit-username" ) );
618 if( localStorage.getItem( "kit-password" ) ) $( "#lock-password" ).show();
619 else $( "#lock-password" ).hide();
622 this.alert = function( title, content, winname ) {
623 launch( "alert", [title, content, winname] );
626 this.dialog = function( title, content, func ){
634 this.appInfo = function( str ){
635 let _title = "", _content = "";
636 let ac = System.appCache[str];
638 _title = ac.name + " (" + ac.version + ")";
639 _content = "<img style='height: 96px' src='./app/" + ac.id + "/" + ac.icon + "'><br>";
641 _content += "<div><span style='font-weight: 100'>" + i + " </span>" + ac[i] + "</div>";
644 else _title = "取得に失敗しました";
645 System.alert( _title, _content );
648 this.installed = new Array();
651 this.min = function( _str ) {
655 this.close = function( _str ) {
656 let _pid = String( _str );
657 $( "#w" + _pid ).remove();
658 $( "#t" + _pid ).remove();
659 $( "#task-ctx" ).hide();
660 delete process[_pid];
661 KWS.refreshWindowIndex();
664 this.kill = function( _str ){
665 for( let pid in process ) {
666 if( process[pid] && process[pid].id == _str ) System.close( pid );
670 this.vacuum = function( _left, _top ){
671 KWS.vacuum( _left, _top ); //非推奨です(削除予定)。
685 this.clock = function() {
688 let Year = DD.getFullYear();
689 S.time.day = DD.getDay();
691 let Month = ( "00" + Number(DD.getMonth()+1) ).slice( -2 );
693 let DateN = ( "00" + DD.getDate() ).slice( -2 );
695 let Hour = ( "00" + DD.getHours() ).slice( -2 );
697 let Min = ( "00" + DD.getMinutes() ).slice( -2 );
699 let Sec = ( "00" + DD.getSeconds() ).slice( -2 );
701 $( ".os-time" ).text( Hour + ":" + Min + ":" + Sec );
702 let MS = DD.getMilliseconds();
705 outer: { radius: .9, color: "transparent" },
706 inner: { radius: .85, color: "transparent" }
709 long: { from: .8, to: .7, width: 2, color: "#303030" },
710 short: { from: .8, to: .75, width: 1, color: "#a0a0a0" }
713 hour: { length: .4, width: 3, cap: "butt", color: "#303030", ratio: .2 },
714 minute: { length: .67, width: 2, cap: "butt", color: "#303030", ratio: .2 },
715 second: { length: .67, width: 1, cap: "butt", color: "dodgerblue", ratio: .2 }
717 let canvas = $(".dropdown-clock-canvas")[0];
718 canvas.width = "200", canvas.height = "200";
719 let context = canvas.getContext("2d");
720 let center = { x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2) };
721 let radius = Math.min(center.x, center.y), angle, len;
722 context.beginPath();context.fillStyle = circle.outer.color;
723 context.arc(center.x, center.y, radius * circle.outer.radius, 0, Math.PI * 2, false);
724 context.fill();context.beginPath();context.fillStyle = circle.inner.color;
725 context.arc(center.x, center.y, radius * circle.inner.radius, 0, Math.PI * 2, false);
727 for( let i=0; i<60; i++ ){
728 angle = Math.PI * i / 30;
730 let line = ( i%5 == 0 ) ? lines.long : lines.short;
731 context.lineWidth = line.width, context.strokeStyle = line.color;
732 context.moveTo(center.x + Math.sin(angle) * radius * line.from, center.y - Math.cos(angle) * radius * line.from)
733 context.lineTo(center.x + Math.sin(angle) * radius * line.to, center.y - Math.cos(angle) * radius * line.to);
736 angle = Math.PI * ( Hour+Min/60 ) / 6, len = radius * hands.hour.length;
737 context.beginPath(), context.lineWidth = hands.hour.width;
738 context.lineCap = hands.hour.cap, context.strokeStyle = hands.hour.color;
739 context.moveTo(center.x - Math.sin(angle) * len * hands.hour.ratio, center.y + Math.cos(angle) * len * hands.hour.ratio);
740 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
741 angle = Math.PI * (Min + Sec / 60) / 30, len = radius * hands.minute.length;
742 context.beginPath(), context.lineWidth = hands.minute.width;
743 context.lineCap = hands.minute.cap, context.strokeStyle = hands.minute.color;
744 context.moveTo(center.x - Math.sin(angle) * len * hands.minute.ratio, center.y + Math.cos(angle) * len * hands.minute.ratio);
745 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
746 angle = Math.PI * Sec / 30, len = radius * hands.second.length;
747 context.beginPath(), context.lineWidth = hands.second.width;
748 context.lineCap = hands.second.cap, context.strokeStyle = hands.second.color;
749 context.moveTo(center.x - Math.sin(angle) * len * hands.second.ratio, center.y + Math.cos(angle) * len * hands.second.ratio);
750 context.lineTo(center.x + Math.sin(angle) * len, center.y - Math.cos(angle) * len), context.stroke();
753 this.changeWallpaper = function( str ) {
754 $( "#kit-wallpaper" ).css( "background", str ).css( "background-size", "cover" );
755 localStorage.setItem( "kit-wallpaper", str )
758 this.moveDesktop = function( str ) {
760 $( "section" ).hide();
761 $( "#desktop-" + str ).show();
762 $( "#desktops" ).html( "<span class='far fa-clone'></span>Desktop" + str );
763 currentDesktop = str;
766 this.avoidMultiple = function( _pid, _alert ) {
767 let _id = process[_pid].id;
769 for( let i in process ) {
770 if( process[i].id == _id ) _cnt += 1;
774 System.close( _pid );
776 System.alert( "多重起動", "アプリケーション" + _id + "が既に起動しています。このアプリケーションの多重起動は許可されていません。" );
782 this.resizable = function( _pid, _elem, _width, _height ){
784 if( _elem ) E = String( _elem );
785 if( !_width ) _width = null;
786 if( !_height ) _height = "100";
787 $("#w" + _pid).resizable({
788 alsoResize: "#w" + _pid + " " + E,
794 this.initLauncher = function(data){
795 for( let i in data ){
796 $("#launcher-apps").append("<div class='launcher-app' data-launch='" + i + "'><img src='" + data[i].icon + "'>" + data[i].name + "</div>");
798 $(".launcher-app").on("click", function(){
799 $("#launch").click();
800 launch( $(this).attr("data-launch") );
804 this.clip = new function(){
806 this.history = new Array();
808 this.set = function( content ){
809 this.content = content;
810 this.history.push(content);
813 this.get = ()=>{ return this.content }
816 this.config = new function(){
817 this.apps = new Object();
820 this.audio = new function(){
821 this.level = localStorage["kit-audio-level"] || 100;
824 this.list = new Array();
826 this.volume = function( _level ){
827 $("#dropdown-sound-slider").slider("value", _level);
830 this.play = function( _audioid, _src ){
831 if( !System.audio.list[_audioid] ){
832 System.audio.list[_audioid] = new Audio(_src);
833 System.audio.list[_audioid].volume = System.audio.level / 100;
835 System.audio.list[_audioid].play();
838 this.get = function( _audioid ){
839 return System.audio.list[_audioid];
842 this.pause = function( _audioid ){
843 System.audio.list[_audioid].pause();
846 this.stop = function( _audioid ){
847 System.audio.list[_audioid].pause();
848 System.audio.list[_audioid] = null;
851 this.seek = function( _audioid, _time ){
852 System.audio.list[_audioid].fastSeek(_time);
855 this.mute = function( _audioid, _bool ){
856 System.audio.list[_audioid].muted = _bool;
861 const KWS = new function(){
862 this.version = "3.2.2";
865 this.darkmode = false;
867 this.changeWindowTitle = function( _pid, _str ){
868 $("#tname"+_pid).text( _str );
869 $("#wtname"+_pid).text( _str );
872 this.min = function( _str ) {
873 let _pid = String( _str );
874 if( $( "#w" + _pid ).is( ":visible" ) ) {
875 $( "#w" + _pid ).css("transition", "none").hide( "drop", {direction: "down"}, 300 );
876 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
877 $( "#t" + _pid ).addClass( "task-min" );
880 $( "#w" + _pid ).show( "drop", {direction: "down"}, 300 );
881 $( "#task-ctx" ).effect( "bounce", {distance: 12, times: 1}, 400 );
882 $( "#t" + _pid ).removeClass( "task-min" );
894 this.max = function( _pid ){
895 if( KWS.fullscreen.pid ){
896 Notification.push("最大化に失敗", "最大化しているウィンドウがあります。");
899 $( "#wt"+_pid ).addClass("wtmaximize");
904 .addClass("windowmaximize")
905 .css("z-index", KWS.windowIndex + 1);
906 KWS.refreshWindowIndex();
908 KWS.fullscreen.prevWidth = $("#winc"+_pid).outerWidth();
909 KWS.fullscreen.prevHeight = $("#winc"+_pid).outerHeight();
910 KWS.fullscreen.prevTop = $("#w"+_pid).offset().top;
911 KWS.fullscreen.prevLeft = $("#w"+_pid).offset().left;
913 KWS.resize( _pid, System.display.width, System.display.height - 30 );
915 $("#kit-header-fullscreen").show().on("click", () => {
918 KWS.fullscreen.pid = _pid;
921 this.unmax = function( _pid ){
922 if( _pid != KWS.fullscreen.pid ){
923 Notification.push("最大化解除に失敗", "対象がフルスクリーンウィンドウではありません。");
926 $( "#wt"+_pid ).removeClass("wtmaximize");
928 "top": KWS.fullscreen.prevTop,
929 "left": KWS.fullscreen.prevLeft
931 .removeClass("windowmaximize");
933 $("#kit-header-fullscreen").hide().off();
934 KWS.resize( _pid, KWS.fullscreen.prevWidth, KWS.fullscreen.prevHeight );
935 KWS.fullscreen.pid = null;
936 KWS.fullscreen.prevWidth = null;
937 KWS.fullscreen.prevHeight = null;
938 KWS.fullscreen.prevTop = null;
939 KWS.fullscreen.prevLeft = null;
942 this.vacuum = function( _left, _top ){
943 for( let i in process ){
944 $("#w"+i).css("transition", ".5s all ease").css("left", _left ).css("top", _top );
947 $(".window").css("transition", "none");
952 this.windowIndex = 1;
954 this.refreshWindowIndex = function(){
955 let num = $(".window").length;
956 let array = new Array();
957 let obj = new Object();
958 for( let i = 0; i < num; i++ ){
959 obj = { id: $(".window")[i].id, zindex: $(".window")[i].style.zIndex };
962 array.sort( (a,b) => {
963 return Number(a.zindex - b.zindex);
965 for( let i in array ){
966 document.getElementById(array[i].id).style.zIndex = i;
968 $("#"+array[i].id).addClass("windowactive");
969 $("#t"+String(array[i].id).substring(1)).addClass("t-active");
970 KWS.active = String(array[i].id).substring(1);
971 process[array[i].id.substring(1)].isactive = true;
974 $("#"+array[i].id).removeClass("windowactive");
975 $("#t"+String(array[i].id).substring(1)).removeClass("t-active");
976 process[array[i].id.substring(1)].isactive = false;
979 KWS.windowIndex = num;
982 this.resize = function( _pid, _width, _height ){
983 if( _width ) $("#winc"+_pid).css("width", _width)
984 if( _height ) $("#winc"+_pid).css("height", _height);
987 this.fusen = new function(){
989 this.list = new Object();
991 this.add = function(_text){
992 KWS.fusen.list[KWS.fusen.fid] = String(_text);
993 $("#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+"' data-kit-contextid='fusen'>"+_text+"</textarea></div>");
994 $("#kit-f"+KWS.fusen.fid).css({
995 "left": Number(KWS.fusen.fid)*40 + 20,
996 "top": Number(KWS.fusen.fid)*10 + 100,
998 elementsWithInteraction: ".kit-fusen-textarea",
999 useCSSTranslation: false,
1000 disableSelect: false,
1002 initiate: function(){
1003 $(this.el).css("ui-opacity", "0.7");
1006 this.el.style.transition = "none";
1007 $(this.el).css("ui-opacity", "1.0");
1010 $(".kit-fusen-textarea").off().on("change",function(){
1011 Notification.push($(this).attr("data-fid"), $(this).val(), "debug");
1012 KWS.fusen.list[$(this).attr("data-fid")] = $(this).val();
1013 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1015 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1019 this.remove = function(_fid){
1020 delete KWS.fusen.list[_fid];
1021 localStorage.setItem("kit-fusen", JSON.stringify( KWS.fusen.list ));
1022 $("#kit-f"+_fid).remove();
1026 this.addCustomContext = function( _elem, _contextid, _obj ){
1027 KWS.context[_contextid] = _obj;
1035 "icon" : "fa-trash-alt",
1036 "function" : function(){
1037 KWS.fusen.remove( S.selectedElement.attr("data-fid") );
1043 "function" : function(){
1044 KWS.fusen.add( KWS.fusen.list[S.selectedElement.attr("data-fid")] );
1051 const Notification = new function() {
1053 this.list = new Object();
1055 this.goodnight = false;
1058 this.push = function( _title, _content, _app ) {
1059 if( !System.debugmode && ( _title == "debug" || _app == "debug" ) ){
1062 this.list[this.nid] = {
1064 "content" : _content,
1066 "time" : System.time.obj.toLocaleString()
1068 if( !this.goodnight ){
1069 if( this.sound ) System.audio.play( "n" + this.nid, this.sound );
1070 $( "#last-notification-title" ).text("").text( _title );
1071 $( "#last-notification-content" ).text("").text( _content );
1072 $( "#last-notification-app" ).text("").text( _app );
1073 $( "#last-notification" ).hide().show( "drop", {direction: "right"}, 300 );
1075 $( "#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>" );
1076 $("#nc" + this.nid).on("click", function(){
1077 let _nid = this.id.slice(2);
1078 $("#nt" + _nid).fadeOut(300);
1081 $("#nt" + this.nid).on("click", function(){
1082 let _nid = this.id.slice(2);
1083 if( Notification.list[ _nid ].app != "system" ){
1084 launch(Notification.list[ _nid ].app);
1088 return (this.nid - 1);
1092 var process = {}, processID = 0, pid, currentDesktop = 1, currentCTX = "", prevWindowIndex, S;