I'm developing a class library for windows 10 universal apps (mobile and desktop device families only). I need to invoke an event if the user has been idle(no touch, mouse move, key press etc) for x number of seconds. This method can be used to solves this problem on android. But I couldn't find a solution on windows UWP.
Is there an API available in UWP to achieve this?
You can detect global input with various events on the app's CoreWindow:
Touch and mouse input with CoreWindow.PointerPressed, PointerMoved, and PointerReleased.
Keyboard input: KeyUp and KeyDown (the soft keys) and CharacterReceived (for characters generated via chords & text suggestions)
Use these to detect the user is active and idle out if it goes too long without any of these events.
I know this is really old question, but I think you can now get to same result with RegisterBackgroundTask
Just set:
new TimeTrigger(15, false) //For time trigger
Link
new SystemCondition(SystemConditionType.UserNotPresent)) //And so you want to know so user is not present
Link
Example usage in App.xaml.cs:
var builder = new BackgroundTaskBuilder();
builder.Name = "Is user Idle";
builder.SetTrigger(new TimeTrigger(2, false)); //two mins
builder.AddCondition(new SystemCondition(SystemConditionType.UserNotPresent));
// Do not set builder.TaskEntryPoint for in-process background tasks
// Here we register the task and work will start based on the time trigger.
BackgroundTaskRegistration task = builder.Register();
task.Completed += (sender, args) =>
{
//Handle user not present (Idle) here.
};
Related
I have a UI test which involves the dismissal of a system-generated UIAlertController. This alert asks the user for the permission to access the device's calendar. The objective of the test is the behaviour after a tap on the OK button:
1 let app = XCUIApplication()
...
// this code was basically generated by the recording feature of XCode 7
2 app.alerts.elementBoundByIndex(0).collectionViews.buttons["OK"].tap()
Now, instead of clicking the OK button, line 2 makes the simulator tap onto the first button which happens to be the Cancel button...
Additionally, I found out that the testing framework does not accurately recognize the appearing alert. So if I check the current count of alerts I always get 0:
// ...tap...
let count = app.alerts.count // == 0
This also happens if I use an NSPredicate for the condition and wait for several seconds.
Is it possible that UI tests do not work reliably with system-generated alerts? I am using XCode 7.0.1.
Xcode 7.1 has finally fixed the issue with system alerts. There are, however, two small gotchas.
First, you need to set up a "UI Interuption Handler" before presenting the alert. This is our way of telling the framework how to handle an alert when it appears.
Second, after presenting the alert you must interact with the interface. Simply tapping the app works just fine, but is required.
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}
app.buttons["Request Location"].tap()
app.tap() // need to interact with the app for the handler to fire
The "Location Dialog" is just a string to help the developer identify which handler was accessed, it is not specific to the type of alert. I believe that returning true from the handler marks it as "complete", which means it won't be called again.
I managed to dismiss access prompt for contacts like this:
let alert = app.alerts["\u{201c}******\u{201d} Would Like to Access Your Contacts"].collectionViews.buttons["OK"]
if alert.exists
{
alert.tap()
}
Replace asterisks with your app's name. It might work the same for calendar.
This is what I ended up using to get the prompt to appear and then allow access to Contacts:
func allowAccessToContacts(textFieldsName: String)
{
let app = XCUIApplication()
let textField = app.textFields[textFieldsName]
textField.tap()
textField.typeText("aaa")
let alert = app.alerts["\u{201c}******\u{201d} Would Like to Access Your Contacts"].collectionViews.buttons["OK"]
if alert.exists
{
alert.tap()
}
textField.typeText("\u{8}\u{8}\u{8}")
}
I have a below requirement in Windows Phone 8 to run voice listener in background agent whenever an incoming call comes or for an outgoing call. The voice listener should stop when there was NO call.
Eg: When I lift an incoming call and while speaking. I would like to say a voice command say "SPEAKER", then the speaker should ON
I saw obscured events can be used for detecting calls. But am unable to start the voice listener from background agent. Kindly please assist.
Here is the method I am using in the ScheduledAgent.cs file, but no luck
private async void SpeakTest()
{
SpeechRecognizerUI speechRecognition = new SpeechRecognizerUI();
SpeechRecognitionUIResult recoResult = await speechRecognition.RecognizeWithUIAsync();
if (recoResult.ResultStatus == SpeechRecognitionUIStatus.Succeeded)
{
lblMessage.Text = recoResult.RecognitionResult.Text;
}
}
First, You can not run a background task whenever you want. OS will decide when to run your task agent. It'll not run continuously. Rather it'll run in interval
Second, In windows phone 8 ( not elsewhere) the microphone is muted to external app.
Third, You shouldn't try to run SpeechRecognizerUI from background agent.
Is there event that will notify a sender app when the use selects "stop cast" from within the chrome extension?
I've a chrome sender app get's in a limbo state if the user chooses to stop the cast from the extension instead of the app cast button.
EDIT:
This is some relevant code:
CastPlayer.prototype.onMediaDiscovered = function (how, mediaSession) {
this.currentMediaSession = mediaSession;
// ...
this.currentMediaSession.addUpdateListener(this.onMediaStatusUpdate.bind(this));
// ...
};
CastPlayer.prototype.onMediaStatusUpdate = function (e) {
console.log(e);
};
Have you tried Session.addUpdateListener(listener) ? I think the listener will be notified when the session is no longer alive.
It seems Google developers are pretty aware of that! :D
They've just update their senders sample code with a commit that is exactly what seems you're looking for: Added session update listener to handle disconnect by clicking cast extension
There's also another commit with the same text in another sample but with less code, here you have: https://github.com/googlecast/CastHelloVideo-chrome/commit/776559c9aaf16d7d82c62ee4dea611b6177ac217
Gnome Shell has great shortcuts, however, I don't find a way to call them programmingly
Assume that I want to use a GJS script to start Google Chrome, move it to workspace 1, and maximize it, then start Emacs, move it to workspace 2, and maximize it.
This could be done using wm.keybindings: move-to-workspace-1, move-to-workspace-2 and maximize. However, how to call them programmingly?
I notice that in GJS, Meta.prefs_get_keybinding_action('move-to-workspace-1') will return the guint of action move-to-workspace-1, but I did not find any function to call the action.
In https://github.com/GNOME/mutter/blob/master/src/core/keybindings.c, I found a function meta_display_accelerator_activate, but I could not find a GJS binding for this function.
So, is there any way to call gnome shell shortcuts programmatically?
The best bet to move an application is to grab its Meta.Window object, which is created after it's started.
This would be done through getting the active workspace, starting the application, then getting the application from the active workspace and moving it.
Sample code for a quick implementation:
const workspace = global.screen.get_active_workspace();
const Gio = imports.gi.Gio;
//CLIname: Name used to open app from a terminal
//wsIndex: Workspace you want it on
function openApp(CLIname, wsIndex) {
let context = new Gio.AppLaunchContext;
//use 2 to indicate URI support
//0 is no flags, 1 for terminal window,
//No 3, 4 for notification support
//null because setting a name has no use
Gio.AppInfo.create_from_commandline(CLIname, null, 2).launch([], context);
//Unfortunately, there is no way I know to grab a specific window if you don't know the index.
for(let w of workspace.list_windows()) {
//check if the window title or window manager class match the CLIname. Haven't found any that don't match either yet.
if(w.title.toLowerCase().includes(CLIname.toLowerCase() || w.get_wm_class().toLowerCase.includes(CLIname.toLowerCase()) {
//Found a match? Move it!
w.change_workspace(global.screen.get_workspace_by_index(wsIndex));
}
{
}
/*init(), enable() and disable() aren't relevant here*/
To answer the actual question way at the end, it might be possible by forcing the GNOME on-screen keyboard to emit those keys, but that would require matching the right keys and I/O emulation for every keybinding you wish to execute, which can change whenever a user wants it to, from an extension.
In WinRT the Suspended event is supposed to be used to save application data. It is even written in the templates that come with Visual Studio. However when the user closes the app the Suspended event does not fire until 10 seconds later. If the user starts the application in the meantime the data is lost. How should I proceed in this case? I tried other events like page's NavigatedFrom but none of them fired.
You could try this:
Window.Current.Activated += (sender, args) =>
{
if (args.WindowActivationState ==
CoreWindowActivationState.Deactivated)
; //save data
};
If an user close the App he expects the App start from scratch next time. But if user left the App to do another things he expects to return back to the last action.
If you force your app to save state even when user close the app:
How could the user start the app from scratch in any time he wants?