Browse Source

Should now work when packaged with electron-builder.

development
Bryan Miller 4 years ago
parent
commit
18616465a6
No known key found for this signature in database
2 changed files with 34 additions and 3 deletions
  1. +20
    -2
      app/styles.js
  2. +14
    -1
      main.js

+ 20
- 2
app/styles.js View File

const { ipcRenderer } = require('electron')
const sass = require('sass'); const sass = require('sass');
const path = require('path');
const fs = require('fs');

const SASS_BASE_PATH = 'view/sass';


// TODO: Once configs are setup, make this section more dynamic!! // TODO: Once configs are setup, make this section more dynamic!!
var VARS = { var VARS = {
}; };




console.log(ipcRenderer.sendSync("getPath", "app"));
function handleFileLoad(url, prev, done){
let apppath = ipcRenderer.sendSync("getPath", "app");
let filepath = path.join(apppath, SASS_BASE_PATH, url + ".scss");
console.log("Attempting to load ", filepath);
fs.readFile(filepath, 'utf-8', (err, data) => {
if (err){
done(err);
} else {
done({contents: data.toString()});
}
});
}

function buildSASSVars(){ function buildSASSVars(){
let res = ""; let res = "";
Object.keys(VARS).forEach((key)=>{ Object.keys(VARS).forEach((key)=>{
function render(entryfile){ function render(entryfile){
return new Promise((res, rej) => { return new Promise((res, rej) => {
let entry = buildSASSVars() + "@import '" + entryfile + "';\n"; let entry = buildSASSVars() + "@import '" + entryfile + "';\n";
sass.render({data: entry, includePaths:['view/sass/']}, (err, data) => {
sass.render({data: entry, importer:handleFileLoad}, (err, data) => {
if (err){rej(err);} if (err){rej(err);}
res(data); res(data);
}); });

+ 14
- 1
main.js View File

const {app, BrowserWindow} = require('electron');
const {app, BrowserWindow, ipcMain} = require('electron');
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');


} }
}); });


ipcMain.on("getPath", (event, arg) => {
let val = null;
switch(arg.toLowerCase()){
case "app":
val = app.getAppPath(); break;
case "home":
val = app.getPath('home'); break;
case "user":
val = app.getPath('user'); break;
}

event.returnValue = val;
});



Loading…
Cancel
Save