mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
feat(monospace): add get/set IPC handlers with safe validation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const { ipcMain } = require('electron');
|
||||
const store = require('../store');
|
||||
const { safeMonospaceSettings, DEFAULT_SETTINGS } = require('../settings/monospaceSettings');
|
||||
|
||||
function readCurrent() {
|
||||
return {
|
||||
monospaceFont: store.get('monospaceFont', DEFAULT_SETTINGS.monospaceFont),
|
||||
monospaceLigatures: store.get('monospaceLigatures', DEFAULT_SETTINGS.monospaceLigatures),
|
||||
};
|
||||
}
|
||||
|
||||
function register() {
|
||||
ipcMain.handle('get-monospace-settings', () => readCurrent());
|
||||
|
||||
ipcMain.handle('set-monospace-settings', (_event, partial) => {
|
||||
const safe = safeMonospaceSettings(partial || {});
|
||||
if (Object.prototype.hasOwnProperty.call(partial || {}, 'monospaceFont')) {
|
||||
store.set('monospaceFont', safe.monospaceFont);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(partial || {}, 'monospaceLigatures')) {
|
||||
store.set('monospaceLigatures', safe.monospaceLigatures);
|
||||
}
|
||||
return readCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { register, readCurrent };
|
||||
Reference in New Issue
Block a user