Rough first "will it blend" swing. Needs UI stylizing, js cleanup, perhaps different dialog technology, etc.

settings-file-dialogs
csharpen 2022-09-09 03:10:34 -05:00
rodzic ac68a3ff61
commit 4a1b6c8e66
2 zmienionych plików z 57 dodań i 39 usunięć

Wyświetl plik

@ -1341,20 +1341,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<div class="mapItem">
<table align="center">
<tr>
<td>
<!--
Should stylize these better.
Is there a more modern approach than https://tympanus.net/codrops/2015/09/15/styling-customizing-file-inputs-smart-way/ ?
-->
<td><input class="button" id="saveSettingsButton" type="file" nwsaveas="gt_settings.json" accept=".json" nwdirectorydesc="Export GridTracker Config..." />
<div class="button" onclick="exportSettings();">Export Settings</div>
</td>
</tr>
<tr>
<td>
<div style="display: none" id="importSettingsButton" class="button" onclick="importSettings();">
<input type="file" name="loadSettingsButton" id="loadSettingsButton" accept=".json" />
<div id="importSettingsButton" class="button" onclick="importSettings();">
Import Settings
</div>
</td>
</tr>
<tr>
<td>
<font style="display: none" id="importSettingsFile"></font>
<font id="importSettingsFile"></font>
</td>
</tr>
</table>

Wyświetl plik

@ -7653,66 +7653,79 @@ function changelookupOnTx()
function exportSettings()
{
var filename = g_appData + g_dirSeperator + "gt_settings.json";
var toWrite = JSON.stringify(localStorage);
fs.writeFileSync(filename, toWrite);
checkForSettings();
var fileinput = document.querySelector("input[id=saveSettingsButton]");
var filename = fileinput.value
if (filename != "")
{
var toWrite = JSON.stringify(localStorage);
fs.writeFileSync(filename, toWrite);
console.log("Filename is " + filename)
}
else
{
// No file selected, likely cancelled out of the file dialog box
}
checkForSettings(filename);
}
function checkForSettings()
function checkForSettings(filename)
{
var filename = g_appData + g_dirSeperator + "gt_settings.json";
if (fs.existsSync(filename))
{
importSettingsButton.style.display = "inline-block";
// importSettingsButton.style.display = "inline-block";
importSettingsFile.style.display = "inline-block";
importSettingsFile.innerHTML = filename;
}
else
{
importSettingsButton.style.display = "none";
// importSettingsButton.style.display = "none";
importSettingsFile.style.display = "none";
}
}
function importSettings()
{
checkForSettings();
var filename = g_appData + g_dirSeperator + "gt_settings.json";
if (fs.existsSync(filename))
var fileinput = document.querySelector("input[id=loadSettingsButton]");
var filename = fileinput.value
if (filename != "")
{
var data = fs.readFileSync(filename);
data = JSON.parse(data);
if (
typeof data.appSettings != "undefined" &&
data.currentVersion == localStorage.currentVersion
)
checkForSettings(filename);
if (fs.existsSync(filename))
{
localStorage.clear();
for (var key in data)
var data = fs.readFileSync(filename);
data = JSON.parse(data);
if (
typeof data.appSettings != "undefined" &&
data.currentVersion == localStorage.currentVersion
)
{
localStorage[key] = data[key];
localStorage.clear();
for (var key in data)
{
localStorage[key] = data[key];
}
fs.unlinkSync(filename);
chrome.runtime.reload();
}
fs.unlinkSync(filename);
chrome.runtime.reload();
}
else
{
if (typeof data.appSettings == "undefined")
else
{
importSettingsFile.innerHTML =
"<font style='color:red'>Settings File Corrupt!</font>";
}
else if (data.currentVersion != localStorage.currentVersion)
{
importSettingsFile.innerHTML =
"<font style='color:red'>Settings Version Mismatch!</font>";
if (typeof data.appSettings == "undefined")
{
importSettingsFile.innerHTML =
"<font style='color:red'>Settings File Corrupt!</font>";
}
else if (data.currentVersion != localStorage.currentVersion)
{
importSettingsFile.innerHTML =
"<font style='color:red'>Settings Version Mismatch!</font>";
}
}
}
}
else
{
// No file selected, likely cancelled out of the file dialog box
}
}
function showCallsignBox(redraw)