+
+
+
@@ -62,7 +62,7 @@
OpenSearch Dashboards Electron
diff --git a/src/configPreload.js b/src/configPreload.js
new file mode 100644
index 0000000..697b6e0
--- /dev/null
+++ b/src/configPreload.js
@@ -0,0 +1,16 @@
+const { contextBridge } = require('electron');
+const { ipcRenderer } = require("electron");
+const configLibrary = require('./config');
+
+contextBridge.exposeInMainWorld(
+ 'electron',
+ {
+ ipcRenderer: ipcRenderer,
+ onName: (fn) => {
+ ipcRenderer.on("name", (event, ...args) => fn(...args));
+ },
+ getConfig: (name) => config.getConfig(name),
+ setConfig: (config, callback) => configLibrary.setConfig(config, callback),
+
+ }
+)
\ No newline at end of file
diff --git a/src/configRenderer.js b/src/configRenderer.js
new file mode 100644
index 0000000..f421ac2
--- /dev/null
+++ b/src/configRenderer.js
@@ -0,0 +1,53 @@
+function init() {
+ addListeners();
+}
+
+// store name variable if exists
+window.electron.onName(function (event, name) {
+ let config = window.electron.getConfig(name);
+ populateFields(config);
+});
+
+function getMapping() {
+ return [{id: "name", key: "NAME"},
+ {id: "awsAccessKeyId", key: "AWS_ACCESS_KEY_ID"},
+ {id: "awsSecretAccessKey", key: "AWS_SECRET_ACCESS_KEY"},
+ {id: "endpoint", key: "ENDPOINT"},
+ {id: "osdPath", key: "OSD_PATH"}
+ ]
+}
+async function populateFields(config) {
+ let mapping = getMapping();
+ for (map of mapping) {
+ let input = document.getElementById(map.id);
+ input.setAttribute("value", config[map.key]);
+ }
+}
+
+function getNewConfig() {
+ let mapping = getMapping();
+ let config = {};
+ mapping.forEach(function(map) {
+ let input = document.getElementById(map.id);
+ config[map.key] = input.value;
+ })
+ return config;
+}
+
+function addListeners() {
+ let submit = document.getElementById("submit");
+ submit.addEventListener("click", async (event) => {
+ event.preventDefault();
+ console.log('click');
+ let newConfig = getNewConfig();
+ console.log('newConfig', newConfig);
+ window.electron.setConfig(newConfig, closeWindow);
+ })
+}
+
+function closeWindow() {
+ window.electron.ipcRenderer.invoke("closeWindow");
+}
+
+init();
+
diff --git a/src/dashboards.js b/src/dashboards.js
index caf318c..5db83bb 100644
--- a/src/dashboards.js
+++ b/src/dashboards.js
@@ -9,22 +9,6 @@ const http = require('http');
const superagent = require('superagent');
-
-const CONFIG_PATH = path.join(__dirname, "config.json");
-
-
-function getConfig(configPath=CONFIG_PATH) {
- let config = fs.readFileSync(configPath);
- config = JSON.parse(config.toString());
- return config;
-}
-
-function setConfig(key, value, callback, configPath=CONFIG_PATH) {
- let config = getConfig(configPath);
- config[key] = value;
- fs.writeFile(configPath, JSON.stringify(config), callback);
-}
-
async function getOSDStatus() {
let statuses = {};
try {
@@ -105,7 +89,6 @@ async function startOSD() {
}
exports.startProxy = startProxy;
-exports.getConfig = getConfig;
-exports.setConfig = setConfig;
+
exports.startOSD = startOSD;
exports.getOSDStatus = getOSDStatus;
diff --git a/src/main.js b/src/main.js
index 4f16f0d..e65125b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -14,10 +14,22 @@ function createWindow() {
win.webContents.openDevTools();
}
+function createConfigWindow() {
+ const win = new BrowserWindow({
+ width: 1600,
+ height: 1200,
+ webPreferences: {
+ preload: path.join(__dirname, 'configPreload.js')
+ }
+ })
+
+ win.loadFile("./src/configManager.html");
+ win.webContents.openDevTools();
+}
+
async function viewOSD() {
app.whenReady().then(() => {
createWindow();
-
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
@@ -34,5 +46,16 @@ ipcMain.handle('swapURL', async (event, arg) => {
win.loadURL(arg);
})
+ipcMain.handle('openConfig', async (event, name) => {
+ let configWindow = createConfigWindow();
+ configWindow.webContents.send('name', name);
+
+})
+
+ipcMain.handle('closeWindow', async (event, arg) => {
+ let win = BrowserWindow.getFocusedWindow();
+ win.close();
+})
+
viewOSD();
\ No newline at end of file
diff --git a/src/renderer.js b/src/renderer.js
index 643e814..94c3e81 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -6,10 +6,8 @@ function getMapping() {
]
}
function init() {
- window.config = {};
- window.config = window.electron.getConfig();
addListeners();
- populateFields();
+ //populateFields();
}
async function populateFields() {
@@ -23,19 +21,15 @@ async function populateFields() {
function addListeners() {
let listeners = getMapping();
- listeners.forEach(function(listener) {
- let input = document.getElementById(listener.id);
- input.addEventListener('blur', (event) => {
-
- if (window.config[listener.key] != input.value) {
- window.config[listener.key] = input.value
- //add in success for save file config
- window.electron.setConfig(listener.key, input.value, ()=>{});
- }
- })
+ let addConfig = document.getElementById("addConfig");
+ addConfig.addEventListener("click", async (event) => {
+ event.preventDefault();
+ window.electron.ipcRenderer.invoke("openConfig");
+
})
-
+
let submit = document.getElementById("submit");
+
submit.addEventListener("click", async (event) => {
event.preventDefault();
console.log(event);