const {app} = require('electron');
const fs = require('fs');
const log = require('electron-log');
const path = require('path');
const rimraf  = require('rimraf');

module.exports = function () {
    return new Promise((resolve, reject) => {
        rimraf(app.getPath('userData'), (err) => {
            if (err) {
                return reject(`Could not delete old file ${app.getPath('userData')}: ${err.message}`);
            }

            resolve();
        });
        // fs.readdir(app.getPath('userData'), function(err, filenames) {
        //     if (err) {
        //         log.error('clearAppData(); has error, remove app data directory');

        //         rimraf(app.getPath('userData'), (err) => {
        //             if (err) {
        //                 return reject(`Could not delete old file ${app.getPath('userData')}: ${err.message}`);
        //             }

        //             resolve();
        //         });
        //     } else {
        //         filenames.forEach(function(filename) {
        //             if ( filename !== 'uploads' ) {
        //                 if ( !rimraf.sync(path.join(app.getPath('userData'), filename)) ) {
        //                     return reject(`Could not delete old file ${path.join(app.getPath('userData'), filename)}`);
        //                 }
        //             }
        //         });
        //     }
        // }, function () {
        //     resolve();
        // });
    });
};