Browse Source

Added SASS compilation, and started building out some systems.

master
Bryan Miller 4 years ago
parent
commit
e73abb5828
No known key found for this signature in database
7 changed files with 203 additions and 10 deletions
  1. +154
    -0
      app/config.js
  2. +21
    -0
      app/index.js
  3. +13
    -9
      main.js
  4. +4
    -1
      package.json
  5. +1
    -0
      view/index.html
  6. +3
    -0
      view/sass/colors.scss
  7. +7
    -0
      view/sass/main.scss

+ 154
- 0
app/config.js View File

@@ -0,0 +1,154 @@

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

const CONF_FILE_NAME = 'saam.conf.json';

const readFile = (path) => {
return new Promise((res, rej) => {
fs.readFile(path, 'utf8', (err, data) => {
res((err) ? null : data);
});
});
};


let confdata = (async () => {
let confPaths = [
path.join(app.getPath('userData'), CONF_FILE_NAME),
path.join(app.getPath('home'), '.saam', CONF_FILE_NAME),
path.join(app.getAppPath(), CONF_FILE_NAME)
];
for (let i=0; i < confPaths.length; i++){
let res = await readFile(confPaths[i]);
if (res !== null){
try{
return JSON.parse(res);
} catch (e) {
console.log("WARNING: Malformed data at ", confPaths[i]);
}
}
}
return {};
})();


class ConfigNode{
constructor(parent = null, data = null, name = ""){
this.__parent = null;
this.__name = "";
this.__data = confdata;
if ((parent instanceof ConfigNode) && (typeof data === 'object') && parent.hasSection(name)){
this.__parent = parent;
this.__name = name;
this.__data = data
}
}

getRoot(){
if (this.__parent !== null)
return this.__parent.getRoot();
return this;
}

getParent(){
return this.__parent;
}

getName(fullName = false){
if (fulleName && this.__parent !== null){
return this.__parent.getName(true) + "." + this.__name;
}
return this.__name;
}

sections(){
let keys = Object.keys(this.__data);
let list = [];
for (let i=0; i < keys.length; i++){
if (typeof this.__data[keys[i]] === 'object')
list.push(keys[i]);
}
return list;
}

keys(){
let keys = Object.keys(this.__data);
let list = [];
for (let i=0; i < keys.length; i++){
if (typeof this.__data[keys[i]] !== 'object')
list.push(keys[i]);
}
return list;
}

hasSection(name){
return ((name in this.__data) && (typeof this.__data[name] === 'object'));
}

getSection(name, noErrorIfExists = false){
if (this.hasSection(name)){
return new ConfigNode(this, this.__data[name], name);
} else if (noErrorIfExists){
return null;
}
throw new Error("No Section '" + name + "' exists.");
}

addSection(name, noErrorIfExists = false){
if (!(name in this.__data)){
this.__data[name] = {};
} else if (!noErrorIfExists){
throw new Error("Value or Section '" + name + "' already exists.");
}
return this;
}

removeSection(name, noErrorOnFail = false){
if (this.hasSection(name)){
if (Object.keys(this.__data[name]).length <= 0){
delete this.__data[name];
} else if (!noErrorOnFail){
throw new Error("Section '" + name + "' is not empty. Cannot remove.");
}
}
return this;
}

hasValue(name){
return ((name in this.__data) && (typeof this.__data[name] !== 'object'));
}

getValue(name, defval = null){
return (name in this.__data) ? this.__data[name] : defval;
}

setValue(name, value){
if (!this.hasSection(name)){
this.__data[name] = value;
} else {
throw new Error("Name '" + name + "' defined as a section. Cannot override.");
}
return this;
}

clearValue(name){
if (!this.hasSection(name)){
if (name in this.__data)
delete this.__data[name];
} else {
throw new Error("Name '" + name + "' defined as a section. Cannot remove.");
}
return this;
}

toJSON(){
JSON.stringify(confdata);
}

}


module.exports = ConfigNode;


+ 21
- 0
app/index.js View File

@@ -0,0 +1,21 @@


const sass = require('sass');

console.log("Hello there")
sass.render({file: 'view/sass/main.scss'}, (err, res) => {
if (err){
console.log(err);
return;
}
console.log(res.css.toString());
let style = document.createElement('style');
style.innerHTML = res.css.toString();

let head = document.getElementsByTagName('head');
if (head.length > 0)
head = head[0]; // There should really only be one head... we're not a hydra!!!
head.appendChild(style);
});



+ 13
- 9
main.js View File

@@ -1,21 +1,25 @@
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');

let win;
let mainWindow;

function createWindow(){
win = new BrowserWindow();
win.loadURL(url.format({
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'view/index.html'),
protocol: 'file',
slashes: true
}));

win.webContents.openDevTools();
win.on('closed', ()=>{win = null;})
mainWindow.webContents.openDevTools();
mainWindow.on('closed', ()=>{mainWindow = null;})
}


@@ -26,7 +30,7 @@ app.on('window-all-closed', ()=>{
});

app.on('activate', ()=> {
if (win === null){
if (mainWindow === null){
createWindow();
}
});

+ 4
- 1
package.json View File

@@ -5,7 +5,10 @@
"devDependencies": {
"electron": "^10.1.2"
},
"scripts":{
"scripts": {
"start": "electron ."
},
"dependencies": {
"sass": "^1.26.11"
}
}

+ 1
- 0
view/index.html View File

@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SAaM</title>
<script type="text/javascript" src="../app/index.js"></script>
</head>
<body>
More to come

+ 3
- 0
view/sass/colors.scss View File

@@ -0,0 +1,3 @@

$COLOR-MAIN: #fa00af;


+ 7
- 0
view/sass/main.scss View File

@@ -0,0 +1,7 @@

@import 'colors';

body {
background-color: $COLOR_MAIN;
}


Loading…
Cancel
Save