how to clear user data while delete mac electron app from application directly?

為{幸葍}努か 提交于 2021-02-20 02:52:27

问题


how to delete user data while deleting the macos electron app? 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.


回答1:


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.

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');
}


来源:https://stackoverflow.com/questions/57602390/how-to-clear-user-data-while-delete-mac-electron-app-from-application-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!