-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add js script to read settings from indexedDB
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(function functionToExecute() { | ||
// Open the database connection. | ||
var open = indexedDB.open("/userfs"); | ||
|
||
open.onupgradeneeded = function () { | ||
// Define the database schema if necessary. | ||
var db = open.result; | ||
var store = db.createObjectStore("/userfs"); | ||
console.log("------------> Upgraded userfs?"); | ||
}; | ||
|
||
open.onsuccess = function () { | ||
var db = open.result; | ||
var key = "/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg"; | ||
|
||
// Write file to DB | ||
// var tx = db.transaction('files', 'readwrite'); | ||
// var store = tx.objectStore('files'); | ||
// store.put(null, "test"); | ||
|
||
// Later, read file back out of DB | ||
var tx2 = db.transaction("FILE_DATA"); | ||
var store2 = tx2.objectStore("FILE_DATA"); | ||
var request = store2.get(key); | ||
|
||
request.onsuccess = function (e) { | ||
// Got the file! | ||
var file = request.result; | ||
|
||
if (file == null) { | ||
alert("You haven't generated any results yet."); | ||
console.log("File is null"); | ||
return; | ||
} else { | ||
console.log("Is int8array: " + (file.contents instanceof Int8Array)); | ||
} | ||
|
||
var blob = new Blob([file.contents], { type: "text/csv;charset=utf-8;" }); | ||
var link = document.createElement("a"); | ||
link.href = window.URL.createObjectURL(blob); | ||
link.download = "webSettings.cfg"; | ||
link.click(); | ||
}; | ||
}; | ||
})(); |