diff --git a/app/custom.js b/app/custom.js new file mode 100644 index 0000000000000000000000000000000000000000..f2332fa40f42d0c03ec64ffd2f7c26a8e8f8e57c --- /dev/null +++ b/app/custom.js @@ -0,0 +1,43 @@ +/*This is the custom file made by OPENSLX members to integrate +noVNC with our own website*/ + + +/* about 'onunload' and 'onbefore unload': + +onunload is responsible for executing an instruction when the +page is closed. It also causes issue with IE and AJAX. + +onbeforeunload is more efficient because it does not run in +competition with the actual closing of the window and is triggered before onunload + +I know Opera used to not acknowledge onbeforeunload - not sure if +they've fixed that, but I always register the listener for both to be safe: + +window.onunload = window.onbeforeunload = (function(){...*/ + +//this is called whenever the user refreshes/goes back or forward/goes to a new url/closes the tab +$(window).on('beforeunload', function(){ + //if you want an event that happens only when the 'x' button is clicked then refer to: + // http://stackoverflow.com/questions/20853142/trying-to-detect-browser-close-event + //and look at the second answer + + console.log('root says bye byee'); //this is working but alerts aren't working + //TODO:send message to the server to shut down the VM + + return 'something'; +}); + +/*TODO: under systems management/modules make a button to 'install' software in +the VM. into that page's HTML we already have the imgid, token and imgtoken. +Just send all of it to the server so it knows which VM to turn on. + +After that the server should fire the taskmanager to actually oṕen the vm +and fire the following commands in different processes: + +virt-run.sh iso + +./utils/launch.sh --vnc localhost:5930 + + +The second command returns a link to access the VM. This link should be sent to the client. +TODO: restrict the webpage pointed by the link ONLY to the user who OWNS the VM. diff --git a/app/ui.js b/app/ui.js index ad80c63baceb24e856e9276c63ec4abf62fc25c2..ace9240d3a0cca7a6d8c1467114b60c3356606c0 100644 --- a/app/ui.js +++ b/app/ui.js @@ -133,6 +133,9 @@ var UI; document.documentElement.classList.add("noVNC_touch"); // Remove the address bar setTimeout(function() { window.scrollTo(0, 1); }, 100); + UI.forceSetting('clip', true); + } else { + UI.initSetting('clip', false); } // Restore control bar position @@ -225,7 +228,6 @@ var UI; UI.initSetting('encrypt', (window.location.protocol === "https:")); UI.initSetting('true_color', true); UI.initSetting('cursor', !Util.isTouchDevice); - UI.initSetting('clip', false); UI.initSetting('resize', 'off'); UI.initSetting('shared', true); UI.initSetting('view_only', false); @@ -266,6 +268,7 @@ var UI; addResizeHandlers: function() { window.addEventListener('resize', UI.applyResizeMode); window.addEventListener('resize', UI.updateViewClip); + window.addEventListener('resize', UI.updateViewDrag); }, addControlbarHandlers: function() { @@ -557,9 +560,9 @@ var UI; status_type = 'normal'; } - statusElem.classList.remove("noVNC_status_normal"); - statusElem.classList.remove("noVNC_status_warn"); - statusElem.classList.remove("noVNC_status_error"); + statusElem.classList.remove("noVNC_status_normal", + "noVNC_status_warn", + "noVNC_status_error"); switch (status_type) { case 'warning': @@ -846,6 +849,12 @@ var UI; return val; }, + // Force a setting to be a certain value + forceSetting: function(name, val) { + UI.updateSetting(name, val); + return val; + }, + // Read form control compatible setting from cookie getSetting: function(name) { var ctrl = document.getElementById('noVNC_setting_' + name); @@ -1071,6 +1080,7 @@ var UI; }, disconnect: function() { + console.log('luiza disconnect'); UI.closeAllPanels(); UI.rfb.disconnect(); @@ -1095,7 +1105,9 @@ var UI; }, disconnectFinished: function (rfb, reason) { - if (typeof reason !== 'undefined') { + alert("luiza disconnect fnished"); + console.log('luiza disconnected finished'); + if (typeof reason !== 'undefined') { UI.showStatus(reason, 'error'); } else if (UI.getSetting('reconnect', false) === true && !UI.inhibit_reconnect) { document.getElementById("noVNC_transition_text").textContent = _("Reconnecting..."); @@ -1218,9 +1230,7 @@ var UI; var display = UI.rfb.get_display(); var resizeMode = UI.getSetting('resize'); display.set_scale(1); - - // Make sure the viewport is adjusted first - UI.updateViewClip(); + UI.rfb.get_mouse().set_scale(1); if (resizeMode === 'remote') { @@ -1240,8 +1250,12 @@ var UI; } else if (resizeMode === 'scale' || resizeMode === 'downscale') { var downscaleOnly = resizeMode === 'downscale'; - display.autoscale(screen.w, screen.h, downscaleOnly); - UI.fixScrollbars(); + var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly); + + if (!UI.rfb.get_view_only()) { + UI.rfb.get_mouse().set_scale(scaleRatio); + Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale()); + } } } }, @@ -1249,7 +1263,16 @@ var UI; // Gets the the size of the available viewport in the browser window screenSize: function() { var screen = document.getElementById('noVNC_screen'); - return {w: screen.offsetWidth, h: screen.offsetHeight}; + var width, height; + + screen.style.overflow = "hidden"; + + width = screen.offsetWidth; + height = screen.offsetHeight; + + screen.style.overflow = "auto"; + + return {w: width, h: height}; }, // Normally we only apply the current resize mode after a window resize @@ -1284,15 +1307,6 @@ var UI; var cur_clip = display.get_viewport(); var new_clip = UI.getSetting('clip'); - var resizeSetting = UI.getSetting('resize'); - if (resizeSetting === 'downscale' || resizeSetting === 'scale') { - // Disable clipping if we are scaling - new_clip = false; - } else if (Util.isTouchDevice) { - // Touch devices usually have shit scrollbars - new_clip = true; - } - if (cur_clip !== new_clip) { display.set_viewport(new_clip); } @@ -1303,23 +1317,47 @@ var UI; // When clipping is enabled, the screen is limited to // the size of the browser window. display.viewportChangeSize(size.w, size.h); - UI.fixScrollbars(); } - - // Changing the viewport may change the state of - // the dragging button - UI.updateViewDrag(); }, // Handle special cases where clipping is forced on/off or locked enableDisableViewClip: function() { var resizeSetting = UI.getSetting('resize'); - if (resizeSetting === 'downscale' || resizeSetting === 'scale') { + + if (UI.isSafari) { + // Safari auto-hides the scrollbars which makes them + // impossible to use in most cases + UI.setViewClip(true); + document.getElementById('noVNC_setting_clip').disabled = true; + } else if (resizeSetting === 'downscale' || resizeSetting === 'scale') { // Disable clipping if we are scaling + UI.forceSetting('clip', false); + UI.setViewClip(false); + document.getElementById('noVNC_setting_clip').disabled = true; + } else if (document.msFullscreenElement) { + // The browser is IE and we are in fullscreen mode. + // - We need to force clipping while in fullscreen since + // scrollbars doesn't work. + var msg = _("Forcing clipping mode since " + + "scrollbars aren't supported " + + "by IE in fullscreen"); + Util.Debug(msg); + UI.showStatus(msg); + UI.rememberedClipSetting = UI.getSetting('clip'); + UI.setViewClip(true); document.getElementById('noVNC_setting_clip').disabled = true; + } else if (document.body.msRequestFullscreen && + UI.rememberedClipSetting !== null) { + // Restore view clip to what it was before fullscreen on IE + UI.setViewClip(UI.rememberedClipSetting); + document.getElementById('noVNC_setting_clip').disabled = + UI.connected || Util.isTouchDevice; } else { document.getElementById('noVNC_setting_clip').disabled = UI.connected || Util.isTouchDevice; + if (Util.isTouchDevice) { + UI.setViewClip(true); + } } }, @@ -1660,19 +1698,7 @@ var UI; updateSessionSize: function(rfb, width, height) { UI.updateViewClip(); - UI.fixScrollbars(); - }, - - fixScrollbars: function() { - // This is a hack because Chrome screws up the calculation - // for when scrollbars are needed. So to fix it we temporarily - // toggle them off and on. - var screen = document.getElementById('noVNC_screen'); - screen.style.overflow = 'hidden'; - // Force Chrome to recalculate the layout by asking for - // an element's dimensions - screen.getBoundingClientRect(); - screen.style.overflow = null; + UI.updateViewDrag(); }, updateDesktopName: function(rfb, name) { diff --git a/core/websock.js b/core/websock.js index 51d9b6250ebc5d3a7632b994bb45cf0c00edd058..ce0a5ede6d0b5d787940d893b486bc8f9f8ae2a1 100644 --- a/core/websock.js +++ b/core/websock.js @@ -246,7 +246,7 @@ close: function () { if (this._websocket) { if ((this._websocket.readyState === WebSocket.OPEN) || - (this._websocket.readyState === WebSocket.CONNECTING)) { + (this._websocket.readyState === WebSocket.CONNECTING)) { Util.Info("Closing WebSocket connection"); this._websocket.close(); } diff --git a/vnc.html b/vnc.html index c6f0d25bd8800450f0847a3294ae4de63c98d15d..1f29657fcaf946e3e195f79a012771f4cac0f84b 100644 --- a/vnc.html +++ b/vnc.html @@ -54,7 +54,9 @@ <!-- Stylesheets --> <link rel="stylesheet" href="app/styles/base.css" /> - +<!-- added by luiza --> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> +<!-- end od added by luiza --> <!-- <script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>