dbus-vis: Use IPC for open file dialog

Previously, the "open file" dialog is opened in the renderer thread
running "initialization.js".

This change moves the dialog to the main thread (main.js) so that the
renderer thread emits a "file-request" request and the main thread
answers with a "filename" response.

This IPC paradigm is required for newer versions of Electron, because
the "dialog" module cannot be imported in renderer threads in those
newer versions.

Signed-off-by: Sui Chen <suichen@google.com>
Change-Id: Ifd324688bb8a4dbdc6a5f86082fb3d205af0d77a
diff --git a/dbus-vis/main.js b/dbus-vis/main.js
index 705ce4e..860fc31 100644
--- a/dbus-vis/main.js
+++ b/dbus-vis/main.js
@@ -1,6 +1,16 @@
 // Modules to control application life and create native browser window
-const {app, BrowserWindow} = require('electron');
+const {app, BrowserWindow, dialog, ipcMain } = require('electron');
 const path = require('path');
+const {fs} = require('file-system');
+
+// Open-file dialog
+ipcMain.on('file-request', (event) => {
+  const options = {
+    title: 'Open a file or folder',
+  };
+  const x = dialog.showOpenDialogSync(options) + '';  // Convert to string
+  event.reply("filename", x);
+});
 
 function createWindow() {
   // Create the browser window.
@@ -10,7 +20,7 @@
     webPreferences: {
       nodeIntegration:
           true,  // For opening file dialog from the renderer process
-      enableRemoteModule: true  // For require('electron').remote
+      contextIsolation: false,
     }
   });