Skip to content

Commit dda784f

Browse files
committed
config saving
1 parent a88202c commit dda784f

File tree

3 files changed

+105
-33
lines changed

3 files changed

+105
-33
lines changed

.idea/workspace.xml

Lines changed: 97 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/components/ConfigDialog.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ public ConfigDialog(Project project) throws IOException, InterruptedException {
105105
freqCombo.addItem(120.0);
106106
}
107107
}
108-
if (new File("config.json").exists()) {
109-
loadConfig();
110-
}
108+
loadConfig();
111109
}
112110

113111
/**

src/main/java/entity/Config.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.JsonObject;
66
import com.google.gson.JsonParser;
77
import com.google.gson.reflect.TypeToken;
8+
import com.intellij.openapi.application.PathManager;
89

910
import java.io.FileReader;
1011
import java.io.FileWriter;
@@ -48,7 +49,7 @@ public Config() {
4849
}
4950

5051
public boolean configExists() {
51-
try (FileReader fileReader = new FileReader("config.json")) {
52+
try (FileReader fileReader = new FileReader(PathManager.getPluginsPath() + "/config.json")) {
5253
return true;
5354
} catch (Exception e) {
5455
return false;
@@ -68,8 +69,10 @@ public void saveAsJson() {
6869
jsonObject.addProperty("dataOutputPath", dataOutputPath);
6970
jsonObject.addProperty("eyeTrackerDevice", eyeTrackerDevice);
7071

71-
try (FileWriter fileWriter = new FileWriter("config.json")) {
72-
fileWriter.write(jsonObject.toString());
72+
Gson gson = new Gson();
73+
try (FileWriter fileWriter = new FileWriter(PathManager.getPluginsPath() + "/config.json")) {
74+
System.out.println(PathManager.getPluginsPath() + "/config.json");
75+
fileWriter.write(gson.toJson(jsonObject));
7376
} catch (Exception e) {
7477
throw new RuntimeException(e);
7578
}
@@ -79,7 +82,7 @@ public void saveAsJson() {
7982
* Load the configuration from the JSON file.
8083
*/
8184
public void loadFromJson() {
82-
try (FileReader fileReader = new FileReader("config.json")) {
85+
try (FileReader fileReader = new FileReader(PathManager.getPluginsPath() + "/config.json")) {
8386
Gson gson = new Gson();
8487
JsonElement jsonElement = JsonParser.parseReader(fileReader);
8588
JsonObject jsonObject = jsonElement.getAsJsonObject();

0 commit comments

Comments
 (0)