renderer
authorKilian Saffran <ksaffran@dks.lu>
Mon, 18 Feb 2019 21:46:50 +0000 (22:46 +0100)
committerKilian Saffran <ksaffran@dks.lu>
Mon, 18 Feb 2019 21:46:50 +0000 (22:46 +0100)
index.html
js/app.js
main.js
modules/settings/index.html
modules/settings/index.js
renderer.js [new file with mode: 0644]

index 50a3643..7b234fe 100644 (file)
@@ -46,5 +46,6 @@
 
 <script src="js/app.js"></script>
 <script>if (window.module) module = window.module;</script>
+<script src="renderer.js"></script>
 </body>
 </html>
\ No newline at end of file
index 2ca925a..a98e980 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -6,14 +6,14 @@
 
 $( document ).ready(function() {
   console.log( "Main ready!" );
-  app.loadmodule("overview");
+  browserapp.loadmodule("overview");
   console.log("After module load!");
 });
 console.log(navigator.platform);
 console.log(location.protocol);
-var app = {
+var browserapp = {
 loadmodule: function(modulename){
-  var appdata = app.getconfig();
+  var appdata = browserapp.getconfig();
   var params = "?";
   for (var i in appdata){
     params += "&" + i +"=" + encodeURIComponent(appdata[i]);
@@ -22,7 +22,7 @@ loadmodule: function(modulename){
   $("#moduleframe").attr("src","modules/"+modulename+"/index.html"+ params);
 },
 loadmodulepage: function(modulename,page,pageparams = null){
-  var appdata = app.getconfig();
+  var appdata = browserapp.getconfig();
   var params = "?";
   for (var i in appdata){
     params += "&" + i +"=" + encodeURIComponent(appdata[i]);
diff --git a/main.js b/main.js
index 2061836..d3f65ea 100644 (file)
--- a/main.js
+++ b/main.js
@@ -46,7 +46,7 @@ function createWindow () {
   mainWindow.show()
   // Open the DevTools.
   mainWindow.webContents.openDevTools()
-
+  
   // Emitted when the window is closed.
   mainWindow.on('closed', function () {
     // Dereference the window object, usually you would store windows
@@ -56,6 +56,7 @@ function createWindow () {
   })
 }
 
+
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.
index 280347a..51a0078 100644 (file)
@@ -21,7 +21,7 @@
                 </div>
               </nav>
     <div class="cotainer-fluid" style="margin-top: 52px;">            
-    
+    <button class="btn btn-secondary" onclick="parent.usersystem.showError('MyError','My Error Message from settings!');">Show Error</button>
     </div>
 <script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
 <script src="../../node_modules/jquery/dist/jquery.min.js"></script>
index 2f60333..1caddee 100644 (file)
@@ -1,3 +1,4 @@
 function initpage(){
-    
+    console.log(parent.usersystem.getsysinfo());
+    parent.usersystem.setProperty("testproperty",{id:"TEST"});
 }
\ No newline at end of file
diff --git a/renderer.js b/renderer.js
new file mode 100644 (file)
index 0000000..6076f0f
--- /dev/null
@@ -0,0 +1,72 @@
+const { dialog } = require('electron').remote;
+const fs = require('fs'); 
+const os = require('os');
+var usersystem = {
+    profilepath: function(){
+        var ppath="";
+        if (os.platform() == "darwin"){
+         ppath = os.homedir() + '/Library/Application Support/invoicejournal/';
+        }
+        return ppath;
+    },
+    selectfile: function(dlgtitle,lastpath,filefilters=null){
+        return dialog.showOpenDialog({title: dlgtitle,defaultPath: lastpath, filters: filefilters, properties: ['openFile'] });
+    },
+    selectdir: function(dlgtitle,lastpath){
+        return dialog.showOpenDialog({title: dlgtitle,defaultPath: lastpath, filters: filefilters, properties: ['openDirectory'] });
+    },
+    showMessage: function(msgTitle,msg,msgdetail,msgtype,msgButtons=["OK"],defautlbtnid=0,cancelbtnid){
+        return dialog.showMessageBox({type: msgtype, //
+                                    title: msgTitle,
+                                    buttons:msgButtons,
+                                    message: msg, 
+                                    detail: msgdetail,
+                                    defaultId: defautlbtnid,
+                                cancelId: cancelbtnid});
+    },
+    showError: function(errtitle,errmsg){
+        dialog.showErrorBox(errtitle, errmsg);
+    },
+    setProperty(key,data){
+       
+        
+        if ((typeof data == 'object') || (typeof data == 'array')){
+            data = JSON.stringify(data);
+        }
+        fs.writeFile(this.profilepath()  + key + ".json", data, (err) => {
+            if (err) {
+                this.showError("Error writing Preference!",err.message);
+                console.log(err);
+                return false;
+            }
+            return true;
+            
+        });
+        return false;
+    },
+    getProperty(key){
+        var data = null;
+        fs.readFile(this.profilepath()  + key + ".json", 'utf-8', (err, data) => {
+            if(err){
+                this.showError("Error reading Preference!",err.message);
+                return data;
+            }
+            if (data.startsWith("{") || data.startsWith("[")){
+                data = JSON.parse(data);
+            }
+            // Change how to handle the file content
+            console.log("The file content is : " + data);
+            return JSON.stringify(data);
+        });
+        return data;
+    },
+    getsysinfo(){
+        return {
+            "hostname": os.hostname(),
+            "userdir": os.homedir(),
+            "platform": os.platform(),
+            "userinfo":os.userInfo()
+        }
+    }
+}
+