WinJS - Hide sensitive content when in background - winjs

I have a WinJS universal app in Windows 8.1. For the purposes of this question, I am only concerned with the Tablet/Desktop portion of the application.
Is there a way to obscure/hide sensitive data when the application is minimized or suspended, such that when a user Alt+Tabs they do not see anything sensitive?
I have accomplished the above in iOS and Android, but Windows is proving more difficult.
Update 1:
I was able to determine when the app is hidden using MSVisibilityChange
document.addEventListener('msvisibilitychange', function() {
if(document.visibilityState == 'visible') {
console.log('app is active');
} else {
console.log('app is hidden');
}
});
I tried showing an image to hide any sensitive data, but the Alt+Tab task switcher still shows the sensitive data, not the image intended to hide that data.

You have the Check point event when the app is moved to the background
WinJS.Application.addEventListener("checkpoint", checkpoint, false);
function checkpoint() {
// Do Magic Here
}
If you handled this event and placed a div on the screen that obscured the screen somehow? that might work. When the user navigated back you could hide the screen?

Related

Web control browser back button

I'm using Navigation 2 and setUrlStrategy(PathUrlStrategy());
I added WillPopScope but the onWillPop is not called when clicking the browser's back button.
Widget build(context) {
return WillPopScope(
onWillPop: () async {
print('here');
if (currentStep == 0) {
return false;
}
return true;
},
child: Scaffold(...
In Navigator 2.0, web browsers are chronological and basically treat all navigation as pushes.
Scenario:
Navigate from screen 1 to screen 2
Click the browser's back button.
In this scenario, Flutter will push the previous route (screen 1) onto the stack.
In other words, the browser back button no longer triggers onPopRoute. Instead it triggers onPushRoute.
I believe it was designed this way so that every navigation action can be treated as a deeplink. With that in mind, if you're developing a Flutter app for the web you should avoid passing arguments from one route to another as much as possible.
https://github.com/flutter/flutter/issues/71122#issuecomment-733864359

Is there a way to prevent the user pressing the back button on their device from popping the current view from the stack?

I'm using React-Native-Navigation from Wix (version 2) to setup navigation in my React Native app. I'm using the sideMenu layout with the center section being a stack. When the user selects one of the side menu items the selected view is pushed onto that center stack. If the user presses their back button on Android, then the view is popped from the stack, but I don't always want this to happen, mainly if the view they selected is a WebView.
If the view is a WebView, I want to manually handle the user pressing the hardware back button. If the WebView can "goBack" then the view will go back, but if it can't then the view will be popped from the stack (as it normally would).
I've tried overriding the back button press using the BackHandler class from react-native and this allows me to capture that press and have the WebView go back if able, but the act of popping the view from the stack also fires. Is there a way in React-Native-Navigation v2 to tell it, "Hey I got this, don't pop unless I tell you to."?
My current code for this section is as follows:
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.backHandler);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.backHandler);
}
backHandler = () => {
if (this.state.canGoBack) {
this.webviewRef.current.goBack();
// I thought this might force the back press to be
// ignored by react-native-navigation, but no dice.
return false;
} else {
// WebView can't go back so pop view like normal
Navigation.pop(this.props.componentId);
}
}
I was expecting this to only pop the view from the stack if the WebView can't currently go back and otherwise just have the WebView go back.
What actually occurs is both events fire. I.e. the WebView goes back, but the view is also popped from the stack.
I was able to find the answer to this through some more digging in the React Native Navigation and React Native docs.
The event subscriptions are called in reverse order (i.e. last registered subscription first), and if one subscription returns true then subscriptions registered earlier will not be called.
So the issue was in my backHandler method. Instead of returning false I needed to return true.
backHandler = () => {
if (this.state.canGoBack) {
this.webviewRef.current.goBack();
// We've handled the event so we return true and the
// handler on the view's parent can effectively be ignored. Yay!
return true;
} else {
// WebView can't go back so pop view like normal
Navigation.pop(this.props.componentId);
}
}

How to capture home button press? I need to emulate its functionality

I am having issues with my app returning to the foreground every time the user presses the back button. I believe this may be because there is a sound playing module that restarts the activity although this is just my hypothesis. However whenever I press the home (middle) button the app is sent to the background and everything works accordingly. I would like to emulate this functionality by capturing the back press event and handle it in a similar manner to the home button. While navigating the source, i've found the following handler in
android/reactnativenavigation/layouts/SingleScreenLayout.java
#Override
public boolean onBackPressed() {
if (handleBackInJs()) {
return true;
}
if (stack.canPop()) {
stack.pop(true, System.currentTimeMillis());
EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
return true;
} else {
return false;
}
}
I can understand at a glance what is being done however I am not very familiar with Java and don't want to introduce any bugs involving the native side of the app, could anyone kindly point out what I would need to modify?
So, you need to capture "the hardware back button" press not the home button right?
check here for the react-native way of doing it

Trigger a dialog box in background script

I have a chrome extension, where I periodically throw out an alert based on something.
The thing is that the default alert in Javascript is very ugly and I am trying to replace it with something more beautiful.
The problem is that currently the alert is triggered from the background script. Google doesn't allow us to include any external libraries in the background html.
Given this problem, how do I go about replacing the default alert with a more modern UI alert?
I was looking to replace the default alert with something like the SweetAlert.
My background.js currently looks like this:
// on some alarm trigger
function showpopup() {
console.log(" in show popuup");
console.log(Date());
alert("ugly alert");
}
I also explored the option of injecting another js file from my background file.
function showpopup() {
console.log(" in show popuup");
console.log(Date());
var s = document.createElement('script');
// added "script.js" to web_accessible_resources in manifest.json
s.src = chrome.extension.getURL('script.js');
s.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(s);
}
My script.js currently just calls an alert
alert("ugly alert now in script.js");
I am not able to figure out how to create my own dialog box in this javascript file script.js.
The problem is where your alert will be shown?
In an browser/OS dialog window? That's what alert() and friends do; as you see yourself, it's ugly and inflexible. In addition, it's technically challenging: it's an old mechanism that stops execution of JS code until closed, which can lead to API malfunctioning; Firefox WebExtensions specifically don't support calling this from the background page.
In the background page? By definition, it's invisible. You can add DOM nodes with an alert there, but you will not see it. Your problem isn't loading a library, your problem is where to display results.
(invisible, so no picture here!)
In the currently open tab? Hijacking an arbitrary page to show your own UI is hard, prone to break, would require draconian permissions with user warnings at install, won't always work. Wouldn't recommend.
In a fresh window? Possible (see chrome.windows API), but hardly "modern UI" at all (at least you can hide the URL bar).
In a browser action popup? Still not possible to trigger it to open in Chrome, so that's out.
The de-facto standard for informing the user about such things is the chrome.notifications API. It offers limited customization, but that's the "modern" approach considering that your extension has no UI surfaces already open at alert time.
You can insert your code into the tab content via
JS: chrome.tabs.executeScript()
CSS: chrome.tabs.insertCSS()
The second possibility would be to use a content script (content.js). But then you would have to use messaging to communicate between background.js and content.js.

MonoTouch: How to update a view [duplicate]

I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.
How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?
You could try something along the lines of:
//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);
//snip
void EnteredForeground (NSNotification notification)
{
// do your stuff here
}
Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!

Resources