Soft "Restart" Windows 8 App - windows-8

I'm going to preface this by saying that I understand the new Windows 8 application lifecycle and how it is now 100% up to the user to decide if they want to terminate the app or not. So, I guess what I'm looking to find is a way to pseudo-restart my app, although I'm open to other suggestions as I'm pretty new to designing Modern UI apps.
I'm building an app that interfaces with a Web 2.0 service that requires authentication via OAuth. Fortunately the Windows 8 WebAuthenticationBroker makes this simple: it displays an asynchronous modal window that houses the web frame to allow the user to sign in and I get to provide a callback method when its done.
Now, obviously I only want to display this sign-in screen if I don't already have a session key stored for the user in roamingSettings.values. I used the Grid App template in Visual Studio, and I execute these functions in default.js as soon as the app is activated (checking roamingStorage, calling WebAuthBroker, etc). Now, the Grid App template provides a data.js to allow me to define some of the REST endpoints that I want to fetch. The main problem is that I can't fetch these REST endpoints until the user is authenticated! Yet they still have to (at least, I think) be declared in data.js ahead of time. So what I'm doing now to avoid errors in the event that the user isn't signed in, is the following:
if (roamingSettings.values[sessionKey]){
list = getFeedItems(); // my function that issues all the REST calls
} else {
list = new WinJS.Binding.List();
}
This works fine if the app is manually restarted after authentication is complete, but I would really rather have a way of completely reloading the app asynchronously after authentication is complete. I've spent a ton of time on this already and I'm getting extremely annoyed because I've seen other apps do this (Instametrogram, for example).
Any ideas?

To answer the core question here, how do you soft restart: window.location.reload() is all you need. This just does the refresh in place.
However, what you are actually looking to do is reset the datasource on the ListView instance -- all you need to do is get hold of that control at runtime, and re-assign the data source to it. E.g.:
var lv = document.getElementById("myListView");
lv.winControl.itemSource = list;
An example of this should also be in the app you have from when it currently assigns the list to the listview.

Related

Is it a best practice to make setInterval every some seconds to re update axios request to update displayed data in vue project? [duplicate]

