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);
|
2019-06-15 01:51:41 +10:00
|
|
|
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 = "";
|
|
|
|
}
|
2019-06-15 01:51:41 +10:00
|
|
|
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"]) {
|
2019-06-15 01:51:41 +10:00
|
|
|
e.sender.webContents.send('theme-json-create-complete', "");
|
2019-04-03 14:59:29 +11:00
|
|
|
} else {
|
2019-06-15 01:51:41 +10:00
|
|
|
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) {
|
2019-06-15 01:51:41 +10:00
|
|
|
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'));
|
2019-06-15 01:51:41 +10:00
|
|
|
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 {
|
2019-10-09 03:14:27 +11:00
|
|
|
var emphasized = secondary
|
|
|
|
}
|
|
|
|
if (json.props.TheDeskActive) {
|
|
|
|
var active = json.props.TheDeskActive
|
|
|
|
} else {
|
|
|
|
var active = primary
|
|
|
|
}
|
|
|
|
if (json.props.TheDeskModal) {
|
|
|
|
var modal = json.props.TheDeskModal
|
|
|
|
} else {
|
|
|
|
var modal = secondary
|
|
|
|
}
|
|
|
|
if (json.props.TheDeskBottom) {
|
|
|
|
var bottom = json.props.TheDeskBottom
|
|
|
|
} else {
|
|
|
|
var bottom = primary
|
|
|
|
}
|
|
|
|
if (json.props.TheDeskPostbox) {
|
|
|
|
var postbox = json.props.TheDeskPostbox
|
|
|
|
} else {
|
|
|
|
var postbox = primary
|
|
|
|
}
|
|
|
|
if (json.props.TheDeskSubcolor) {
|
|
|
|
var subcolor = json.props.TheDeskSubcolor
|
|
|
|
} else {
|
|
|
|
var subcolor = primary
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
|
|
|
} else {
|
2019-10-09 03:14:27 +11:00
|
|
|
var emphasized = primary
|
|
|
|
var acs = secondary
|
|
|
|
var active = primary
|
|
|
|
var modal = secondary
|
|
|
|
var bottom = primary
|
|
|
|
var postbox = primary
|
|
|
|
var subcolor = primary
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
var css = ".customtheme {--bg:" + secondary + ";--drag:" + drag + ";" +
|
|
|
|
"--color:" + text + ";--beforehover:" + beforehover + ";--modal:" +
|
2019-10-09 03:14:27 +11:00
|
|
|
modal + ";--subcolor:" + subcolor + ";--box:" + subcolor +
|
|
|
|
";--sidebar:" + bottom + ";--shared:" + emphasized + ";" +
|
|
|
|
"--notfbox:" + secondary + ";--emphasized:" + active + ";--his-data:" +
|
2019-04-03 14:59:29 +11:00
|
|
|
secondary +
|
2019-10-09 03:14:27 +11:00
|
|
|
";--active:" + active + ";--postbox:" + postbox + ";--modalfooter:" +
|
2019-04-03 14:59:29 +11:00
|
|
|
primary +
|
2019-10-09 03:14:27 +11:00
|
|
|
";--accentbtn:" + subcolor + ";--selected:" + selected + ";--selectedWithShare:" + selectedWithShare + "}"+
|
2019-08-21 01:36:47 +10:00
|
|
|
"--gray:" + gray + ";"+
|
|
|
|
".customtheme #imagemodal{background: url(\"../img/pixel.svg\");}";
|
2019-06-15 01:51:41 +10:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
2019-06-15 01:51:41 +10:00
|
|
|
e.sender.webContents.send('theme-json-list-response', themes);
|
2019-04-03 14:59:29 +11:00
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
exports.css = css;
|