Cooooookies!!!

This commit is contained in:
Rafał Dzięgiel
2021-03-16 13:12:44 +01:00
parent 72b55939b4
commit 918157be04
3 changed files with 62 additions and 3 deletions

29
src/fileOps.js Normal file
View File

@@ -0,0 +1,29 @@
const { Gio, GLib } = imports.gi;
const Debug = imports.src.debug;
const Misc = imports.src.misc;
const { debug } = Debug;
Gio._promisify(Gio._LocalFilePrototype, 'make_directory_async', 'make_directory_finish');
function createCacheDirPromise()
{
return new Promise(async (resolve, reject) => {
const cacheDir = Gio.File.new_for_path(
GLib.get_user_cache_dir() + '/' + Misc.appId
);
if(cacheDir.query_exists(null))
return resolve(cacheDir);
const dirCreated = await cacheDir.make_directory_async(
GLib.PRIORITY_DEFAULT,
null,
).catch(debug);
if(!dirCreated)
return reject(new Error(`could not create dir: ${cacheDir.get_path()}`));
resolve(cacheDir);
});
}