Is there a event listener for when the Electron startDrag ends? - macos

I am trying to make a file drag and drop app with Electron and I need to know if the file being dragged has been successfully dragged onto the user's desktop or if the drag and drop has been cancelled.
I tried using the GlobalEventHandlers.ondragend event listener, but it seems to be cancelled by e.preventDefault() needed for the startDrag function :
const dropAreaRef = document.body;
dropAreaRef.addEventListener("dragstart", handleExport, false);
dropAreaRef.addEventListener("dragend", handleExportEnd, false);
function handleExport(e) {
e.preventDefault();
window.electron.startDrag(files);
}
function handleExportEnd(e) {
console.log("export ended")
}
I have looked into the Electron.WebContents documentation, but cannot find any mention of a startDrag callback function or any electron Instance Events.

Related

How to handle Xamarin Camera Button Click Event

Right now I am creating a Xamarin application and I am using the camera to login. The application is working fine as below:
var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { });
The above method uses the Camera API and builds the Camera frame and Button as below:
I wanted to fire click event of the camera just after 10 seconds automatically. Kindly let me know the Event Name, which will be fired, and how will it fire?
Thanks
There is no such event in MediaPlugin.
There are 2 solutions how to approach your requirements.
The first one is to run the delay whether the photo is taken or not.
var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { });
await Task.Delay(10000);
if(photo != null)
{
//photo was taken
}
else
{
//camera was canceled
}
More cleaner solution is to use timer and once timer expires you can execute your code.
The second one is more harder to implement. You need to write platform specific code for Android and for iOS.
It means in YourProjectName.Android project you have to implement broadcastreceiver to listen camera button click.
The same for YourProjectName.iOS.
Here's a link!

Get Kendo Window in the drag event

I'm binding to the drag event of my windows.
$("##Model.Name").data("kendoWindow").dragging._draggable.bind("drag", function (e) {
var wnd = $("##Model.Name").data("kendoWindow");
Now, I'd like to write one function and bind all of the windows to that function, so I cannot hard-code the window's id. How can I get the sender window in that function?
I've tried the followings:
$(e.target).closest('.k-window').data('kendoWindow')
$(e.currentTarget).closest('.k-window').data('kendoWindow')
$(e.sender).closest('.k-window').data('kendoWindow')
all of them return null.
You want .k-window-content
$('.k-window-content').each(function(){
$(this).data("kendoWindow")...
});
Edit, OP wanted to use the dragging._draggable.bind method:
$("#id").data("kendoWindow").dragging._draggable.bind("drag", function (e) {
e.currentTarget.parent().find(".k-window-content").data("kendoWindow")...
});

Firefox extension development: load event only once

I'm developing a kind of kiosk system for firefox. Therefore I need to listen to the load event, everytime a link is clicked and a new page / document is loaded. I used this in the js file to accomplish that:
window.addEventListener('load', function () {
gBrowser.addEventListener('DOMContentLoaded', function () {
alert("load");
}, false);
}, false);
But the event is only fired if i open the new browser window but not on reload or loading another content.
What could I do?
You should probably use nsIWindowWatcher service to do this:
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
function windowObserver(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
// Do stuff here
}
}
// To start watching windows do this
Services.ww.registerNotification(windowObserver);
// To stop watching windows do this
Services.ww.unregisterNotification(windowObserver);

Add eventlistener to a window in Titanium Mobile commonJS

I have a surely somehow stupid problem with adding an eventlistener to a window I create in a commonJS module in Titanium Mobile.
Consider i.e. the following code:
var SegmentListWindow = function(){
var window = S.ui.createWindow("Testwindow");
window.addEventListener("app:customListener", function(){ doSomething();});
return window;
}
exports.SegmentListWindow = SegmentListWindow;
The window is nicely generated using
var Window = require(".....").SegmentListWindow;
var win = new Window();
S.ui is just a simple helper method to create some standard window in my app.
But the event listener is never called, I tryTi.App.fireEvent("app:customListener"), but the event doesn't reach the listener.
Only when Using Ti.App.addEventListener and adding a global eventlistener it's working.
I think maybe that problem is I am not adding the event listener to the "instance" of the window? But how to fix this? I don't want to add the event listener manually when instantiating the window somewhere in the app. Can't I do this in the commonJS module?
Well, that really was a simple question.
I am doing a Ti.App.fireEvent, but was listening for window.addEventListener, that couldn't work.
Now I am doing the following:
Adding an eventlistener on window instantiation to the global Ti.App-Object, and remove this listener on the window's close event.
That works perfectly.
You could also define the SegmentListWindow as you did in the question:
var SegmentListWindow = function(){
var window = Ti.UI.createWindow({title:"Testwindow"});
window.addEventListener("win:customListener", function(){ doSomething();});
return window;
}
exports.SegmentListWindow = SegmentListWindow;
and then fire the event on the win object:
var Window = require(".....").SegmentListWindow;
var win = new Window();
win.fireEvent('win:customListener');

Disable click event after touch and hold

I am developing an app iOS app in appcelerator and I got a table with user.
When I click on the user it opens the profile but I also want the user to be able to copy the name just by tap and hold for 2 seconds.
These two event works fine separately but right now after tap and hold the click event fires to. How can I prevent the click event from firing after tap hold?
// Set the timeout
var holdTime = 500, timeout;
// Create the table touch start event listener
table.addEventListener('touchstart', function(e) {
// Set the selected user id
var itemValue = e.row.value_full;
// Define the function
timeout = setTimeout(function(e) {
// Create the fade out animation
var fadeOut = Titanium.UI.createAnimation({
curve: Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
opacity: 0,
duration: 1000
});
// Create the loading screen
var copied = UI_messages.showFlash({label : 'Copied!'});
// Add the loading screen
win.add(copied);
// Save value to clipboard
Titanium.UI.Clipboard.setText(itemValue);
// Fade the message out
copied.animate(fadeOut);
}, holdTime);
});
// Create the event listener for touch move
table.addEventListener('touchmove', function() {
// Clear the timeout
clearTimeout(timeout);
});
// Create the event listener for touch move
table.addEventListener('touchend', function(e) {
// Clear the timeout
clearTimeout(timeout);
});
I've run into this problem before as well. The solution I used isn't very pretty, but it's the only effective way that I've found to suppress a touch event after a touch-and-hold.
The only working solution that I could find was to create a bool variable in a global namespace. In your setTimeout function, change the value of the bool to true to indicate that a touch-and-hold has occurred.
In the onClick event event for the row, check the global variable first to see if you've already created a touch-and-hold event - if you have, just return from the onClick event. This will effectively disable your click event when a touch-and-hold occurs.
Remember to set the global variable to false after the touch-and-hold function ends.

Resources