Chrome App Lifecycle - lifecycle

I'm reading through Chrome App Lifecycle. The model looks very simple. There's an onLaunch and onSuspend.
A few questions:
1) Is it possible to detect a transition from foreground to background?
2) Does Chrome persist any state automatically before moving to the background?
3) Does Chrome snap a capture of the app's window before moving to the background?
4) Does the same apply to Chrome Packaged Apps?

1) Yo'll only receive onSuspend event right before event page become inactive. If you want to know when the user close app's window you need to listen for page unload event in the app an inform event page about the fact (using chrome.runtime API).
2) If you set "id" parameter for chrome.app.window.create options object, Chrome will persist window state: width, height, top and left position and screen number and restore it during next app bootstrap. You can override this behavior setting your own values in chrome.app.window.create method.
3) As far as I know - no.
4) No. It is different kind of apps.

Related

Nativescript - resumeEvent handling

In my app when the app is resumed from a sleep, I'd like to
reload the page - or ideally, just update specific UI elements.
How can this be done?
Preferably in a platform independent way.
You want to hook into the onResume method in the application module which exposes the event when an app resumes from the background.
https://docs.nativescript.org/api-reference/modules/application.html#onresume
So in your app.js (the entry point of your application), import the module and add the onResume event handler and it can run everytime the app resumes. Now reloading a page will require a little more work. You'd have to use the frame module and find out the current page and do your work, but I'm guessing it can be done with a little effort using the approach mentioned.
UPDATE: based off your comment, you need the reloadPage() method from the ui/frame module. https://docs.nativescript.org/api-reference/modules/_ui_frame_.html#reloadpage
The correct method is reloadPage() in the Frame module (as contributed by #Brad) but the problem is that it's NOT an exposed api.
No problem - just copy/paste it and it works.
The problem is that it basically does a navigateTo() to the currentPage and that effects the navigation history. You have 2 choices - setting clearHistory to true and you lose all history (don't want that) or set clearHistory to false which creates a a duplicate of the current-page (don't want that either). There's also a backstackVisible option but that doesn't help in this scenario.
#Brad tells me that there's api that allows access to the navigation stack - haven't looked into it.
For my app - the user will be at the root page most of the time, so I decided to reload the page only if on the root page and then set clearHistory to true and that works for me.

Addind and removing UI elements in restartless TB addon

I develop a restartless addon for Thunderbird. I need to add some UI elements in compose window when the addon is activated.
What I did so far is:
at startup, add an observer on windows via nsIWindowWatcher
at shutdown, remove window observer, and set a variable X to true
when this observer observes domwindowopened event, add a eventlistener to the opened window for "compose-window-init" event (when it observes domwindowclosed, it removes the eventlistener)
when this compose-window-init event is fired, check the document.location of the window, if it corresponds to a message composer:
add the UI elements,
or remove UI elements and remove eventListener, if X is set to true
This works well (UI is added to compose message when addon is activated, and removed when deactivated) except the following : when addon is deactivated then activated again, the first compose message is not provided with the UI elements. The UI is added to the other one, but not to the first.
Any idea on why and how to solve this ?
Thx
I found what was wrong.
See my post at:
http://forums.mozillazine.org/viewtopic.php?f=19&t=2949755&p=14254205#p14254205
Regards

How to intercept events from specific windows in OSX

I want to have the following workflow:
User presses hotkey, or status bar menu button
User clicks on a window
Window is now "registered" in my app
App intercepts mouse events from all registered windows
I've read a lot on CGEvents, CGEventTaps and NSEvents. I can intercept global events and post new ones using CGEvents and CGEventTaps but there is not window information like windowNumber in NSEvent, only PSD (and I'm not sure how to use those), so I can't filter out events from non-registered windows. NSEvent, on the other hand, doesn't let me to intercept global events, only local ones through a localMonitor.
How could I achieve the desired functionality?
You can use the Mac OS X Accessibility API to get details about the currently focused window or application.
The UIElementInspector Apple Sample Code gives many examples.
// Given a uiElement and its attribute, return the value of an accessibility object's attribute.
+ (id)valueOfAttribute:(NSString *)attribute ofUIElement:(AXUIElementRef)element;
Use the kAXFocusedApplicationAttribute or kAXFocusedWindowAttribute attributes with valueOfAttribute:ofUIElement: to get the window/app when you "register" it with your app.
When a CGEvent comes in, compare the currently focused window/app to your list of registered windows/apps to determine if the event should be intercepted.

