Skip to content

Commit 800b041

Browse files
authored
Merge pull request #31 from CodeDead/feature/theme-switch
Feature/theme switch
2 parents a330d7a + 2b896a7 commit 800b041

File tree

22 files changed

+180
-63
lines changed

22 files changed

+180
-63
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
build
55
src/serviceWorker.js
66
README.md
7+
.eslintcache

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ dist/*
3333
!.yarn/sdks
3434
!.yarn/versions
3535
.pnp.*
36+
37+
.eslintcache

public/electron.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const createWindow = () => {
1515
mainWindow = new BrowserWindow({
1616
webPreferences: {
1717
nodeIntegration: true,
18+
contextIsolation: false,
1819
},
1920
frame: false,
2021
title: 'DeadHash',
@@ -26,13 +27,13 @@ const createWindow = () => {
2627
fileWorkerWindow = new BrowserWindow({
2728
show: isDev,
2829
icon: path.join(__dirname, '../build/logo512.png'),
29-
webPreferences: { nodeIntegration: true },
30+
webPreferences: { nodeIntegration: true, contextIsolation: false },
3031
});
3132

3233
textWorkerWindow = new BrowserWindow({
3334
show: isDev,
3435
icon: path.join(__dirname, '../build/logo512.png'),
35-
webPreferences: { nodeIntegration: true },
36+
webPreferences: { nodeIntegration: true, contextIsolation: false },
3637
});
3738

3839
if (isDev) {

src/components/App/index.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,14 @@ const App = () => {
2626
const [, dispatch] = useContext(CryptoContext);
2727

2828
const enabled = state.canDragDrop;
29-
let { themeIndex } = state;
30-
31-
let themeType = 'light';
32-
if (themeIndex === 8) {
33-
themeType = 'dark';
34-
themeIndex = 2;
35-
}
29+
const { themeIndex, themeStyle } = state;
3630

3731
const color = ThemeSelector(themeIndex);
3832

3933
const theme = createMuiTheme({
4034
palette: {
4135
primary: color,
42-
type: themeType,
36+
type: themeStyle,
4337
},
4438
});
4539

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
import React from 'react';
2-
import { Item, Menu, MenuProvider } from 'react-contexify';
2+
import { Item, Menu, useContextMenu } from 'react-contexify';
33
import CopyIcon from '@material-ui/icons/FileCopy';
44
import PasteIcon from '@material-ui/icons/Assignment';
55

66
const CopyPasteMenu = ({
77
id, children, copyData, pasteData, copy, paste,
8-
}) => (
9-
<>
10-
<MenuProvider id={`copyPasteMenu${id}`} style={{ width: '100%' }}>
11-
{children}
12-
</MenuProvider>
13-
<Menu id={`copyPasteMenu${id}`}>
14-
<Item onClick={() => copyData()}>
15-
<CopyIcon />
16-
{' '}
17-
{copy}
18-
</Item>
19-
<Item onClick={() => pasteData()}>
20-
<PasteIcon />
21-
{' '}
22-
{paste}
23-
</Item>
24-
</Menu>
25-
</>
26-
);
8+
}) => {
9+
const MENU_ID = `copyPasteMenu${id}`;
10+
11+
const { show } = useContextMenu({
12+
id: MENU_ID,
13+
});
14+
15+
/**
16+
* Handle the context menu event
17+
* @param event The event argument
18+
*/
19+
const handleContextMenu = (event) => {
20+
event.preventDefault();
21+
show(event, {
22+
props: {
23+
key: 'value',
24+
},
25+
});
26+
};
27+
28+
return (
29+
<>
30+
<div
31+
style={{ width: '100%' }}
32+
onContextMenu={handleContextMenu}
33+
>
34+
{children}
35+
</div>
36+
<Menu id={MENU_ID}>
37+
<Item onClick={() => copyData()}>
38+
<CopyIcon />
39+
{' '}
40+
{copy}
41+
</Item>
42+
<Item onClick={() => pasteData()}>
43+
<PasteIcon />
44+
{' '}
45+
{paste}
46+
</Item>
47+
</Menu>
48+
</>
49+
);
50+
};
2751

2852
export default CopyPasteMenu;

src/components/Hash/index.jsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Paper from '@material-ui/core/Paper';
33
import { makeStyles } from '@material-ui/core';
44
import Typography from '@material-ui/core/Typography';
55
import CheckIcon from '@material-ui/icons/Check';
6-
import { Menu, Item, MenuProvider } from 'react-contexify';
6+
import { Menu, Item, useContextMenu } from 'react-contexify';
77
import 'react-contexify/dist/ReactContexify.min.css';
88
import CopyIcon from '@material-ui/icons/FileCopy';
99

