how does a browser will pick the client Locale value.? - browser

How a browser will get the client machine locale value. I am curious about internal process of how an browser picks up the Operating System locale value of the client machine. (i.e for the Browser/any app that is running on the client OS, which variable value does these apps/browser will fetch and send as the request header info?)

Fascinating question.
Firefox has shown how it gets this according to different Operating Systems here : https://dxr.mozilla.org/mozilla-esr45/source/intl/locale/nsLocaleService.cpp?q=nslocaleservice&redirect_type=direct#69
From that I have created a list for you
Windos XP : GetSystemDefaultLCID()
If QT library is available QLocale::system().name().toUtf8()
Fallback is C++ getenv("LANG") very raw
Mac uses this CFLocaleRef cflocale = CFLocaleCopyCurrent(); see here for more info How to get the locale of the current user in OSX using C++
Also, Androids Chromium browser which was built in c++ makes a call to Java.LocaleUtils which uses Java's Locale.getDefault()
std::string GetDefaultLocaleString() {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jstring> locale =
Java_LocaleUtils_getDefaultLocaleString(env);
return ConvertJavaStringToUTF8(locale);
}
https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#getDefault()

Related

How to get the VNC connection status?

I have been looking to find a way for my Qt application to know if a VNC connection is active.
How/can I get a VNC connection status?
This is an embedded Linux application.
A starting point would be to look into the Qt sources at src/plugins/gfxdrivers/vnc/qscreenvnc_p.h; there a class QVNCServer is declared that also defines a isConnected() method which appears to do exactly what you need.
The crucial point, however, is to access that method from your application code; as can be deducted from the filename suffix _p the classes in that header are private (read: internal) to the Qt libs and not part of the public interface. Accordingly they are not documented in the reference, and I haven't found a public method to get the current QVNCServer object, nor any other VNC related instance that could provide a pointer to that object.
My suggestion is that you start with the related public interface in src/plugins/gfxdrivers/vnc/qscreenvnc_qws.h, which incorporates the server class as part of a QProxyScreen subclass, and work onwards from there to get an idea how the VNC server instance is created, and where the pointer to it is handled. You may be able to add a method to the QVNCScreen interface which allows you to get the connection state from your application. However you'll have to patch the Qt sources and rebuild the libraries.
Getting the QScreen object in application code is easy:
foreach(const QScreen* s, QScreen::instance()->subScreens())
{
if(s->classId() == QScreen::VNCClass)
//Here you can cast the screen instance and call a method on it
}

Electron Node.js node localstorage osx mkdir permission denied

