How to implement idle timeout in Nativescript android application - nativescript-angular

I am building a Finacial application in Nativescript angular. I need some references like if the app is opened and running in the background after the set of some idle timeout it should redirect to the page which we specified. I couldn't get the proper reference in Nativescript can anyone please add a solution for the idle timeout. I have checked Nativescript extended activity but couldn't get properly

You should start by reading the documentation. What you need is Lifecycle hooks.
Read : https://docs.nativescript.org/angular/core-concepts/application-lifecycle#use-application-events
applicationOn(suspendEvent, (args: ApplicationEventData) => {
setTimeout(() => {
// do what you want after a certain amouont of time
// don't
}, 5000);
});
or
applicationOn(resumeEvent, (args: ApplicationEventData) => {
// compare current datetime with the last datetime saved in suspendEvent event
});
Don't forget your app can be force-closed, so you have to handle this depending on your needs

Related

Is there a way to configure "exit_on_all_closed" for browser tabs?

I'm currently working on understanding building Rust apps using Bevy in WebAssembly. Under normal circumstances, the exit_all_on_closed variable in the following code allows for the app to close when the window the app is launched in is closed.
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
title: "Extreme".to_string(),
..default()
},
add_primary_window: true,
exit_on_all_closed: true,
close_when_requested: true,
}))
.run()
}
Since I'm launching the app in my browser using a wasm server, I'd assumed that closing either the tab the app launches in or the entire browser would trigger the app exit, but it does not. Is there functionality in Bevy to handle that? Is there another work around?
Attempted: set exit_all_on_closed to true, launch app in browser, and close browser. Expected app to exit.
Actual result: Browser window closed but app is still running.
You can use the browsers beforeunload event via web-sys to track when users close a tab or a browser window containing your application.
Using this in combination with onload would also allow you to track all currently open instances.

Manifest v3 fetch data from external API

I'm developing a Browser (Chrome, Firefox) extension with react with Manifest v3.
In my app, I have a search bar where I show suggested words based on the value typed by the user (like search engine do).
In manifest v2, I used to load this script like so:
"content_security_policy": "script-src 'self' https://suggest.finditnowonline.com; object-src 'self'"
In v3 this is not supprted anymore but I cannot find the way how I could still make my code work.
he most relevant resource I found online are this answer: Content Security Policy in Manifest V3 for Facebook Page Plugin
and this documentation: https://www.chromium.org/Home/chromium-security/extension-content-script-fetches
But I cannot understand how I can implement my script from the background.js page since It needs to fetch the API dynamically, every time the user type something in the input field.
This is the react code: where I fetch the api
useEffect(() => {
const fetchSuggestedWords = async () => {
try {
const res = await fetchJsonp(`${process.env.SUGGESTED_WORDS_URL}${searchValue}`)
const suggestedWordsArray = await res.json()
setSuggestedWords(suggestedWordsArray[1].slice(0, 10))
return
} catch {
console.log('error fetching suggested results')
}
}
if (searchSuggestedWords) {
fetchSuggestedWords()
}
}, [searchValue])
Where searchValue is a state update whenever the onChange event is trigger on the input field.
Any tips on how to approach this new format?
Would people recommend not switching to Manifest v3 just yet?
From what I gathered, you're trying to talk to an api and not load an external script.
If you're trying to load external, that will not work.
Fetching data on the other hand has multitudes of ways it can be done, not all are proper though.
Also I've noticed that you're misunderstanding the core keys of the async messaging system and service worker cycle.
Add a service worker
*Background.js or svc-worker.js
and give it a on message listener, try to at least handle messaging between your extension, if you're not sure, you can always get an example on github.
After that, it's a matter of setting the CSP and optimizing where you'll be fetching the data.
After a little while, I'm sure you'll get the hang of it.
the code in content should be like
content.js
inputElement.oninput = (e) => {let input = e.target.value;
chrome.runtime.sendMessage({Origin: 'Content', Message: input})};
Handle the message in svc worker
svc-worker.js formatted
chrome.runtime.onMessage(request => {
const {Origin, Message} = request
// parse message
// fetch chain here
})
Please note, this is not the only way to handle this.
There's a billion different ways, if you want to add some of this data in a use Effect hook as a dependency, that's going to be tricky, as the data given obtained is always counted as different when obtained via message. < At least in my case scenario.

Handling Back button in Nativescript

I am developing an app by using Nativescript with Angular. According to our design, there is a dashboard when application is started. Now the thing I want to do is that when user click on back button in android, I want to confirm with user 'Are you sure you want to exit?'.
If user click OK, the app will be killed.
If user click No, the app will stay on dashboard page.
If you are aware of this, please share me how can I accomplish this.
Thanks & Best Regards,
Zaw Zaw Naing
You can create a service and maintain current page which can be passed if you want to implement something specific to page. Else you can directly implement logic within below service.
#Injectable()
export class BackService {
private currentPagePara: CurrentPageParameters; //Custom object only if required
constructor(
}
backHandler() {
if (application.android) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (data: application.AndroidActivityBackPressedEventData) => {
// Implement your logic here
});
} else if (application.ios) {
console.log("app ios")
}
}
}
Inject this service in base component and call backhandler
this._backService.backHandler()

Tap event testing with protractor and appium

I have html with on-tap= doThis(). When going to test it with protractor and appium the .click event does not fire it off. It seems like a really simple thing to do, but yet I can not find any documentation on touch events for iOS appium. Does this have to do with the driver I am using?
// javascript
// assuming we have an initialized `driver` object for an app
driver.contexts().then(function (contexts) {
return driver.context(contexts[1]); // choose the webview context
})
// do some web testing
.elementsByCss('.green_button').click()
.context('NATIVE_APP') // leave webview context
// do more native stuff here if we want
.quit() // stop webdrivage

Is it possible to get the currently playing track in the 1.x apps api?

I am trying to update my Spotify remote control app that is currently using the legacy API to use the new 1.x API. Is it possible using the 1.x API to access information about the currently playing track? models.player.track does not seem to exist anymore (though it's in the documentation).
For the curious, I am using this for my app running in Spotify Desktop which uses websockets to talk with a Python server, which then provides a web interface for phones and tablets to remotely control the instance of Spotify running on the desktop. This works great using the legacy API and I can control playback and get the now playing info from any connected remote. I assume this app is going to stop working at some point soon since Spotify says they are retiring the legacy API. (Unless my assumption that the app will stop working is wrong, then never mind).
Thanks.
It is possible to access the current playing track loading the track property of the Player.
You would do something like this:
require(['$api/models'], function(models) {
function printStatus(track) {
if (track === null) {
console.log('No track currently playing');
} else {
console.log('Now playing: ' + track.name);
}
}
// update on load
models.player.load('track').done(function(p) {
printStatus(p.track);
});
// update on change
models.player.addEventListener('change', function(p) {
printStatus(p.data.track);
});
});
You have a working example in the Tutorial App named Get the currently playing track.

Resources