node-webkit windows 构建在哪里存储持久数据?

node-webkit windows build where to store persistent data?

我正在使用 node-webkit 构建桌面应用程序。我使用 nw-builder 从我的 mac 构建 windows 32 & windows 64 位。该程序在 windows 中运行良好,只是我用来存储数据的文件在程序退出时消失了。

该应用程序被打包为一个 .pak 文件,我假设当程序关闭时,所有文件都会被删除。所以当我再次启动应用程序时,持久化数据消失了。

如何在 Windows 中为 node-webkit 保留数据?

我正在使用 'node-persist' 包来坚持。在 Mac 中,它在 .app 文件中创建了一个名为 'persist' 的文件夹,并将文件写入可以正常工作的文件夹。

但在 windows 中,由于 .pak 文件,当程序关闭时,持久化文件会丢失。我该如何解决 ?有没有办法将文件存储在 .pak 之外。 .pak 似乎被提取到一个临时位置。

更新(已解决)

我已经按照 https://github.com/nwjs/nw.js/wiki/App

中的描述使用了 App.dataPath

摘录:

Get the application's data path in user's directory. Windows: %LOCALAPPDATA%/; Linux: ~/.config/; OSX: ~/Library/Application Support/ where is the field in the manifest.

PopcornTime also uses the same in its database.js file. https://git.popcorntime.io/popcorntime/desktop/blob/master/src/app/database.js

您有多种选择:

https://github.com/nwjs/nw.js/wiki/Save-persistent-data-in-app

就我个人而言,我使用了 localStorage。对于简单的需求,它非常简单并且模仿浏览器的行为。