Is it possible to have a NW.js application "not resizeable" but also allow fullscreen? - nwjs

I'm in a dilemma. I'm adapting an old thing I made for browsers a few years ago into a desktop application with NW.js. I can't make major changes to the code, so this means it's fixed-resolution (not vector-based). A Canvas 2D square of a fixed size.
In my package.json, I have therefore set its GUI window to not be resizeable, because if I make it resizeable, the user can resize the window and it looks ugly since the content remains a fixed square.
But with "resizable": false, which does prevent the user from resizing the window, it also prevents "fullscreen mode" from working! When I enter fullscreen mode, it does not cover the full screen, but only same size canvas in the top-left part of the screen. This is obviously because I've told it to not be resizeable. If I set "resizable": true, the fullscreen works perfectly, but of course the user is then able to resize the window when in non-fullscreen mode!
Is there some way around this? Can the "resizeability" be set dynamically on runtime? I looked for a long time for a solution before asking this.

You can handle this manually, here is an example, you'll obviously need to tweak it though.
<button id="enter">Enter Fullscreen</button>
<button id="leave">Leave Fullscreen</button>
<script>
const enterButton = document.getElementById('enter');
const leaveButton = document.getElementById('leave');
const win = nw.Window.get();
enterButton.addEventListener('click', function () {
win.setResizable(true);
win.enterFullscreen();
});
leaveButton.addEventListener('click', function () {
win.leaveFullscreen();
win.resizeTo(600, 600);
win.setResizable(false);
});
</script>

Related

White screen appears for a split second after splash screen

I have made an app with IBM mobileFirst 7.0 (I also use Ionic) and I notice that right after the splash screen and for half a second or so, a white screen appears. I searched the web and some people said that uncommenting
autoHideSplash: false,
in wlInitOptions and adding this code:
var app = angular.module('app.controllers', []);
//manually hide splash screen
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
setTimeout(function() {
WL.App.hideSplashScreen();
}, 100);
});
})
in my controller (I only have 1) would solve the issue. Yet nothing happens. (I also changed the timeout but nothing seems to change)
I want to seee my app right after the splash screen dissappears without the white screen. How can I do that?
UPDATE & SOLUTION:
After reading Idan's answer, I made a few changes that fixed the problem.
First of all in my index.html, I was loading MobileFirst at the end of my <head>, after Ionic and all controllers had loaded. I changed that and now in the <head> tag I firstly load:
<!-- mobileFirst initialization -->
<script src="js/wlInit.js"></script>
<script src="js/messages.js"></script>
and then I load Ionic and the controllers.
I also changed the timeout of WL.App.hideSplashScreen() in my controller from 100 to 1500.
No white screen appears any longer :D
I see you're using the WL.App API, but are you sure you're using it in the right place? This API can be called only after function wlCommonInit was called.
So I think you're on the right path. It sounds like you should indeed try to extend the duration of the splash screen as something in your app is taking a while to load (hence the white flashing), so by extending the splash screen a little while longer, letting whatever it is to load, and then removing the splash screen could be a possible workaround.
Make sure this API is called only after wlCommonInit was called
Increase the duration some more.
Read more about the API, here: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.0/advanced-client-side-development/common-ui-controls/#splashscreen
You can also use ng-cloak to hide any white flashes that angular causes.

open image instead of popup : leaflet

