How to remove UWP (Cordova) title bar arrow? - javascript

I have a Cordova application running on Windows 10 (UWP) and I am using Visual Studio 2017 to build the Cordova project.
The hosted window has an arrow in the title bar that I am trying to remove.
Here is a picture of what I am talking about:
I saw another question on StackOverflow that had an accepted answer to use the following code:
if (cordova.platformId == "windows")
{
var currentView = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
currentView.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
}
However, this does not work for me.
I perform the check after DeviceReady and the cordova.platformId does indeed equal "windows" which is fine.
How does the JavaScript code execute the Windows.UI.Core.SystemNavigationManger namespace? I understand it is a UWP namespace as per the following link,
Windows.UI.Core.SystemNavigationManger, but where is this defined and accessible by the JavaScript code? Is there a 3rd party Cordova plugin I am missing?

I had the same problem. I was able to fix it by putting the following code in the render of my first component:
if (window.cordova && window.cordova.platformId === "windows")
{
console.log("Disabling back button")
var currentView = window.Windows.UI.Core.SystemNavigationManager.getForCurrentView();
currentView.appViewBackButtonVisibility = window.Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
}

Related

How to make page search on electron like in Chrome or VS Code or Firefox? [duplicate]

Does the Electron application framework have built-in text search?
The quick-start application doesn't provide any apparent search functionality (e.g. using Ctrl-F or from the menu options). I would have expected this to be a BrowserWindow option (or an option of its WebContents), but I don't see anything helpful in the docs.
I know this is an old thread, but might still be relevant for people out there.
Had the same problem, and first fixed by using electron-in-page-search, but this component doesn't work properly with Electron 2 or greater.
Then finally found electron-find resolved my problem. Using with Electron 4.
You just add the component to your project:
npm install electron-find --save
Add a global shortcut in your Electron main process to send an event to the renderer in a ctrl+f:
globalShortcut.register('CommandOrControl+F', () => {
window.webContents.send('on-find');
});
And then you can add this to your page (the renderer process)
const remote = require('electron').remote;
const FindInPage = require('electron-find').FindInPage;
let findInPage = new FindInPage(remote.getCurrentWebContents());
ipcRenderer.on('on-find', (e, args) => {
findInPage.openFindWindow()
})
Hope that helps.
Try webContents.findInPage just added in the latest version.
There is an issue with the solution Robson Hermes offered. globalShortcut is, by definition, global, so the shortcut will be detected even when the app is not focused. This will result in the Ctrl+F shortcut being "stolen" from everywhere else.
I have found no ideal solution (see this issue on the electron repository), but a hacky one can be achieved by doing what Robson said and adding
win.on('focus', () => {
globalShortcut.register('CommandOrControl+F', () => windows.main.send('on-find'))
})
win.on('blur', () => {
globalShortcut.unregister('CommandOrControl+F')
}
Note that as seen here, this is not ideal and can lead to several issues:
Other applications can get a lock on the shortcut when you lose focus, i.e. the shortcut will magically stop working when you switch back to the app later.
Some apps can appear on screen without taking focus (spotlight I believe has this behavior) and during the app's appearance the shortcuts will still be captured by your application.
There's also gonna be those weird one in a thousand situations where somehow you switch focus and the shortcut is not removed.
Instead of using global shortcuts , use Accelerators ( normal Keyboard shortcut )
{
label : 'help',
click : function(){.
electron.shell.openExternal('http://....').
},
accelerator : 'CmdOrCtrl+ Shift + H'
}
The above shown is just an example of How to use accelerator

Vaadin 8 Html Imports Javascript

I am trying to use Vaadin 8 's "Html Import" feature
i followed instructions here : What's New In Vaadin 8
you can check it at 10th feature.
i am also sure that i installed both polymer-cli and bower.As GameCard creator mantioned at his own github.
But when run the application "the cards" are loading but not the way as it should.Mines have no flipping animation and kind a looks bad.
Screenshot :
Update After Gerald's Solution.
Finally Works with the Right Version of Polymer.
Seems to be a problem with the game-card element and the latest version of Polymer. I opened an issue on GitHub. Try with the version I used when I developed the demo. Find it here. Just replace your bower_components directory with the one in my demo.
initialize rank and symbol in different order (set rank first):
GameCard = function () {
var element = this.getElement();
this.setCard = function (symbol, rank) {
element.set("rank", rank);
element.set("symbol", symbol);
};
};

Electron does not listen keydown event

I am a backend developer who got a little project to fix it.
So my boss gives me an electron project which runs on touch devices.
I know that I can listen any key events in Javascript if I use the document object, but in electron it does not work, it says the docuemnt cannot be found.
So implemented this when I or other support guy press the F12 button then the dev tools be rendered out in the electron app.
mainWindow = new BrowserWindow({
'web-preferences': {'web-security': false}
});
mainWindow.onkeydown = function (e) {
console.log("Key down");
if (e.which === 123) {
console.log("Key is F12");
mainWindow.webContents.openDevTools();
}
};
But this code is not working to me. I have no idea how I can listen the F12 button is pressed.
Unfortunately I cannot render out button to the UI which can show the devtools. Because of the customers mustn't press it.
Sometimes I need to see the realtime console tab in devtools on the device.
There is a known issue in Electron ( which has lately been marked as wontfix ) that prevents the usual approach to catch key events using the traditional JS approach.
There also is a small library called electron-localshortcut that circumvents this issue by hijacking the Electron global shortcuts API when the window is active.
Use like this in your main.js:
const electronLocalshortcut = require('electron-localshortcut');
electronLocalshortcut.register(mainWindow, 'F12', () => {
// Open DevTools
});
Without additional libraries you can use "globalShortcut" of electron
const { app, BrowserWindow, globalShortcut } = require("electron");
globalShortcut.register("CmdOrCtrl+F12", () => {
mainWindow.isFocused() && mainWindow.webContents.toggleDevTools();
});
I think F12 is preserved so I use ctrl+f12 which is not far off
You can use the library mousetrap to add global short cut, because it can be installed through node and could bypass the problem of electron mentioned in the accepted answer.
A code example in the render process would be:
var Mousetrap = require('mousetrap');
Mousetrap.bind('4', function() { console.log('4'); });

notification.confirm callback not firing phonegap iOS

I'm using Phonegap (Cordova) v1.9, and this app is solely for iPhone4+ use.
I've tried the two methods below, on their own and simultaneously.
Phonegap's deviceready event has been fired previous to this code.
I'm using the iPhone configuration utility to watch the console, but I'm not getting anything from the code below.
Also, I'm using Sencha Touch (v1.1) and jQuery. No conflicts noticed throughout the app.
Please help?
function onConfirmCallback(button){
console.log("onConfirmCallback");
console.log(button);
}
var toConfirm = navigator.notification.confirm("You don't have a pincode set.\nWould you like to set one now?", onConfirmCallback, "Pincode", "Yes,No");
toConfirm.onAlertDismissed = function(index, label){
console.log("onAlertDismissed");
console.log(index);
}
Have you tried looking for exceptions to see what might be happening?
try
{
var toConfirm = navigator.notification.confirm("You don't have a pincode set.\nWould you like to set one now?", onConfirmCallback, "Pincode", "Yes,No");
toConfirm.onAlertDismissed = function(index, label) {
console.log("onAlertDismissed");
console.log(index);
}
}
catch (ex)
{
console.log(ex.message);
}
Edit:
The example mentioned in the comment below (from https://groups.google.com/group/phonegap/browse_thread/thread/126f56f4e296e555) is for PhoneGap 0.9.2. I have not seen any examples for v1.3 where the confirm function returns an object as your using with 'toConfirm'. Maybe that is causing your problem. Have you tried the following (removing all other code to do with toConfirm to simplify the problem)?
navigator.notification.confirm("You don't have a pincode set.\nWould you like to set one now?", onConfirmCallback, "Pincode", "Yes,No");
http://docs.phonegap.com/en/1.3.0/phonegap_notification_notification.md.html#notification.confirm
Also, is there any reason your not using a newer version of PhoneGap (Cordova)?

OSX Dashboard widget command line access problem

I'm trying to access command line from a simple Dashboard Widget on Snow Leopard. My intention is to fill the contents of the widget from a command-line script I call. This should be possible.
I'm calling the script every time the widget is shown using it's onshow callback:
if (window.widget) {
widget.onshow = onshow;
}
function onshow() {
document.getElementById("mydynamicarea").innerHTML = widget.system("/usr/bin/id -un", null).outputString;
}
Above I'm trying to use just a simple command showing my username to test the command-line access. This doesn't work, the widget shows just the static text which I have on the HTML:
<div id="mydynamicarea">No data available</div>
The same Javascript works if I use a static string instead of the widget.system call:
if (window.widget) {
widget.onshow = onshow;
}
function onshow() {
document.getElementById("mydynamicarea").innerHTML = "This text is actually shown on widget";
}
When I look at the Console, I can see this error-message:
TypeError: Result of expression 'widget.system' [undefined] is not a function.
I have configured the command-line access in info.plist:
<key>AllowSystem</key>
<true/>
Any idea what I'm doing wrong?
killall DashboardClient
helped for me
There seems to be some bug in Dashboard. I managed to make the Widget work by renaming it. The widget worked just fine in Dashcode before renaming (thanks, Till Theis) and when I installed it from there with another name it worked. That inspired me to just trying to rename it and that worked as well.

Categories

Resources