Adding alarm from BackgroundAgent (not working, looking for workarounds) - Windows Phone 8

I am developing an application which needs to notify the user at a pre-difined time with the help of background agent,
So I tried to add an Alarm, but according to MSDN's "Unsupported APIs for Background Agents for Windows Phone" all the methods regarding Microsoft.Phone.Scheduler (Add, Remove, Replace) are not supported (when ever i try to call Add method from background agent it gives error "BNS Error: The API can only be called from foreground app".). I tried to add the alarm when in foreground and then play with the "BeginTime" property and use the Replace method from the my scheduledTask (specifically, PeriodicTask which runs its code every 30 minutes) but to no avail, it did nothing.
What is important for me is to notify the user (with longer-enough sound) at the date and time that decided in the background-agent's Invoke method (My class derives from ScheduledTaskAgent and override the Invoke method), So I'm looking for workarounds. If there would be a toast that appears at a pre-defined time that would be ok somehow. Or maybe a toast that stays for a longer time on the top of the screen (from the moment the scheduled-task came up with an instance of DateTime until[and even after] the time that specifiend in this DateTime instance).
Please confirm, is it only the background agent that can calculate the correct time for the alarm to go off?
Assuming this is so, you can notify the user by sending a toast (which will also vibrate the phone, unless user has disabled that) and updating a tile pinned to the home page. These are both permitted APIs. So the toast message could tell the user to go look at the tile, which could have specific details about the alarm. The tile state will persist until you change it. If your foreground app would pin the tile for the user, that's a start. If you can then get the user to move the tile to the top of the screen, so it's always visible, you should be all set.
Considering that the alarm time might happen when the user is not actively using the phone, perhaps you want to do the toast plus a notification on the lock screen (as well as updating the tile)? That will provide another visual indication, though, again, it depends on the user configuring a lock screen.

How to schedule notification to user on specified time

In my app I need to schedule notification to user on specified date and time (for example 1st May at 10:00). At this moment notification must be shown and when user clicks on this notification, my app should be open. I see two ways to do it:
1. Scheduled notifications. But if I use the Alarm class, I can not change the title of the notification (which is "Alarm" in English version of SDK).
Reminder class mostly suits me, but when it appears atop the lock screen and user clicks it, my app doesn't open. May be is there a way around these moments? Also I would like to get rid of listpicker with time (5 min, 10 min, 1 hour, etc.) and the "snooze" button, but it's not critical.
2. Toast (or tile) notifications from background agent. But I'm not sure that my background agent runs at the right time. As I understand the background agents runs by the system, and their launch is limited by several factors (phone battery charge, the presence of the running applications or other background agents). It may not even start. There is a way to force the agent at a specific time by using the LaunchForTest, but everywhere write that this method can be used only for debugging purposes, and before the publication of the application it must be removed.
If I do not delete this method, will my application be certified? Also I don't like that the toast notification is only opens for 10 seconds and then disappears without a trace. Something can be done about it?
I need to notification was guaranteed shown at the right time, and when you click on it my application was open. What is the best way to do this?
If this is not possible in Windows Phone 7, is there a way to do this in Windows Phone 8?
Thanks.
I think you should use the Reminders for this. When you click them your application will open.
Something like:
var reminder = ScheduledActionService.Find("MyAppReminder");
if (reminder != null)
{
ScheduledActionService.Remove("MyAppReminder");
}
reminder = new Reminder("MyAppReminder")
{
Title = "Bla",
BeginTime = DateTime.Now.AddDays(2),
Content = message,
NavigationUri = new Uri("/Start.xaml", UriKind.Relative),
RecurrenceType = RecurrenceInterval.None
};
ScheduledActionService.Add(reminder);
As for the application not opening when the notification appears on the lock screen, it makes sense. Would be a big security hole if you could open apps directly from the lock screen! Hope it helps.

Resources