简体   繁体   English

如何在Chrome应用中关闭功能运行功能?

[英]How to run a function on close in a Chrome App?

I'm having an issue where closing my Chrome App too quickly after completing a stage corrupts the save data. 我遇到一个问题,即在完成一个阶段后过快关闭我的Chrome应用会损坏保存数据。 This is because it's in the middle of saving some data. 这是因为它正在保存一些数据。

Is there any way to keep the Chrome App open for a few seconds after the user presses close or alt+f4? 用户按下关闭键或alt + f4键后,有什么方法可以使Chrome应用保持打开状态几秒钟? Or another solution that maybe has a popup telling the user that the app is saving and will close automatically? 还是另一个解决方案,可能有一个弹出窗口告诉用户该应用程序正在保存并会自动关闭?

You can use the chrome.runtime.onSuspend.addListener( function ) method to specify some code to run when the user quits the app. 您可以使用chrome.runtime.onSuspend.addListener(function)方法来指定一些在用户退出应用程序时要运行的代码。 As stated in the chrome documentation, any code running or triggered in the background/event page will keep the program alive for a short time to allow these processes to end. 如chrome文档中所述,在后台/事件页面中运行或触发的任何代码都会使程序在短时间内保持活动状态,以使这些过程结束。 Remember to register this event listener method in your background/event page before the user has a chance to quit. 在用户有机会退出之前,请记住在您的后台/事件页面中注册此事件侦听器方法。

Additional information here: https://developer.chrome.com/extensions/runtime#event-onSuspend 此处的其他信息: https : //developer.chrome.com/extensions/runtime#event-onSuspend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM