YT: store reusable alive info in temp folder

This commit is contained in:
Rafał Dzięgiel
2021-03-17 10:38:39 +01:00
parent d9b35b7fb8
commit bd20d305ba
2 changed files with 89 additions and 47 deletions

View File

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