I am working with leaflet api.I can draw rectangles and polygons.I have bound the popup with every rectangle and polygon.When i click on drawn shape, popup opens(leaflet functionality).Popup contains some html(image).
As i am working on a demo application, i am wiling to try the fancebox plugin.
Means, when i click on drawn shape, instead of popup, i want to open up that image using fancybox.
Can i do that using simple method like using another function instead of .bindpopup.
Working Script (image loaded using fance box when we click on popup)
e.layer.bindPopup("<a class='fancybox' rel='group' href=''><img /></a>");
I can understand there must be some other javascript function to do it.
If there is some way to do it please let me know, as i am new to leaflet didn't have enough mental power to understand it yet but i hope i will....
Thanks for your time :)
I would just do e.layer.on('click', function() { //do fancybox init, perhaps like $(body).append("<a class='fancybox' rel='group' href=''><img /></a>")})
Although it makes a lot more performance sense to bind that event on the L.FeatureGroup holding all the shapes instead of one by one.

resize jPanel on VLCJ fullscreen for controlsPanel

I am using netbeans to create a media player using vlcj-3.8.0.jar.Here is the source code for netbeans users,vlcj gui netbeans based just unzip and open project in netbeans(contains playlist, volume, plays in canvas)I know placing the whole code violates the SSCCE standards but it might be informative for others. Another reason is that if you are a netbeans user then running the code and finding the problem is very easy for you, u wont need to search the entire code. So my problem, all works fine but i am having problem when i toggle the fullscreen. The controlsPanel as you can see in the picture below wont resize and i dont how how to do it. I tried to put the panel in border layout but it messes everything inside it(i have jslider and jlabels inside it).
http://postimg.org/image/kcxuwgjgx/
Here is a code to toggle on and off for fullscreen, where
jPanel2: is in border layout that has canvas inside it,
controlsPanel: panel in absolute layout that has jslider and jlabels has properties i set through netbeans as horizonal size and vertical size as default, horizontal resizable as ticked
private void toggle_fullscreenMouseClicked(java.awt.event.MouseEvent evt) {
if(fullscreen_check==1){
controlPanel.setVisible(true);
titlePanel.setVisible(false);
mediaPlayer.setFullScreen(true);
//at fullscreen the controlPanel should be resized horizontally to the end of the screen
controlPanel.setPreferredSize((new Dimension(1200,100)));
controlPanel.setSize((new Dimension(1200,100)));
controlPanel.revalidate();
//here is the problem:controlPanel stays the same...why??
fullscreen_check=0;
}
else{
mediaPlayer.setFullScreen(false);
Dimension ss = new Dimension (10,10);
jPanel2.setPreferredSize(ss);
jPanel2.setSize(ss);
jPanel2.revalidate();
fullscreen_check=1;
}
} `
I tried to use the code:
controlPanel.setPrefferedSize((new Dimension(1200,900);
controlPanel.revalidate();
//OR:
controlPanel.setSize((new Dimension(1200,900);
controlPanel.revalidate();
but it wont work...any help or idea will be greatly appreciated!! If any of you guys tried my code and make the controlsPanel to be resized to full screen, i will be very grateful!!

Addon SDK way to make a dialog

What is the proper way to use the SDK to make a dialog (which is not anchored to the add-on bar, etc. but shows centered on screen)? It doesn't seem like there is any API for this important capability. I do see windows/utils has open but I have two problems with that:
The dialog opening seems to require "chrome" privs to get it to be centered on the screen (and I'd be expectant of add-on reviewers complaining of chrome privs, and even if not, I'd like to try to stick to the SDK way).
While I can get the DOM window reference of the new window/utils' open() dialog, I'm not sure how to attach a content script so I can respond to user interaction in a way that prompts (and can respond to) privileged behavior ala postMessage or port.emit (without again, directly working with chrome privs).
Ok, this answer should have been pretty obvious for anyone with a little experience with the SDK. I realized I can just use a panel. In my defense, the name "panel" is not as clear as "dialog" in conjuring up this idea, and I am so used to using panels with widgets, that it hadn't occurred to me that I could use it independently!
Edit
Unfortunately, as per Bug 595040, these dialogs are not persistent, meaning if the panel loses focus, the "dialog" is gone... So panel looks like it is not a suitable candidate after all... :(
Edit 2
I've since moved on and have gotten things working mostly to my satisfaction with sdk/window/utils and openDialog on whose returned window I add a load listener and then call tabs.activeTab.on('ready', and then set tabs.activeTab.url to my add-on local HTML file so the ready event will get a tab to which I can attach a worker. There is still the problem with chrome privs I suppose, but at least the main communications are using SDK processes.
Update to Edit 2:
Code sample provided by request:
var data = require('sdk/self').data,
tabs = require('sdk/tabs');
var win = require('sdk/window/utils').openDialog({
// No "url" supplied here in this case as we add it below (in order to have a ready listener in place before load which can give us access to the tab worker)
// For more, see https://developer.mozilla.org/en-US/docs/Web/API/window.open#Position_and_size_features
features: Object.keys({
chrome: true, // Needed for centerscreen per docs
centerscreen: true, // Doesn't seem to be working for some reason (even though it does work when calling via XPCOM)
resizable: true,
scrollbars: true
}).join() + ',width=850,height=650',
name: "My window name"
// parent:
// args:
});
win.addEventListener('load', function () {
tabs.activeTab.on('ready', function (tab) {
var worker = tab.attach({
contentScriptFile: ....
// ...
});
// Use worker.port.on, worker.port.emit, etc...
});
tabs.activeTab.url = data.url('myHTMLFile.html');
});
if the panel loses focus, the "dialog" is gone...
It doesn't get destroyed, just hides, right? If so, depending on why it's getting hidden, you can just call show() on it again.
You'd want to make sure it's not being hidden for a good reason before calling show again. If there's a specific situation in which it's losing focus where you don't want it to, create a listener for that situation, then call if (!panel.isShown) panel.show();
For example, if it's losing focus because a user clicks outside the box, then that's probably the expected behaviour and nothing should be done. If it's losing focus when the browser/tab loses focus, just register a tab.on('activate', aboveFunction)
Simply adding ",screenX=0,screenY=0" (or any values, the zeroes seem to be meaningless) to the features screen seems to fix centerscreen.

Prevent iPhones webkit from opening a new browser window (and thus exiting fullscreen) when clicking an `rel="external"` link

Opening my mobile webpage from my homescreen (after adding it to my homescreen), it starts in fullscreen mode, so far so good.
After logging in (form/submitbutton), the 'app' is still in fullscreen mode, which is also the desired result.
Now, when I click a link that has the rel="external" attribute, webkit opens a new window in Safari, so it exits the fullscreen 'app' I started from my homscreen, I would like it to stay in fullscreen mode.
data-ajax="false" has te same result. Removing data-ajax="false" and rel="external" will not exit fullscreen, but this way you can't link to a multi-page document (1 document with different data-role="page").
Does anyone has the same problem, or even better, a solution?
I do not really care about the transitions, I just want the webpage to remain in fullscreen mode, (the user has to log in again when the new window has opened).
iPhone 3gs
M_webkit / 5.0.2
Why not create a script that pulls out the href and goes to the new url via javascript.
If you use jQuery it's as simple as:
$("a[rel='external']").bind("click",
function() {
if (this.href) {
location.href = this.href;
return false;
}
});
Without jquery you'll need to use object detection and attach a click event to it with the same logic inside the anonymous function above.