From 2025517596c333494ebb38b2601ada2fceab0897 Mon Sep 17 00:00:00 2001 From: flaryer Date: Fri, 27 May 2022 17:23:00 +0800 Subject: [PATCH] add config file --- index.html | 75 ++++++++++++++++++++++++++--------------------- js/index.js | 56 +++++++++++++++++++++++++++++++---- package-lock.json | 4 +-- package.json | 2 +- 4 files changed, 96 insertions(+), 41 deletions(-) diff --git a/index.html b/index.html index 6556ce1..749000c 100644 --- a/index.html +++ b/index.html @@ -18,14 +18,14 @@
-
+
-
+
+
+ +
@@ -43,9 +52,7 @@ cols="30" rows="2" class="form-control" - > -(filename) => true + >
+
+ +
+ +
+Null
+ +
+Null
+ >
- -
-Null
- -
-Null
{ tableBody.append( $( - `` + `` ) ); }); @@ -132,6 +135,40 @@ function diff() { $("#diffModal").modal(); } +function loadConfig() { + const config = JSON.parse(fs.readFileSync(configPath)); + $("#directory-input").val(config.directory ?? ""); + $("#input-file-fliter").val(config.fileFilter ?? ""); + $("#language-select").val(config.language ?? ""); + $("#threshold").val(config.threshold ?? ""); + $("#result-fliter").val(config.resultFilter ?? ""); +} + +function saveConfig(config) { + fs.writeFileSync( + configPath, + JSON.stringify( + config ?? { + directory: $("#directory-input").val(), + fileFilter: $("#input-file-fliter").val(), + language: $("#language-select").val(), + threshold: $("#threshold").val(), + resultFilter: $("#result-fliter").val(), + } + ) + ); +} +function resetConfig() { + saveConfig({ + directory: os.homedir(), + fileFilter: "(filename) => true", + language: "2", + threshold: 75, + resultFilter: `(fileAName, fileBName, percentage) => {\n const A = fileAName.split("-");\n const B = fileBName.split("-");\n return A[0] != B[0] && A[1] == B[1];\n};`, + }); + loadConfig(); +} + (function () { const amdLoader = require("./node_modules/monaco-editor/min/vs/loader.js"); const amdRequire = amdLoader.require; @@ -159,3 +196,12 @@ function diff() { ); }); })(); + +(function () { + if (!fs.existsSync(configPath)) { + resetConfig(); + } else { + loadConfig(); + } + window.onbeforeunload = () => saveConfig(); +})(); diff --git a/package-lock.json b/package-lock.json index bd58046..c845b84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simgui", - "version": "0.0.4", + "version": "0.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "simgui", - "version": "0.0.4", + "version": "0.0.5", "license": "MIT", "dependencies": { "electron-squirrel-startup": "^1.0.0", diff --git a/package.json b/package.json index 4f1f25c..c9b2ddb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simgui", - "version": "0.0.4", + "version": "0.0.5", "description": "SimGUI", "main": "dist/main.js", "scripts": {
${v.fileAName}${ - v.fileBName - }${v.similarPercentage.toString()}
${v.fileAName}${v.fileBName}${v.similarPercentage}