@@ -19,6 +19,7 @@ const useStyles = makeStyles((theme) => ({
1919
const Hash = ({
2020
hashType, content, compareString, id, copy,
2121
}) => {
22+
const MENU_ID = `hashMenu${id}`;
2223
const classes = useStyles();
2324

2425
let compareColor = null;
@@ -28,15 +29,32 @@ const Hash = ({
2829
compareColor = { color: 'green' };
2930
}
3031

32+
const { show } = useContextMenu({
33+
id: MENU_ID,
34+
});
35+
36+
/**
37+
* Handle the context menu event
38+
* @param event The event argument
39+
*/
40+
const handleContextMenu = (event) => {
41+
event.preventDefault();
42+
show(event, {
43+
props: {
44+
key: 'value',
45+
},
46+
});
47+
};
48+
3149
return (
3250
<Paper className={classes.paper}>
3351
<Typography variant="subtitle1" color="primary" gutterBottom>
3452
{hashType}
3553
{compareIcon}
3654
</Typography>
37-
<MenuProvider id={`hashMenu${id}`}>
55+
<div onContextMenu={handleContextMenu}>
3856
<span style={compareColor}>{content}</span>
39-
</MenuProvider>
57+
</div>
4058
<Menu id={`hashMenu${id}`}>
4159
<Item onClick={() => navigator.clipboard.writeText(content)}>
4260
<CopyIcon />

src/contexts/MainContextProvider/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ru_RU from '../../languages/ru_RU';
2222
import tr_TR from '../../languages/tr_TR';
2323

2424
const languageIndex = localStorage.languageIndex ? parseFloat(localStorage.languageIndex) : 1;
25+
const themeStyle = localStorage.themeStyle ? localStorage.themeStyle : 'light';
2526
const themeIndex = localStorage.themeIndex ? parseFloat(localStorage.themeIndex) : 0;
2627
const autoUpdate = localStorage.autoUpdate && localStorage.autoUpdate === 'true' ? true : !localStorage.autoUpdate;
2728
const minimizeEnabled = localStorage.minimizeEnabled && localStorage.minimizeEnabled === 'true' ? true : !localStorage.minimizeEnabled;
@@ -45,6 +46,7 @@ const initState = {
4546
],
4647
drawerOpen: false,
4748
selectedListItem: 0,
49+
themeStyle,
4850
themeIndex,
4951
autoUpdate,
5052
checkedForUpdates: false,

src/languages/de_DE/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ const de_DE = () => ({
6868
maximizeEnabled: 'Schaltfläche "Maximieren"',
6969
languageEnabled: 'Schaltfläche "Sprache"',
7070
exit: 'Schließen',
71-
darkTheme: 'Dunkel',
72-
darkThemeDescription: 'Schont die Augen.',
7371
export: 'Export',
7472
yourTextHere: 'Dein Text hier',
7573
filePath: 'Dateipfad',
7674
yes: 'Ja',
7775
no: 'Nein',
7876
confirmation: 'Bestätigung',
7977
confirmResetSettings: 'Möchten Sie wirklich alle Einstellungen zurücksetzen?',
78+
themeStyle: 'Themenstil',
79+
light: 'Licht',
80+
dark: 'Dunkel',
81+
orange: 'Orange',
82+
orangeThemeDescription: 'Lass uns Niederländisch werden.',
8083
});
8184

8285
// eslint-disable-next-line camelcase

src/languages/en_US/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ const en_US = () => ({
6868
maximizeEnabled: 'Maximize button',
6969
languageEnabled: 'Language button',
7070
exit: 'Exit',
71-
darkTheme: 'Dark',
72-
darkThemeDescription: 'Easy on the eyes.',
7371
export: 'Export',
7472
yourTextHere: 'Your text here',
7573
filePath: 'File path',
7674
yes: 'Yes',
7775
no: 'No',
7876
confirmation: 'Confirmation',
7977
confirmResetSettings: 'Are you sure you want to reset all settings?',
78+
themeStyle: 'Theme style',
79+
light: 'Light',
80+
dark: 'Dark',
81+
orange: 'Orange',
82+
orangeThemeDescription: 'Let\'s get Dutch.',
8083
});
8184

8285
// eslint-disable-next-line camelcase

src/languages/es_ES/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ const es_ES = () => ({
6868
maximizeEnabled: 'Botón Maximizar',
6969
languageEnabled: 'Botón de idioma',
7070
exit: 'Salida',
71-
darkTheme: 'Oscuro',
72-
darkThemeDescription: 'Fácil para los ojos.',
7371
export: 'Exportar',
7472
yourTextHere: 'Tu texto aqui',
7573
filePath: 'Ruta de archivo',
7674
yes: 'Sí',
7775
no: 'No',
7876
confirmation: 'Confirmación',
7977
confirmResetSettings: '¿Estás seguro de que quieres restablecer todos los ajustes?',
78+
themeStyle: 'Estilo del tema',
79+
light: 'Ligero',
80+
dark: 'Oscuro',
81+
orange: 'Naranja',
82+
orangeThemeDescription: 'Vamos a holandeses.',
8083
});
8184

8285
// eslint-disable-next-line camelcase

0 commit comments

Comments
 (0)