Skip to content

Commit a90dc0c

Browse files
authored
Custom css: Add a setting option for custom css.
This PR adds an option to inject custom CSS. Fixes - #432.
1 parent 028bc02 commit a90dc0c

File tree

3 files changed

+113
-5
lines changed

3 files changed

+113
-5
lines changed

app/renderer/css/preference.css

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ body {
1313

1414
kbd {
1515
display: inline-block;
16-
border: 1px solid #ccc ;
16+
border: 1px solid #ccc;
1717
border-radius: 3px;
1818
font-size: 15px;
1919
font-family: Courier New, Courier, monospace;
@@ -271,8 +271,7 @@ img.server-info-icon {
271271

272272
.settings-card:hover {
273273
border-left: 8px solid #bcbcbc;
274-
box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),
275-
0 2px 0px 0px rgba(0,0,0,0.12);
274+
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 0px 0px rgba(0, 0, 0, 0.12);
276275
}
277276

278277
.hidden {
@@ -320,7 +319,8 @@ i.open-tab-button {
320319
cursor: pointer;
321320
}
322321

323-
.reset-data-button {
322+
.reset-data-button,
323+
.custom-css-button {
324324
display: inline-block;
325325
border: none;
326326
padding: 10px;
@@ -331,11 +331,29 @@ i.open-tab-button {
331331
text-decoration: none;
332332
}
333333

334+
.css-delete-action {
335+
margin-bottom: 10px;
336+
}
337+
334338
.reset-data-button:hover {
335339
background-color: #3c9f8d;
336340
color: #fff;
337341
}
338342

343+
.selected-css-path {
344+
background: #eeeeee;
345+
padding: 10px;
346+
margin-top: 10px;
347+
margin-right: 10px;
348+
display: flex;
349+
width: 90%;
350+
justify-content: space-between;
351+
}
352+
353+
#remove-custom-css {
354+
align-items: flex-end;
355+
}
356+
339357
#server-info-container {
340358
min-height: calc(100% - 260px);
341359
}
@@ -412,4 +430,19 @@ input.toggle-round:checked+label:before {
412430

413431
input.toggle-round:checked+label:after {
414432
margin-left: 25px;
433+
}
434+
435+
436+
/* responsive grid */
437+
438+
@media (max-width: 650px) {
439+
.selected-css-path {
440+
margin-right: 15px;
441+
}
442+
#css-delete-action {
443+
margin-left: 10px;
444+
}
445+
#css-delete-action span {
446+
display: none;
447+
}
415448
}

app/renderer/js/components/webview.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const DomainUtil = require(__dirname + '/../utils/domain-util.js');
77
const ConfigUtil = require(__dirname + '/../utils/config-util.js');
88
const SystemUtil = require(__dirname + '/../utils/system-util.js');
99
const LinkUtil = require(__dirname + '/../utils/link-util.js');
10-
const { shell, app } = require('electron').remote;
10+
const { shell, app, dialog } = require('electron').remote;
1111

1212
const BaseComponent = require(__dirname + '/../components/base.js');
1313

@@ -21,6 +21,7 @@ class WebView extends BaseComponent {
2121
this.zoomFactor = 1.0;
2222
this.loading = false;
2323
this.badgeCount = 0;
24+
this.customCSS = ConfigUtil.getConfigItem('customCSS');
2425
}
2526

2627
template() {
@@ -139,6 +140,21 @@ class WebView extends BaseComponent {
139140
this.props.onTitleChange();
140141
// Injecting preload css in webview to override some css rules
141142
this.$el.insertCSS(fs.readFileSync(path.join(__dirname, '/../../css/preload.css'), 'utf8'));
143+
144+
// get customCSS again from config util to avoid warning user again
145+
this.customCSS = ConfigUtil.getConfigItem('customCSS');
146+
if (this.customCSS) {
147+
if (!fs.existsSync(this.customCSS)) {
148+
this.customCSS = null;
149+
ConfigUtil.setConfigItem('customCSS', null);
150+
151+
const errMsg = 'The custom css previously set is deleted!';
152+
dialog.showErrorBox('custom css file deleted!', errMsg);
153+
return;
154+
}
155+
156+
this.$el.insertCSS(fs.readFileSync(path.resolve(__dirname, this.customCSS), 'utf8'));
157+
}
142158
}
143159

144160
focus() {

app/renderer/js/pages/preference/general-section.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ class GeneralSection extends BaseSection {
6969
<div class="setting-control"></div>
7070
</div>
7171
</div>
72+
<div class="title">Add custom CSS</div>
73+
<div class="settings-card">
74+
<div class="setting-row" id="add-custom-css">
75+
<div class="setting-description">
76+
This will inject the selected css stylesheet in all the added accounts
77+
</div>
78+
<button class="custom-css-button blue">Add</button>
79+
</div>
80+
<div class="setting-row" id="remove-custom-css">
81+
<div class="setting-description">
82+
<div class="selected-css-path" id="custom-css-path">${ConfigUtil.getConfigItem('customCSS')}</div>
83+
</div>
84+
<div class="action red" id="css-delete-action">
85+
<i class="material-icons">indeterminate_check_box</i>
86+
<span>Delete</span>
87+
</div>
88+
</div>
89+
</div>
7290
<div class="title">Reset Application Data</div>
7391
<div class="settings-card">
7492
<div class="setting-row" id="resetdata-option">
@@ -93,6 +111,9 @@ class GeneralSection extends BaseSection {
93111
this.showDesktopNotification();
94112
this.enableSpellchecker();
95113
this.minimizeOnStart();
114+
this.addCustomCSS();
115+
this.showCustomCSSPath();
116+
this.removeCustomCSS();
96117

97118
// Platform specific settings
98119
// Flashing taskbar on Windows
@@ -232,6 +253,22 @@ class GeneralSection extends BaseSection {
232253
});
233254
}
234255

256+
customCssDialog() {
257+
const showDialogOptions = {
258+
title: 'Select file',
259+
defaultId: 1,
260+
properties: ['openFile'],
261+
filters: [{ name: 'CSS file', extensions: ['css'] }]
262+
};
263+
264+
dialog.showOpenDialog(showDialogOptions, selectedFile => {
265+
if (selectedFile) {
266+
ConfigUtil.setConfigItem('customCSS', selectedFile[0]);
267+
ipcRenderer.send('forward-message', 'hard-reload');
268+
}
269+
});
270+
}
271+
235272
updateResetDataOption() {
236273
const resetDataButton = document.querySelector('#resetdata-option .reset-data-button');
237274
resetDataButton.addEventListener('click', () => {
@@ -251,6 +288,28 @@ class GeneralSection extends BaseSection {
251288
});
252289
}
253290

291+
addCustomCSS() {
292+
const customCSSButton = document.querySelector('#add-custom-css .custom-css-button');
293+
customCSSButton.addEventListener('click', () => {
294+
this.customCssDialog();
295+
});
296+
}
297+
298+
showCustomCSSPath() {
299+
if (!ConfigUtil.getConfigItem('customCSS')) {
300+
const cssPATH = document.getElementById('remove-custom-css');
301+
cssPATH.style.display = 'none';
302+
}
303+
}
304+
305+
removeCustomCSS() {
306+
const removeCSSButton = document.getElementById('css-delete-action');
307+
removeCSSButton.addEventListener('click', () => {
308+
ConfigUtil.setConfigItem('customCSS');
309+
ipcRenderer.send('forward-message', 'hard-reload');
310+
});
311+
}
312+
254313
}
255314

256315
module.exports = GeneralSection;

0 commit comments

Comments
 (0)