From: Kilian Saffran Date: Mon, 18 Feb 2019 21:46:50 +0000 (+0100) Subject: renderer X-Git-Tag: 0.7beta~41 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=faab90d28b43122dd073d8fbbe211339d693f900;p=invoicejournal.git renderer --- diff --git a/index.html b/index.html index 50a3643..7b234fe 100644 --- a/index.html +++ b/index.html @@ -46,5 +46,6 @@ + \ No newline at end of file diff --git a/js/app.js b/js/app.js index 2ca925a..a98e980 100644 --- 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 --- 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. diff --git a/modules/settings/index.html b/modules/settings/index.html index 280347a..51a0078 100644 --- a/modules/settings/index.html +++ b/modules/settings/index.html @@ -21,7 +21,7 @@
- +
diff --git a/modules/settings/index.js b/modules/settings/index.js index 2f60333..1caddee 100644 --- a/modules/settings/index.js +++ b/modules/settings/index.js @@ -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 index 0000000..6076f0f --- /dev/null +++ b/renderer.js @@ -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() + } + } +} +