Skip to content

Commit

Permalink
Merge pull request #14 from mbuslenko/feature/reset-to-default-settings
Browse files Browse the repository at this point in the history
⚙️ ability to reset to factory settings
  • Loading branch information
mbuslenko committed Jul 31, 2022
2 parents 88b7f5b + 9dbfbcf commit 65d59ba
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Nodetools",
"version": "0.1.9",
"version": "0.1.10",
"description": "Personal all-hands assistant.",
"main": "./app/main.js",
"compilerOptions": {
Expand Down
36 changes: 25 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import settings, {
changeSetting,
changeSettings,
initSettings,
setDefaultSettings,
} from './settings';
import { ShortcutsSettings } from './settings/settings.types';
import { openWebURL } from './shared/utils/open-website';
Expand All @@ -27,14 +28,12 @@ require('update-electron-app')({
repo: 'mbuslenko/nodetools',
});


/**
* This prevents the app to be opened twice
*/
const gotTheLock = app.requestSingleInstanceLock()
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) app.quit();


/**
* Create window function starts the browser window
* in native mode
Expand Down Expand Up @@ -104,7 +103,7 @@ ipcMain.on('change-transliteration-language', (_event, arg) => {
}

changeSetting('transliterate', arg);
})
});

ipcMain.on('change-convert-currencies-settings', (_event, arg) => {
if (process.platform === 'darwin') {
Expand Down Expand Up @@ -156,6 +155,10 @@ ipcMain.on('change-air-alerts-state', (_event, arg) => {
changeSetting('airAlerts', { enabled: true, state: arg.state });
});

ipcMain.on('set-default-settings', (_event, _arg) => {
setDefaultSettings()
})

/**
* Generate and configure shortcuts
* and check for permissions on the macOS
Expand Down Expand Up @@ -202,7 +205,7 @@ app.whenReady().then(async () => {
await InlineDomain.transliterateText();

if (!selectedLanguage) {
createWindow('../src/views/transliterate-settings.html')
createWindow('../src/views/transliterate-settings.html');
}
});

Expand Down Expand Up @@ -290,11 +293,22 @@ app.whenReady().then(() => {
},
]
: []),
{ label: 'Separator', type: 'separator' },
{
label: 'Errors',
role: 'window',
click: () => createWindow('../src/views/errors-list.html'),
},
{ label: 'Separator', type: 'separator' },
{
label: 'Set default settings',
role: 'window',
click: () =>
createWindow('../src/views/set-default-settings-dialogue.html', {
height: 420,
width: 600,
}),
},
],
},
{ label: 'Separator', type: 'separator' },
Expand Down Expand Up @@ -422,18 +436,18 @@ ipcMain.on('upload-file', (_event, arg) => {

switch (arg.task) {
case 'convert':
createWindow('../src/views/convert-file.html')
createWindow('../src/views/convert-file.html');
break;
case 'encrypt':
createWindow('../src/views/encrypt-file.html')
createWindow('../src/views/encrypt-file.html');
break;
case 'decrypt':
createWindow('../src/views/decrypt-file.html')
createWindow('../src/views/decrypt-file.html');
}
});

ipcMain.handle('get-file-path', (_event, _arg) => {
return filePath
return filePath;
});

ipcMain.on('convert-file', async (_event, arg) => {
Expand All @@ -446,7 +460,7 @@ ipcMain.on('encrypt-file', async (_event, arg) => {
const filesDomain = new FilesDomain();

await filesDomain.encryptFile(filePath, arg.password);
})
});

ipcMain.handle('decrypt-file', async (_event, arg) => {
const filesDomain = new FilesDomain();
Expand All @@ -457,7 +471,7 @@ ipcMain.handle('decrypt-file', async (_event, arg) => {
} catch {
return false;
}
})
});

/**
* Close window handler for macOS
Expand Down
10 changes: 7 additions & 3 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ const defaultSettings: Settings = {

const settings = new Store<Settings>();

export const setDefaultSettings = () => {
settings.store = defaultSettings;
}

export const initSettings = async () => {
const currentSettings = settings.store as Settings;

//if (!currentSettings.shortcuts) {
settings.store = defaultSettings;
if (!currentSettings.shortcuts) {
setDefaultSettings();

// if settings are not set, so it's a new user
await axios.request({
Expand All @@ -51,7 +55,7 @@ export const initSettings = async () => {
platform: process.platform,
},
});
//}
}

settings.set('restartToApplyChanges', false);
};
Expand Down
161 changes: 161 additions & 0 deletions src/views/set-default-settings-dialogue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>nodetools</title>
<style>
* {
font-family: sans-serif;
}

body {
--nodetools: #0058f7;
--fg: black;
--bg: white;
background: #070e27;
color: white;
margin-right: 5vh;
margin-left: 5vh;
}

.bodyClass {
margin-right: 20vh;
margin-left: 23vh;
}

.header {
display: flex;
justify-content: space-between;
margin-top: 15vh;
margin-bottom: 10vh;
margin-left: 23vh;
}

.logo {
width: 35vh;
}

.strong {
font-weight: bold;
}

.blue {
color: #7e8bb6;
}

.description {
margin-left: 50vh;
color: grey;
font-weight: lighter;
font-size: 12px;
}

.footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
text-align: center;
padding: 1rem;
box-sizing: border-box;
font-size: 12px;
}

.five {
margin-bottom: 5vh;
}

.submit-button {
display: flex;
justify-content: center;
margin-top: 7vh;
}

.buttons {
display: flex;
justify-content: space-between;
}
</style>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor"
crossorigin="anonymous"
/>
</head>
<body class="bg-black">
<div class="header">
<svg
viewBox="0 0 169 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="logo"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M6.43936 3.08946C6.21815 3.16951 5.46355 3.88003 3.19962 6.14009C1.57638 7.76055 0.194903 9.18501 0.129693 9.30563C0.0611196 9.43232 0.0125774 9.68695 0.0146975 9.90839C0.0177679 10.2367 0.071135 10.3785 0.385928 10.8953C1.19119 12.2173 1.50276 13.082 1.65212 14.4098C1.83751 16.0572 1.44662 17.6603 0.472119 19.2493C0.0322428 19.9666 -0.0716402 20.3352 0.043428 20.7699C0.113829 21.036 0.509184 21.4616 3.09383 24.0535C4.72774 25.692 6.17604 27.0848 6.31391 27.1503C6.48535 27.2316 6.6945 27.2598 6.97603 27.2395C7.32738 27.214 7.49179 27.1443 8.10025 26.7628C9.39232 25.9526 10.5608 25.6232 12.1375 25.6247C13.6416 25.6261 14.8135 25.9372 15.9617 26.6397C16.2708 26.8289 16.6377 27.0443 16.7769 27.1184C17.1093 27.2953 17.66 27.2925 18.0072 27.1121C18.3575 26.9301 24.0577 21.2142 24.1594 20.9429C24.2018 20.8298 24.2365 20.5643 24.2365 20.3531C24.2365 20.0309 24.189 19.8932 23.9416 19.4988C23.4246 18.6743 22.9987 17.7343 22.8015 16.9817C22.6385 16.3599 22.6094 16.0922 22.6064 15.1906C22.6013 13.6657 22.9092 12.4967 23.6231 11.3299C23.8123 11.0208 24.0278 10.6538 24.1018 10.5147C24.2648 10.2084 24.2806 9.56435 24.1319 9.2837C24.0744 9.17514 22.6845 7.74783 21.0432 6.11187C18.8353 3.91117 18.002 3.12514 17.8397 3.0902C17.7191 3.06417 17.5774 3.02952 17.5247 3.01307C17.3052 2.94471 16.7628 3.14875 16.1628 3.52539C14.9222 4.30433 13.6696 4.65926 12.1527 4.66182C10.6725 4.66438 9.44941 4.33635 8.28162 3.62357C7.94965 3.421 7.59582 3.21338 7.4953 3.16213C7.19082 3.00693 6.75094 2.97666 6.43936 3.08946ZM8.62478 12.3671C10.3615 13.2255 10.8915 15.451 9.72787 16.999C8.14799 19.1007 4.80962 18.3737 4.23786 15.8034C3.89236 14.2507 4.79032 12.6876 6.31867 12.1812C6.63287 12.077 6.88502 12.0518 7.40604 12.0728C8.00996 12.097 8.1436 12.1293 8.62478 12.3671ZM18.3465 12.3265C20.1055 13.1496 20.7086 15.2457 19.6493 16.8547C18.7737 18.1847 17.043 18.6069 15.592 17.8444C14.9938 17.5301 14.5766 17.0854 14.2683 16.4334C13.9793 15.8223 13.9102 14.8518 14.1114 14.2296C14.3672 13.4384 14.9528 12.7461 15.6763 12.3796C16.2108 12.1086 16.5153 12.0494 17.2311 12.0768C17.7548 12.0969 17.949 12.1404 18.3465 12.3265Z"
fill="white"
/>
<path
d="M42.16 24V6.48H47.752L55.12 21.168H55.912L55.432 21.6V6.48H58.648V24H53.032L45.664 9.312H44.848L45.328 8.88V24H42.16ZM68.4925 24.456C67.3405 24.456 66.3245 24.272 65.4445 23.904C64.5645 23.536 63.8205 23.04 63.2125 22.416C62.6045 21.776 62.1405 21.056 61.8205 20.256C61.5165 19.456 61.3645 18.624 61.3645 17.76V17.256C61.3645 16.36 61.5245 15.512 61.8445 14.712C62.1805 13.896 62.6525 13.176 63.2605 12.552C63.8845 11.912 64.6365 11.416 65.5165 11.064C66.3965 10.696 67.3885 10.512 68.4925 10.512C69.5965 10.512 70.5885 10.696 71.4685 11.064C72.3485 11.416 73.0925 11.912 73.7005 12.552C74.3245 13.176 74.7965 13.896 75.1165 14.712C75.4365 15.512 75.5965 16.36 75.5965 17.256V17.76C75.5965 18.624 75.4365 19.456 75.1165 20.256C74.8125 21.056 74.3565 21.776 73.7485 22.416C73.1405 23.04 72.3965 23.536 71.5165 23.904C70.6365 24.272 69.6285 24.456 68.4925 24.456ZM68.4925 21.6C69.3085 21.6 69.9965 21.424 70.5565 21.072C71.1165 20.704 71.5405 20.216 71.8285 19.608C72.1165 18.984 72.2605 18.28 72.2605 17.496C72.2605 16.696 72.1085 15.992 71.8045 15.384C71.5165 14.76 71.0845 14.272 70.5085 13.92C69.9485 13.552 69.2765 13.368 68.4925 13.368C67.7085 13.368 67.0285 13.552 66.4525 13.92C65.8925 14.272 65.4605 14.76 65.1565 15.384C64.8525 15.992 64.7005 16.696 64.7005 17.496C64.7005 18.28 64.8445 18.984 65.1325 19.608C65.4365 20.216 65.8685 20.704 66.4285 21.072C66.9885 21.424 67.6765 21.6 68.4925 21.6ZM83.4376 24.432C82.5256 24.432 81.6856 24.264 80.9176 23.928C80.1496 23.592 79.4856 23.12 78.9256 22.512C78.3656 21.904 77.9336 21.2 77.6296 20.4C77.3256 19.584 77.1736 18.704 77.1736 17.76V17.256C77.1736 16.328 77.3176 15.456 77.6056 14.64C77.9096 13.824 78.3256 13.112 78.8536 12.504C79.3976 11.896 80.0456 11.424 80.7976 11.088C81.5656 10.736 82.4136 10.56 83.3416 10.56C84.3656 10.56 85.2616 10.784 86.0296 11.232C86.8136 11.664 87.4376 12.32 87.9016 13.2C88.3656 14.08 88.6216 15.184 88.6696 16.512L87.6856 15.36V6.48H91.0216V24H88.3816V18.456H88.9576C88.9096 19.784 88.6376 20.896 88.1416 21.792C87.6456 22.672 86.9896 23.336 86.1736 23.784C85.3736 24.216 84.4616 24.432 83.4376 24.432ZM84.1816 21.624C84.8376 21.624 85.4376 21.48 85.9816 21.192C86.5256 20.888 86.9576 20.456 87.2776 19.896C87.6136 19.32 87.7816 18.648 87.7816 17.88V16.92C87.7816 16.152 87.6136 15.512 87.2776 15C86.9416 14.472 86.5016 14.072 85.9576 13.8C85.4136 13.512 84.8216 13.368 84.1816 13.368C83.4616 13.368 82.8216 13.544 82.2616 13.896C81.7176 14.232 81.2856 14.712 80.9656 15.336C80.6616 15.96 80.5096 16.688 80.5096 17.52C80.5096 18.352 80.6696 19.08 80.9896 19.704C81.3096 20.312 81.7416 20.784 82.2856 21.12C82.8456 21.456 83.4776 21.624 84.1816 21.624ZM100.171 24.456C99.0508 24.456 98.0668 24.264 97.2188 23.88C96.3868 23.496 95.6908 22.984 95.1308 22.344C94.5868 21.688 94.1708 20.96 93.8828 20.16C93.6108 19.36 93.4748 18.544 93.4748 17.712V17.256C93.4748 16.392 93.6108 15.56 93.8828 14.76C94.1708 13.944 94.5868 13.224 95.1308 12.6C95.6908 11.96 96.3788 11.456 97.1948 11.088C98.0108 10.704 98.9548 10.512 100.027 10.512C101.435 10.512 102.611 10.824 103.555 11.448C104.515 12.056 105.235 12.864 105.715 13.872C106.195 14.864 106.435 15.936 106.435 17.088V18.288H94.8908V16.248H104.347L103.315 17.256C103.315 16.424 103.195 15.712 102.955 15.12C102.715 14.528 102.347 14.072 101.851 13.752C101.371 13.432 100.763 13.272 100.027 13.272C99.2908 13.272 98.6668 13.44 98.1548 13.776C97.6428 14.112 97.2508 14.6 96.9788 15.24C96.7228 15.864 96.5948 16.616 96.5948 17.496C96.5948 18.312 96.7228 19.04 96.9788 19.68C97.2348 20.304 97.6268 20.8 98.1548 21.168C98.6828 21.52 99.3548 21.696 100.171 21.696C100.987 21.696 101.651 21.536 102.163 21.216C102.675 20.88 103.003 20.472 103.147 19.992H106.219C106.027 20.888 105.659 21.672 105.115 22.344C104.571 23.016 103.875 23.536 103.027 23.904C102.195 24.272 101.243 24.456 100.171 24.456ZM114.406 24.168C113.206 24.168 112.214 24.016 111.43 23.712C110.662 23.392 110.086 22.864 109.702 22.128C109.318 21.376 109.126 20.368 109.126 19.104L109.15 7.296H112.27L112.246 19.32C112.246 19.96 112.414 20.456 112.75 20.808C113.102 21.144 113.598 21.312 114.238 21.312H116.278V24.168H114.406ZM107.062 13.416V10.968H116.278V13.416H107.062ZM124.791 24.456C123.639 24.456 122.623 24.272 121.743 23.904C120.863 23.536 120.119 23.04 119.511 22.416C118.903 21.776 118.439 21.056 118.119 20.256C117.815 19.456 117.663 18.624 117.663 17.76V17.256C117.663 16.36 117.823 15.512 118.143 14.712C118.479 13.896 118.951 13.176 119.559 12.552C120.183 11.912 120.935 11.416 121.815 11.064C122.695 10.696 123.687 10.512 124.791 10.512C125.895 10.512 126.887 10.696 127.767 11.064C128.647 11.416 129.391 11.912 129.999 12.552C130.623 13.176 131.095 13.896 131.415 14.712C131.735 15.512 131.895 16.36 131.895 17.256V17.76C131.895 18.624 131.735 19.456 131.415 20.256C131.111 21.056 130.655 21.776 130.047 22.416C129.439 23.04 128.695 23.536 127.815 23.904C126.935 24.272 125.927 24.456 124.791 24.456ZM124.791 21.6C125.607 21.6 126.295 21.424 126.855 21.072C127.415 20.704 127.839 20.216 128.127 19.608C128.415 18.984 128.559 18.28 128.559 17.496C128.559 16.696 128.407 15.992 128.103 15.384C127.815 14.76 127.383 14.272 126.807 13.92C126.247 13.552 125.575 13.368 124.791 13.368C124.007 13.368 123.327 13.552 122.751 13.92C122.191 14.272 121.759 14.76 121.455 15.384C121.151 15.992 120.999 16.696 120.999 17.496C120.999 18.28 121.143 18.984 121.431 19.608C121.735 20.216 122.167 20.704 122.727 21.072C123.287 21.424 123.975 21.6 124.791 21.6ZM140.6 24.456C139.448 24.456 138.432 24.272 137.552 23.904C136.672 23.536 135.928 23.04 135.32 22.416C134.712 21.776 134.248 21.056 133.928 20.256C133.624 19.456 133.472 18.624 133.472 17.76V17.256C133.472 16.36 133.632 15.512 133.952 14.712C134.288 13.896 134.76 13.176 135.368 12.552C135.992 11.912 136.744 11.416 137.624 11.064C138.504 10.696 139.496 10.512 140.6 10.512C141.704 10.512 142.696 10.696 143.576 11.064C144.456 11.416 145.2 11.912 145.808 12.552C146.432 13.176 146.904 13.896 147.224 14.712C147.544 15.512 147.704 16.36 147.704 17.256V17.76C147.704 18.624 147.544 19.456 147.224 20.256C146.92 21.056 146.464 21.776 145.856 22.416C145.248 23.04 144.504 23.536 143.624 23.904C142.744 24.272 141.736 24.456 140.6 24.456ZM140.6 21.6C141.416 21.6 142.104 21.424 142.664 21.072C143.224 20.704 143.648 20.216 143.936 19.608C144.224 18.984 144.368 18.28 144.368 17.496C144.368 16.696 144.216 15.992 143.912 15.384C143.624 14.76 143.192 14.272 142.616 13.92C142.056 13.552 141.384 13.368 140.6 13.368C139.816 13.368 139.136 13.552 138.56 13.92C138 14.272 137.568 14.76 137.264 15.384C136.96 15.992 136.808 16.696 136.808 17.496C136.808 18.28 136.952 18.984 137.24 19.608C137.544 20.216 137.976 20.704 138.536 21.072C139.096 21.424 139.784 21.6 140.6 21.6ZM150.313 24V6.48H153.649V24H150.313ZM148.681 8.976V6.48H153.649V8.976H148.681ZM161.706 24.408C159.914 24.408 158.506 24.032 157.482 23.28C156.474 22.512 155.946 21.456 155.898 20.112H158.898C158.946 20.56 159.194 20.968 159.642 21.336C160.09 21.704 160.794 21.888 161.754 21.888C162.554 21.888 163.186 21.744 163.65 21.456C164.13 21.168 164.37 20.776 164.37 20.28C164.37 19.848 164.186 19.504 163.818 19.248C163.466 18.992 162.858 18.824 161.994 18.744L160.842 18.624C159.386 18.464 158.266 18.048 157.482 17.376C156.698 16.704 156.306 15.808 156.306 14.688C156.306 13.792 156.53 13.04 156.978 12.432C157.426 11.824 158.042 11.368 158.826 11.064C159.626 10.744 160.538 10.584 161.562 10.584C163.162 10.584 164.458 10.936 165.45 11.64C166.442 12.344 166.962 13.376 167.01 14.736H164.01C163.978 14.288 163.754 13.904 163.338 13.584C162.922 13.264 162.322 13.104 161.538 13.104C160.834 13.104 160.29 13.24 159.906 13.512C159.522 13.784 159.33 14.136 159.33 14.568C159.33 14.984 159.482 15.304 159.786 15.528C160.106 15.752 160.618 15.904 161.322 15.984L162.474 16.104C164.01 16.264 165.21 16.688 166.074 17.376C166.954 18.064 167.394 18.992 167.394 20.16C167.394 21.024 167.154 21.776 166.674 22.416C166.21 23.04 165.554 23.528 164.706 23.88C163.858 24.232 162.858 24.408 161.706 24.408Z"
fill="white"
/>
</svg>
</div>

<div class="bodyClass text-white">
<h3 class="strong">Are you sure?</h3>
<p>
You are about to reset your settings to the factory defaults. This
action cannot be undone.
</p>
<div class="buttons">
<button
type="button"
class="btn btn-dark"
onclick="setDefaultSettings()"
>
Yes, I am totally sure
</button>
<button type="button" class="btn btn-dark" onclick="window.close()">
No, leave the current settings
</button>
</div>
</div>

<div class="footer text-white-50">
<p>
* To close this window press the
<span class="strong">Escape</span> button
</p>
</div>

<script>
window.onkeydown = (e) => {
if (e.keyCode === 27) {
window.close();
}
};
const { ipcRenderer } = require('electron');

function openUnited24Website() {
const shell = require('electron').shell;

shell.openExternal('https://u24.gov.ua/');
window.close();
}

function setDefaultSettings() {
ipcRenderer.send('set-default-settings');
window.close();
}
</script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
crossorigin="anonymous"
></script>
</body>
<script></script>
</html>

0 comments on commit 65d59ba

Please sign in to comment.