[英]how to clear user data while delete mac electron app from application directly?
how to delete user data while deleting the macos electron app? 删除macos electronic应用程序时如何删除用户数据? It seems we need to write a daemon to listen to the folders change, but how to do?
看来我们需要编写一个守护程序来侦听文件夹的更改,但是该怎么办? do you have more clear or easier methods to handle it?
您有更清晰或更简单的方法来处理它吗?
packaging used electron-builder. 包装中使用了电子助力器。
I use electron-localstorage
to set one flag into app, while everytime you start app, which will check if the flag can get from app, if not, this was new installed and opend first time, so it will clear the old userdata. 我使用
electron-localstorage
在应用程序中设置一个标志,而每次您启动应用程序时,都会检查该标志是否可以从应用程序中获取,如果不能,则是第一次安装并首次打开该标志,因此它将清除旧的用户数据。
const userDataPath = app.getPath('userData');
const storage = require('electron-localstorage');
if(platform.isMac && !isDevelopment) {
storage.setStoragePath(path.join(__dirname,'../data.json'));
let item = storage.getItem('opened');
if(!item) {
rimraf(`${userDataPath}`, () => {
console.log('clear user data path done!')
})
}
storage.setItem('opened', 'true');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.