thedesk/app/main/css.js

118 lines
3.9 KiB
JavaScript
Raw Normal View History

2019-04-03 14:59:29 +11:00
function css(mainWindow) {
const electron = require("electron");
const fs = require("fs");
const path = require('path')
var ipc = electron.ipcMain;
var JSON5 = require('json5');
const app = electron.app;
const join = require('path').join;
var customcss = join(app.getPath("userData"), "custom.css");
2019-05-19 17:39:30 +10:00
ipc.on('custom-css-create', function (e, arg) {
2019-04-03 14:59:29 +11:00
fs.writeFileSync(customcss, arg);
e.sender.webContents.send('custom-css-create-complete', "");
2019-04-03 14:59:29 +11:00
})
2019-05-19 17:39:30 +10:00
ipc.on('custom-css-request', function (e, arg) {
2019-04-03 14:59:29 +11:00
try {
var css = fs.readFileSync(customcss, 'utf8');
} catch (e) {
var css = "";
}
e.sender.webContents.send('custom-css-response', css);
2019-04-03 14:59:29 +11:00
})
2019-05-19 17:39:30 +10:00
ipc.on('theme-json-create', function (e, arg) {
2019-04-03 14:59:29 +11:00
var themecss = join(app.getPath("userData"), JSON5.parse(arg)["id"] +
".thedesktheme");
fs.writeFileSync(themecss, JSON.stringify(JSON5.parse(arg)));
if (JSON5.parse(arg)["id"]) {
e.sender.webContents.send('theme-json-create-complete', "");
2019-04-03 14:59:29 +11:00
} else {
e.sender.webContents.send('theme-json-create-complete', "error");
2019-04-03 14:59:29 +11:00
}
})
2019-05-19 17:39:30 +10:00
ipc.on('theme-json-delete', function (e, arg) {
2019-04-03 14:59:29 +11:00
var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
console.log(themecss);
2019-05-19 17:39:30 +10:00
fs.unlink(themecss, function (err) {
e.sender.webContents.send('theme-json-delete-complete', "");
2019-04-03 14:59:29 +11:00
});
})
2019-05-19 17:39:30 +10:00
ipc.on('theme-json-request', function (e, arg) {
2019-04-03 14:59:29 +11:00
var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
var json = JSON.parse(fs.readFileSync(themecss, 'utf8'));
e.sender.webContents.send('theme-json-response', json);
2019-04-03 14:59:29 +11:00
})
2019-05-19 17:39:30 +10:00
ipc.on('theme-css-request', function (e, arg) {
2019-04-03 14:59:29 +11:00
var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
try {
var json = JSON.parse(fs.readFileSync(themecss, 'utf8'));
var primary = json.vars.primary;
var secondary = json.vars.secondary;
var text = json.vars.text;
if (json.base == "light") {
var drag = "rgba(255, 255, 255, 0.8)";
var beforehover = "#757575";
2019-07-12 01:53:55 +10:00
var selected = "#3f3f3f"
var selectedWithShare = "#b2babd"
2019-08-21 01:36:47 +10:00
var gray = "#757575"
2019-04-03 14:59:29 +11:00
} else {
var drag = "rgba(0, 0, 0, 0.8)";
var beforehover = "#9e9e9e";
2019-07-12 01:53:55 +10:00
var selected = "#c0c0c0"
var selectedWithShare = "#003a30"
2019-08-21 01:36:47 +10:00
var gray = "#cccccc"
2019-04-03 14:59:29 +11:00
}
if (json.props) {
if (json.props.TheDeskAccent) {
var emphasized = json.props.TheDeskAccent
} else {
var emphasized = secondary;
}
} else {
var emphasized = primary;
}
var css = ".customtheme {--bg:" + secondary + ";--drag:" + drag + ";" +
"--color:" + text + ";--beforehover:" + beforehover + ";--modal:" +
secondary + ";--subcolor:" + primary + ";--box:" + primary +
";--sidebar:" + primary + ";--shared:" + emphasized + ";" +
"--notfbox:" + secondary + ";--emphasized:" + primary + ";--his-data:" +
secondary +
";--active:" + primary + ";--postbox:" + primary + ";--modalfooter:" +
primary +
2019-08-21 01:36:47 +10:00
";--accentbtn:" + primary + ";--selected:" + selected + ";--selectedWithShare:" + selectedWithShare + "}"+
"--gray:" + gray + ";"+
".customtheme #imagemodal{background: url(\"../img/pixel.svg\");}";
e.sender.webContents.send('theme-css-response', css);
2019-04-03 14:59:29 +11:00
} catch (e) {
var css = "";
}
})
2019-05-19 17:39:30 +10:00
ipc.on('theme-json-list', function (e, arg) {
fs.readdir(app.getPath("userData"), function (err, files) {
2019-10-09 00:04:51 +11:00
if (err || !files) throw err;
2019-05-19 17:39:30 +10:00
var fileList = files.filter(function (file) {
2019-10-09 00:04:51 +11:00
if(file.match(/\.thedesktheme$/)){
var tfile = join(app.getPath("userData"), file)
return fs.statSync(tfile).isFile() && /.*\.thedesktheme$/.test(tfile)
}else{
return null
}
2019-04-03 14:59:29 +11:00
})
var themes = [];
for (var i = 0; i < fileList.length; i++) {
var themecss = join(app.getPath("userData"), fileList[i]);
var json = JSON.parse(fs.readFileSync(themecss, 'utf8'));
themes.push({
name: json.name,
id: json.id
})
}
e.sender.webContents.send('theme-json-list-response', themes);
2019-04-03 14:59:29 +11:00
});
})
}
exports.css = css;