简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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