hi
I want to build a control panel for a web art application that needs to run in fullscreen, so all this panel, that controls stuff like colors and speed values, have to be located at a different window.
My idea is to have a database storing all these values and when I make a change in the control panel window the corresponding variable in the application window gets updated too. So, it's basically a real-time update that I could do with AJAX setting a interval to keep checking for changes BUT my problem is: I can't wait 30 seconds or so for the update to happen and I guess a every-1-second AJAX request would be impossible.
Final question: is there a way to create a sort of a listener to changes in the database and fire the update event in the main application only immediately after I change some value in the control panel? Does Angular or another framework have this capability?
(Sorry for the long explanation, but I hope my question is clearer by offering the context [: )
A web socket powered application would have this benefit. This carries a bit more complexity on the back end, but has the benefit of making your application as close to real-time as can be reasonably expected.
The Mozilla Development Network has some good documentation on websockets.
On the front end, the WebSocket object should work for you on most modern browsers.
I'm not sure what your back end is written in, but Socket.IO for Node.js and Tornado for Python will make your applications web-socket capable
If one window is opening the other windows via JavaScript, you can keep the reference to the opened window and use otherWindow.postMessage to pass messages across
"Parent" window looks like
// set up to receive messages
window.addEventListener('message', function (e) {
if (e.origin !== 'http://my.url')
return; // ignore unknown source
console.log(e.message);
});
// set up to send messages
var otherWindow = window.open('/foo', '_blank');
otherWindow.postMessage('hello world', 'http://my.url');
"Child" windows look similar
// same setup to recieve
// ...
// set up to send
var otherWindow = window.opener;
// ... same as before
For the realtime I would recommend using a library like socket.io or using a database like firebase.
For the fullscreen I would recommend using a library like angular-screenfull
i use https://pushjs.io/, had exactly the same problem and this is a really simple solution for your problem. It is capable of sending and listening to events without any database interference.

How to auto-refresh a screen in Moqui?

Use case is a regularly updated display of vehicle tracking data retrieved through a REST call, onto a central office screen, with no user interaction.
There is no single answer for this, but some alternatives to consider:
add some JavaScript to your screen that uses the JS setTimeout() method or something similar to reload the page
for a smoother result but a lot more effort write the section of the screen that needs to auto-update as a Vue component and use the standard websocket interface to send data to the browser to update the data in the HTML; this is generally best done using the NotificationMessage interfaces and methods in the Moqui API where the JavaScript client registers on a topic and gets a notification along with any others registered (structure the topic ID as needed to differentiate different feeds) and have a scheduled service job feed the notification topic

Azure Mobile App - Strange API result only on .NET

Edit:
As of 3/21/2017, even after upgrading from Azure client SDK version 2 to 3.0.1, this is still a problem. So... bump.
I have an Azure Mobile App with custom authentication. I am developing a client for iOS and a client for Windows (VB.NET WinForms).
On iOS, everything works just fine. Registration and Login work, and also a standard API call.
On WinForms, all of the pieces works fine, just not exactly when and how I want (i.e., not all of the time).
Registration works.
Login works.
Standard API call works.
What doesn't work is the standard API call after a Login event.
I have put a console.log() line in my API code, and in all cases, it gets to the line just before the res.json() finishing call.
Here's how I am assigning my user to the client in iOS:
NSString *token = dict[#"token"];
NSString *userId = dict[#"userId"];
MSUser *user = [[MSUser alloc] initWithUserId:userId];
[user setMobileServiceAuthenticationToken:token];
client.currentUser = user;
Here's how I am assigning my user to the client in VB.NET:
Dim token = result.Item("token")
Dim userId = result.Item("userId")
Dim user As New MobileServiceUser(userId)
user.MobileServiceAuthenticationToken = token
MobileService.CurrentUser = user
So, the standard workflow is as follows:
User logs in
Program calls standard API method
On iOS, this works flawlessly. I see the log entry on the API output and it immediately returns the correct information to the iOS app.
On Windows.NET, the following 2 scenarios exist:
If I skip the login process and just call the standard API method (which has been set to access "anonymous"), it works.
If I force the login process and then call the standard API method, the code just hangs forever. The log entry does show up on the API output, but waiting several minutes on the .NET debugger yields no output and no error message. It's just (apparently) hung indefinitely.
So, from what I can tell, the following statements apply:
The API code seems to run the same way every time, no matter which platform is calling the code.
The iOS code seems to run correctly.
Logging in always seems to go fine on either platform.
The .NET code runs fine if the *.json permissions are "anonymous" and no Login attempt has been made.
The .NET code breaks (i.e., hangs indefinitely) if the standard API call is sent after logging in.
This would seem, then, to be related to something happening to the MobileServiceClient during my LoginWithResult method. But, from what I can see, it's the EXACT same code (effectively) on both iOS and Windows.
Does anybody see a flaw in my thinking or code?

`StreamSocketListener`-based server in Universal App

It is known that Windows 8.1 and Windows Phone 8.1 put lots of constraints on background activities of third-party app. For instance, it is impossible to develop server-like capability (e.g. BitTorrent) in Store App without having to keep the screen always-on using DisplayRequest.
From the latest documentation, I have a feeling that one can utilize the method EnableTransferOwnership of StreamSocketListener to delegate the usual request processing code to a background task. The problem is that I don't know how IBackgroundTask should work in this case. Normally, they are activated by some conditions/triggers such as "Internet becomes available". The only sensible trigger in this case seems to be ControlChannelTrigger but apparently, the documentation implies that it cannot be used with StreamSocketListener since the app needs to be the one who creates and register a StreamSocket, not waiting for the socket to be created by some connecting client.
Is it possible now to implement a StreamSocketListener-based server in Windows 10 Universal app platform? If it is, how can I do that?
Use it to activate a background task on socket activity such as receiving data when the app is not active, e.g.:
var socketTaskBuilder = new BackgroundTaskBuilder();
socketTaskBuilder.Name = "SocketActivityBackgroundTask";
socketTaskBuilder.TaskEntryPoint = "SocketActivityBackgroundTask.SocketActivityTask";
var trigger = new SocketActivityTrigger();
socketTaskBuilder.SetTrigger(trigger);
var task = socketTaskBuilder.Register();
socket = new StreamSocket();
socket.EnableTransferOwnership(task.TaskId, SocketActivityConnectedStandbyAction.Wake);
For a complete example, look at the Socket Activity sample or the documentation.

Remove A URL Scheme Handler from Launch Services

I am developing a Cocoa Mac app which dynamically generates and registers itself for URL schemes. However, when the application registers itself to handle a newly generated URL scheme (e.g. myscheme1423://), I would like to prevent the application from responding to any previously registered URL schemes.
I am using LSSetDefaultHandlerForURLScheme() for the purpose of registering a URL scheme; in conjunction, the application automatically overwrites it's Info.plist to contain the new scheme. As you may know, the LSSetDefaultHandlerForURLScheme() function adds the given bundleID/scheme to a Launch Services database. However, I couldn't find an equivalent Launch Services function to remove the same bundleID/scheme pair from the database.
I know that I could simply ignore any external events which originated from a URL scheme other than the one for which the app is actively registered, but it feels to me that there should be a simple way to completely wipe out the system's knowledge of the previous scheme. If my application goes through the process of registering for a new scheme more than a few hundred times, a point will come where a significant amount of space (for a Plist, at least) is being taken up on disk by a plethora of pointless pieces of data (i.e. the old Launch Services entries).
I just fired up a playground and began playing. This is utterly undocumented but it appears to work.
Try passing ("None" as CFString) for the second parameter of
LSSetDefaultHandlerForURLScheme()