I have an electron app, and would like to fire off an event every time the app is in focus. For example, if I have my electron app and chrome open, and I switch to chrome, then back to electron, I want that event to fire. Any ideas?
Thank you.
There is the focus event for this.
In your BrowserWindow you have to:
const {BrowserWindow} = require('electron')
let win = new BrowserWindow()
win.on('focus', () => {
//do something
})
REF: https://github.com/electron/electron/blob/master/docs/api/browser-window.md
Related
Hello Team I need to add this code to a puppeteer test to listen in the page that I'm working the messages that the page which is opened automatically
window.addEventListener('message', event => {
console.log(event
});
I Try to use this code https://github.com/puppeteer/puppeteer/blob/main/examples/custom-event.js but this is not suitable for me. Any idea?
Thanks
I'd like to listen for button press events on an xbox one controller, but seems that many solutions to this are experimental and under development. Most examples I've found showing how to receive input from a gamepad use a polling method to repeatedly check the gamepad for events, but for my application it is crucial that I can record the exact timing of the button press, and I don't want to miss button presses in between scanning the game pad.
I can use either Firefox or Chrome but I haven't gotten the following solutions to work in either browser yet:
Firefox: According to this page https://www.chromestatus.com/feature/5989275208253440#, "gamepad button and axis events are implemented in Firefox behind the flag dom.gamepad.non_standard_events.enabled". I have enabled this in Firefox but listening to state change events (as described at https://www.smashingmagazine.com/2015/11/gamepad-api-in-web-games/) still has no effect.
Chrome: This github page https://github.com/MozillaReality/gamepad-plus/blob/master/README.md looks like it can extend the Gamepad API so I can also listen for button press events in Chrome, but when I try to compile the JavaScript as a standalone module using npm run build I get the error node_modules_missing and the build fails.
I'd appreciate advice on how to enable .addEventListener('gamepadbuttondown'... to work in either of these browsers.
Thanks to a codepen example by Christopher Van Wiemeersch at https://codepen.io/cvan/pen/aOzgGE I have found a solution in Firefox.
First I opened a Firefox browser (version 73.0.1) and entered about:config in the URL. Then I toggled dom.gamepad.non_standard_events.enabled to true.
Then I used the following functions/listeners from Christopher's codepen:
var gamepadConnected = function (e) {
console.log('Gamepad connected at index %d: %s. %d buttons, %d axes.',
e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length);
};
var gamepadDisconnected = function (e) {
console.log('Gamepad removed at index %d: %s.', e.gamepad.index, e.gamepad.id);
};
var gamepadButtonDown = function (e) {
console.log('Gamepad button down at index %d: %s. Button: %d.',
e.gamepad.index, e.gamepad.id, e.button);
};
var gamepadButtonUp = function (e) {
console.log('Gamepad button up at index %d: %s. Button: %d.',
e.gamepad.index, e.gamepad.id, e.button);
};
window.addEventListener('gamepadconnected', gamepadConnected);
window.addEventListener('gamepaddisconnected', gamepadDisconnected);
window.addEventListener('gamepadbuttondown', gamepadButtonDown);
window.addEventListener('gamepadbuttonup', gamepadButtonUp);
Then when a button is pressed I record the timestamp using var timestamp = new Date().getTime().
I just found Framework7 and it looks promising as a base for mobile apps.
From navigation tabs I can load a Component Page which has dynamic data. But this data is only set when the application is loaded.
Wanted:
Every time user clicks on tab, load data and render page.
Question:
How can I make a component page load every time?
I have made an example from framework7-template-tabs. Check console showing when pageInit is called.
Live:
http://f7-navigate-component-question.surge.sh/
Code:
https://github.com/gotling/framework7-tab-component-page-question
If you want some action to happen every time a particular tab is clicked/loaded, you can use the show event of the tab, documented here.
For example, to alert something every time tab2 is loaded, you could do this
$$("#tab2" ).on( "show", function( event, ui ) {
myApp.alert("Tab loaded!");
} );
I got the answer in the Framework 7 forum.
Listen to page show events:
$('#view-catalog').on('tab:show', ...
Refresh the page:
$('#view-catalog').on('tab:show', function () {
catalogView.router.navigate(catalogView.router.currentRoute.url, {
reloadCurrent: true,
ignoreCache: true
});
});
If using Framework7 2.0.6 or newer that could have been simplified with:
$('#view-catalog').on('tab:show', function () {
viewCatalog.router.refreshPage();
});
I have an adobe desktop AIR app. When I send some data with a local connection, I want the app in front of all the other windows with focus on it.
I tested on a brand new air app with just this code:
import flash.display.NativeWindow;
var window:NativeWindow = stage.nativeWindow;
var aspa = setInterval (activateWin,8000);
function activateWin (){
trace("Activate window");
window.activate();
clearInterval(aspa);
}
And nothing happens. While if I write:
window.alwaysInFront=true;
window.alwaysInFront=false;
It brings the app to the front, but this command gives no focus to the window.
If I add
NativeApplication.nativeApplication.activate(stage.nativeWindow);
This makes the status bar icon blink, but still no focus or front action.
Reading this page, it seems it should work.
Am I missing something?
I've just use
window.activate();
window.alwaysInFront = true;
window.alwaysInFront = false;
and it's works fine on windows and mac os
I am using kinetic-v4.3.0-beta2.js
I want to handle mobile touch event on group for ios & android.
I am binding event such as following
group.on('touchstart', function (evt) {
$('#onpopMenu').popup("open", { x: leftPosition, y: topPosition });
});
I tried 'touchend', 'touchstart' and 'tap'
Got partial success in "Tap" but in that case, shape is draggable so tap event is not properly fire because object will move from it's place.
but if shape is not draggable then it will work fine.
I tried 'touchend' and 'touchstart' event also but popup menu is close after event fire in iOs and android as I am opening Jquery Mobile Popup by Touching group!
The popup menu will only open for 2-3 seconds when the touchstart event fired.
Anyone faced the same problem with kinetic JS Mobile events? How to handle only "Click" or "Touch" event with it.
I checked this http://www.html5canvastutorials.com/kineticjs/html5-canvas-mobile-events/ for reference but had no luck!
I am developing application with Phonegap + JQM + Kinetics JS
Thanks in advance!
Keep in mind that your application is running inside a webview. This is why you've got these 2/3 seconds of delay on touch/click event.
This is why in all my PhoneGap dev, I use Fastclick.js. FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
You can find it here https://github.com/ftlabs/fastclick.
It's easy to use (if you're using jQuery) :
<script type='application/javascript' src='/path/to/fastclick.js'></script>
<script>
$(function() {
FastClick.attach(document.body);
});
</script>
I made a jsfiddle for you to test out the click/touch events.
From what I understand, you have a Kinetic.Group node that is draggable but you want to open up a popup using jquery mobile.
You are right that when you drag an object, the tap event does not fire. But you said otherwise the tap event works fine if the shape is not draggable. This leads me to believe:
You want a popup on "tap"
You want a popup on "dragend"
If so, all you need is to use both events like this:
group.on('tap dragend', function (evt) {
$('#onpopMenu').popup("open", { x: leftPosition, y: topPosition });
});
Please let me know if my assumptions are wrong, and I can work with you to get the right solution. I am guessing when you want to popup, so if you let me know exactly when you want a popup to occur that will help a lot.
You might want to also look into using evt.cancelBubble = true; http://www.html5canvastutorials.com/kineticjs/html5-canvas-cancel-event-bubble-propagation-with-kineticjs/