Reputation: 1886
I have a Chrome Packaged Web App with a text editor (CodeMirror), and I'd like to implement what (I thought!) was a simple feature:
When the app is closed, it should remember the contents of the editor so that it's there when it is opened again.
Loading the text from storage is easy, and it works fine.
I just can't seem to make save on exit work. I'd like to save the code in chrome.storage.sync which means I can't just save every time a character is pressed - what I need to do is detect when the web app exits and then save the contents of the window.
I might just be doing something really stupid, but because I can't seem to debug what happens in background.js I have no idea - I can't even tell if my code is getting called when the window closes :(
Does anyone have an example of how to detect when a Packaged App's window is closed and then write something (anything!) into chrome.storage.sync? Hopefully I can work onwards from there!
(and sorry - I would have posted the code I used last time, but I can't find it now)
thanks!
Upvotes: 0
Views: 253
Reputation: 77531
As a workaround, you could always use chrome.storage.local
as storage that you can write to very often, and then save to sync
from your event page when the window closes.
You can listen to this from the event page with chrome.app.window.onClosed
.
You may want look into syncFileSystem
API for saving editor files, since storage.sync
has quite a low capacity.
Upvotes: 1