Ionic 3 - Display lock screen when we minimized the app - background

In Ionic 3, we need to display the lock screen if app is minimized or goes to background if we open any other app.
Thanks
AK

I got it how we can implement the above logic.
platform.pause.subscribe(() => {
//logic when the application is in the background
this.navCtrl.push(LockScreenPage);
});
platform.resume.subscribe(() => {
//logic when the application has been resumed after being paused.
});
But anybody have any idea where we can have it commonly in the application, because I am having 16 pages in my app. If I create BaseApp and extends with all the 16 pages then this code would executes 16times. Any other way to implement this logic. Is it OK we use it in component.ts?

Related

Even listener stops working when app is running in the background

I am making a React Native app which talks to Spotify via this module: https://github.com/cjam/react-native-spotify-remote
The module has an event listener which allows us to listen to Spotify player state changes, for example:
import { remote as SpotifyRemote } from "react-native-spotify-remote";
// and in a React component:
SpotifyRemote.addListener("playerStateChanged", (state) => {
console.log(state);
});
The above works as long as our RN app is in focus. However, when the app is in the background (i.e. we are on a different app or the phone is locked), the event listner no longer gets triggered.
I am expecting the event listener to get triggered even when the app is running in the background but it isn't doing that.
Is there anyway to make this work even the app is not in focus? Thank you!

Electron notifications don't bring app up to front again on click on the notification

I have an electron app that will just wrap a remote page while adding some extra features. With the following code the page loads and works. When the remote page fires some notifications using the notification API those notifications show up when the electron app is minimized. My problem is that when clicking on those notifications the app does not get put to front like it does when opening the remote page on any other browser directly. I could test this only for Ubuntu 19.10 Linux (Gnome 3).
Any idea if I need to configure something for that or if this is a bug with Electron/Ubuntu/Gnome?
const {app, shell, BrowserWindow} = require('electron');
let mainWindow;
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1024,
height: 786,
});
mainWindow.setMenu(null);
mainWindow.setTitle('My app – Connecting…');
mainWindow.loadURL('https://some.url.somwhere');
// Emitted when the window is closed.
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', createWindow);
First of it is NOT a good idea to wrap a remote page unless you really know what you are doing as if you were redirected to a malicious page the page would have access to run code in the operating system. I would suggest giving this a read to make sure you're being safe.
Secondly the notification HTML5 API (runs in renderer) and notification module (runs in main) both do not have default behaviour to bring the page to the front when the notification is clicked you must add this behaviour yourself.
Because your loading a remote page you're probably using the notification module therefore it would be accomplished like follows:
notification = new Notification({title: "Message from: "+result[i].messageFrom,body: messagebody,icon: path.join(__dirname, 'assets','images','icon.png')})
notification.show()
notification.on('click', (event, arg)=>{
mainWindow.moveTop()
mainWindow.focus()
})

How to make app change to foreground from background programmatically in react-native?

As the title, how can we start a react-native app from background to foreground, like we tap on push notification, it will show the app?
Thank you!
Look at https://github.com/geektimecoil/react-native-onesignal library it is easy to use and you can even specify what screen you want to open within your app with the
opened event listener
OneSignal.addEventListener('opened', (data) => {
if (data.notification.payload.title === 'New mensaje!') {
this.props.pushNewRoute('chat'); // open specific app screen (Redux)
}
});

How to lock the app from exit in react native?

I'm trying to make that the costumer will not be able to leave the app, even when he press on the home button.
My app is coded with react native, and I'm looking for solution by the code and not by configuration because this feature should work only for specific users...
Do you have any idea or any guide that can help me with that?
I was looking for the solution for a long time but nothing came up.
Thank you for the help
You can do this using BackHandler events. You have to put this code in your main navigation file. When user press back button they will exit from app u can customize ur logic for that for particular user etc...
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', function () {
BackHandler.exitApp();
}.bind(this));
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress');
}

Vue 2.0.1 and Electron - Visual Flash

I'm creating an app visually similar to Alfred to manage and search for my bookmarks. Its working well, but when I do a search and open a bookmark, I immediately hide the app and when I invoke it again, it return to the default mode doing a visual flash. The reset to default is triggered right before hiding the app.
I hide the application like this : remote.app.hide() and I added a listener on win.hide in my components to reset the vue.
It works, but the reset is processed after the application show up again.
I don't know how to do it when the application is hide or to show up it right after the vue is reloaded.
If you have any clue, it would be great.
I created a sample project on Github you can clone and test this issue.
Github Project
I'm working on macOS at the moment.
Thank you.
I found an easy way, you cannot rely on the window.on('hide') event.
So in your shortcut registration, I made your app emit a custom event that your Vue.js will listen to reset your input before hiding the app:
main.js
const retShow = globalShortcut.register('CmdOrCtrl+Alt+V', () => {
if (!win.isVisible()) {
win.show()
} else {
app.emit('hide-window'); // Let the window hide the app
}
})
In your Vue.js app, in the created hook:
app.js
app.on('hide-window', function () {
vm.reset();
setTimeout(app.hide, 10);
});
Here my pull request: https://github.com/Cronos87/electron-vue-flash-issue/pull/1/files