Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //<?php require_once('../../js_asm.php'); ?>
  2. var mWindowID = <?=(isset($_GET['w']))?intval($_GET['w']):0;?>;
  3. var mAuxWindows = [];
  4. function isMasterWindow(){
  5. var cWindowSessionID = window.localStorage.getItem("cWindowSID");
  6. if( cWindowSessionID == undefined ){
  7. window.localStorage.clear();
  8. window.localStorage.setItem("cWindowSID", '<?=$Session;?>' );
  9. } else {
  10. if( cWindowSessionID != '<?=$Session;?>' ){
  11. window.localStorage.clear();
  12. window.localStorage.setItem("cWindowSID", '<?=$Session;?>' );
  13. } else {
  14. return false;
  15. };
  16. };
  17. return true;
  18. };
  19. function refreshAuxWindows(){
  20. };
  21. function closeAuxWindows(){
  22. };
  23. function isFullScreen() {
  24. return document.fullscreenElement !== null;
  25. }
  26. let previousX = window.screenX;
  27. let previousY = window.screenY;
  28. setInterval(() => {
  29. const currentX = window.screenX;
  30. const currentY = window.screenY;
  31. if (currentX !== previousX || currentY !== previousY) {
  32. // Window has moved
  33. console.log("Window moved!");
  34. console.log("New Position X:", currentX, "Y:", currentY);
  35. previousX = currentX;
  36. previousY = currentY;
  37. }
  38. }, 700); // Check every 700 milliseconds
  39. /*
  40. if (!('getScreenDetails' in window)) {
  41. // Returning a one-element array with the current screen,
  42. // noting that there might be more.
  43. window.getScreenDetails = async () => [window.screen];
  44. // Set to `false`, noting that this might be a lie.
  45. window.screen.isExtended = false;
  46. }
  47. */
  48. async function getDisplayInfo() {
  49. if (window.screen.isExtended) {
  50. console.log("Multiple displays detected.");
  51. } else {
  52. console.log("Single display detected.");
  53. }
  54. if ('getScreenDetails' in window) {
  55. try {
  56. const screenDetails = await window.getScreenDetails();
  57. screenDetails.screens.forEach((screen, index) => {
  58. console.log(`Display ${index + 1}:`);
  59. console.log(` Width: ${screen.width}`);
  60. console.log(` Height: ${screen.height}`);
  61. console.log(` Left: ${screen.left}`);
  62. console.log(` Top: ${screen.top}`);
  63. });
  64. } catch (error) {
  65. console.error("Error getting screen details:", error);
  66. }
  67. } else {
  68. console.log("window.getScreenDetails() is not supported.");
  69. console.log(`Display 0:`);
  70. console.log(` Width: ${window.screen.width}`);
  71. console.log(` Height: ${window.screen.height}`);
  72. console.log(` Left: ${window.screen.left}`);
  73. console.log(` Top: ${window.screen.top}`);
  74. }
  75. };
  76. async function doCheckWindowSize(){
  77. //var zz = window.getScreenDetails();
  78. if ('getScreenDetails' in window) {
  79. try{
  80. const screenDetails = await window.getScreenDetails();
  81. screenDetails.addEventListener('screenschange', (event) => {
  82. if (screenDetails.screens.length !== currentScreenLength) {
  83. currentScreenLength = screenDetails.screens.length;
  84. //updateScreenInfo();
  85. }
  86. });
  87. } catch( err ){
  88. console.log( 'Permission denied or API not supported:', err );
  89. };
  90. try {
  91. permission =
  92. ((navigator.permissions.query({ name: 'window-management' })).state === 'granted')
  93. ? 'Granted'
  94. : 'No Permission';
  95. } catch (err) {
  96. console.error(err);
  97. }
  98. currentScreenLength = screenDetails.screens.length;
  99. //updateScreenInfo();
  100. } else {
  101. screenDetails = window.screen;
  102. permission = 'Window Management API - NOT SUPPORTED';
  103. currentScreenLength = 1;
  104. //updateScreenInfo();
  105. };
  106. getDisplayInfo();
  107. if( isMasterWindow() ){
  108. //window.open('/?w=1', 'app_second', 'location=0,menubar=0,status=0,titlebar=0,toolbar=0,left=20,top=20,width=' + screen.availWidth + ',height=' + screen.availHeight);
  109. if (parseInt(navigator.appVersion)>3) {
  110. if (navigator.appName=="Netscape") {
  111. winW2 = window.innerWidth;
  112. winH2 = window.innerHeight;
  113. if ( winH2<700 ) winH2=700;
  114. };
  115. if (navigator.appName.indexOf("Microsoft")!=-1) {
  116. winW2 = document.body.offsetWidth;
  117. winH2 = document.body.offsetHeight;
  118. if ( winH2<700 ) winH2=700;
  119. };
  120. };
  121. if ( winW2 != winW || winH2!=winH ){
  122. updateUserScreenResolution( winW2, winH2 );
  123. };
  124. } else {
  125. //requestBodyFullscreen();
  126. //alert( "AUX Window:"+mWindowID );
  127. };
  128. };
  129. function requestBodyFullscreen() {
  130. const body = document.body;
  131. if (body.requestFullscreen) {
  132. body.requestFullscreen();
  133. } else if (body.mozRequestFullScreen) { /* Firefox */
  134. body.mozRequestFullScreen();
  135. } else if (body.webkitRequestFullscreen) { /* Chrome, Safari, Opera */
  136. body.webkitRequestFullscreen();
  137. } else if (body.msRequestFullscreen) { /* IE/Edge */
  138. body.msRequestFullscreen();
  139. }
  140. };
  141. function exitBodyFullscreen() {
  142. if (document.exitFullscreen) {
  143. document.exitFullscreen();
  144. } else if (document.mozCancelFullScreen) { /* Firefox */
  145. document.mozCancelFullScreen();
  146. } else if (document.webkitExitFullscreen) { /* Chrome, Safari, Opera */
  147. document.webkitExitFullscreen();
  148. } else if (document.msExitFullscreen) { /* IE/Edge */
  149. document.msExitFullscreen();
  150. }
  151. };
  152. function initMultiWindows(){
  153. return;
  154. document.addEventListener('fullscreenchange', function() {
  155. if (isFullScreen()) {
  156. console.log("Fullscreen mode activated.");
  157. } else {
  158. console.log("Fullscreen mode deactivated.");
  159. }
  160. });
  161. document.addEventListener("fullscreenerror", (event) => {
  162. console.log("Fullscreen Error.");
  163. });
  164. if( mWindowID == 0 ){
  165. } else {
  166. //Unreg Windows
  167. mAuxWindows = undefined;
  168. window.addEventListener('beforeunload', function(event) {
  169. console.log("BeforeUnload Woerks!");
  170. //event.preventDefault();
  171. //event.returnValue = null;
  172. });
  173. };
  174. doCheckWindowSize();
  175. };