I am working with Electron and Node.js. We have developed an application that works fine on windows and as a requirement had to package it for mac os. I packaged the application using electron-packager, the packaging process completes and package is generated. Double clicking it throws an error that permission denied for mkdir, as i am using node localstorage to maintain some settings on the user's local machine. somehow mac doesn't local storage to create folder in the root of the application. Any help in this matter will be great. Thanks
First off, is the code in question in the main process or in a renderer process? If it is the latter, you don't need to use 'node-localstorage', because you can use the renderer's native LocalStorage. If you are in the main process, then you need to provide your own storage strategy so using 'node-localstorage' is a viable option.
In any case, you need to carefully consider where to store the data; for starters, let's look at where Electron's renderer processes would store its LocalStorage data: this differs based on the OS, but you can get and set the paths using the app module -- the path in question is userData, which on OS X would default to ~/Library/Application Support/<App Name>. Electron uses that folder to persist cookies, caches, LocalStorage etc. so I would suggest using that folder as well. (Otherwise, refer to XDG defaults for good defaults)
What your example above was trying to do is store your 'errorLogDb' in the current working directory, which might depend on your OS, where your App is installed, how you executed it, etc.
Finally, it's a good idea to differentiate between your 'production' app and your app during development and testing, because you might not want to use the same storage folders for every environment. In any case, just writing to './errorLogDb' is likely to cause lots of headaches so I'd be thankful for the permission denied error.
this strategy worked for me:
const { LocalStorage } = require('node-localstorage');
let ls;
mb.on('ready', () => {
let prefsPath = mb.app.getPath('userData') + '/prefs';
ls = new LocalStorage(prefsPath);
loadPrefs();
});
mb.on('after-create-window', () => { /* ls... */ }
exports.togglePref = () => { /* ls... */ }

How to disable the debug remote port in node-webkit desktop app

I wan't to protect the code of my node-webkit desktop application packaged in an exe file.
The problem is not on the file directly but with the dedicated port for remote debugging.
Perhaps I haven't understood something but, on Windows, if I execute a "netstat -a -o" command, I see an open port associated to the application and if I open this port on my browser, I have a page with "Inspectable WebContents" and a link to the webkit application.
With this debug window, it's possible to access to all the sources of the app and I don't know how to disable this feature.
For now, I think there is no actual way to disable remote debugging in nw.js.
Even so, according to the wiki, remote debugging seems to only be executed through the command line switches. Therefore you can block the chromium command line switches (or only --remote-debugging-port) to prevent arbitrary remote debugging by user until nw.js supports disabling functionality of remote debugging.
For instance:
const gui = require('nw.gui');
const app = gui.App;
for (let element of app.fullArgv) {
// app.argv has only user's switches except for the chromium args
if (app.argv.indexOf(element) < 0) {
app.quit(1); // invalid args!
}
}
However, I am not quite sure the above code could protect your application code, because the nw.js is using Chromium internally. So that, the application code would be extracted in temporary folder on initialization. Whereas above solution isn't really protect your nw.js application. See more details: https://github.com/nwjs/nw.js/issues/269
Note: node-webkit has changed name to nw.js

BrowserStack TestSwarm only pulls Windows OS's

I've recently setup an instance of TestSwarm that interfaces with BrowserStack by using the testswarm-browserstack nodejs module (https://github.com/clarkbox/testswarm-browserstack). I was referred to use the nodejs module from a link on BrowserStack site that walked through connecting TestSwarm to BrowserStack. Everything seems to be working as expected except that non-Windows OS's don't kick off in my automated process.
I have a bunch of OS X browsers configured on TestSwarm that seem to be configured correctly, they just never get launched during the automated runs. I'm able to join the swarm manually with BrowserStack, where I manually pull up an OS X browser and browse to the join url on my TestSwarm instance and it will properly pick up the browser and start running tests against it. The testswarm-browserstack nodejs module just seems like its ignoring the OS X browsers when it requests browsers from BrowserStack.
According the the documentation the testswarm-browserstack nodejs module should be able to handle OS X browser request as it uses BrowserStack API version 2.0 (https://github.com/clarkbox/testswarm-browserstack/pull/33)
Here is a small sample of how I'm specifying OS X browser in my TestSwarm configuration file:
"OSX-10-6-FF-22-0": {
"browserFamily": "Firefox",
"browserMajor": "22",
"browserMinor": "0",
"osFamily": "Mac OS X",
"osMajor":"10",
"osMinor":"6"
},
"OSX-10-6-Safari-4": {
"browserFamily": "Safari",
"browserMajor": "4",
"browserMinor": "0",
"osFamily": "Mac OS X",
"osMajor":"10",
"osMinor":"6"
},
Any incite would be appreciated, thanks!
I checked the link and can see the configuration is bit different. It specifies to mention browser, version and os. ex:
'Safari|5|0': {
browser: 'safari',
version: '5.0',
os: 'mac'
}
So does BrowserStack expects. Check the api docs at https://github.com/browserstack/api. Do comment back if you have your own config translator.

Using ActiveX Com Components with nodejs. Is it possible

Is there a way to use any ActiveX com components with nodejs?
Actually, I would never need this but I'm running nodejs on Windows and trying to send ping requests without forking new processes (no such module exists for Windows).
As some Activex components exist for sending ping requests with raw sockets, maybe I can use them.
An example of how you can create a COM object from JavaScript is:
var rs = new ActiveXObject("ADODB.Recordset");
There is node-win32ole ( npm install win32ole ).
EDIT: win32ole is no longer actively maintained. You could try winax instead.
(updated)
You could try to use node-ffi to bind to Win32 and launch a COM/ActiveX component (CoCreateInstance) or access winsock/icmp directly. See https://github.com/rbranson/node-ffi
Or try to ping via WMI, e.g. "select * from win32_pingstatus where Address='...'". See https://npmjs.org/package/wmi
An ICMP ping module for Node.js now exists:
https://npmjs.org/package/net-ping
Years later:
node winax
node win32ole no longer works with up to date node.js versions

Resources