Skip to content

Commit e8e71a5

Browse files
committed
* Upgraded context menu
* Fixed contextIsolation warning
1 parent a330d7a commit e8e71a5

File tree

10 files changed

+101
-37
lines changed

10 files changed

+101
-37
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/reducers/MainReducer/Actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const SET_LANGUAGE_INDEX = 'SET_LANGUAGE_INDEX';
22
export const SET_ACTIVE_LIST_ITEM = 'SET_ACTIVE_LIST_ITEM';
33
export const SET_THEME_INDEX = 'SET_THEME_INDEX';
4+
export const SET_THEME_STYLE = 'SET_THEME_STYLE';
45
export const SET_AUTO_UPDATE = 'SET_AUTO_UPDATE';
56
export const SET_UPDATE_CHECKED = 'SET_UPDATE_CHECKED';
67
export const RESET_MAIN_REDUCER = 'RESET_MAIN_REDUCER';

src/reducers/MainReducer/Actions/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import {
22
RESET_MAIN_REDUCER,
33
SET_ACTIVE_LIST_ITEM,
4-
SET_AUTO_UPDATE, SET_CAN_DRAG_DROP,
5-
SET_LANGUAGE_INDEX, SET_LANGUAGE_STATUS, SET_MAXIMIZE_STATUS, SET_MINIMIZE_STATUS,
4+
SET_AUTO_UPDATE,
5+
SET_CAN_DRAG_DROP,
6+
SET_LANGUAGE_INDEX,
7+
SET_LANGUAGE_STATUS,
8+
SET_MAXIMIZE_STATUS,
9+
SET_MINIMIZE_STATUS,
610
SET_THEME_INDEX,
11+
SET_THEME_STYLE,
712
SET_UPDATE_CHECKED,
813
} from './actionTypes';
914

@@ -22,6 +27,11 @@ export const setThemeIndex = (index) => ({
2227
payload: index,
2328
});
2429

30+
export const setThemeStyle = (style) => ({
31+
type: SET_THEME_STYLE,
32+
payload: style,
33+
});
34+
2535
export const setAutoUpdate = (autoUpdate) => ({
2636
type: SET_AUTO_UPDATE,
2737
payload: autoUpdate,

src/reducers/MainReducer/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import {
22
RESET_MAIN_REDUCER,
33
SET_ACTIVE_LIST_ITEM,
4-
SET_AUTO_UPDATE, SET_CAN_DRAG_DROP,
5-
SET_LANGUAGE_INDEX, SET_LANGUAGE_STATUS, SET_MAXIMIZE_STATUS, SET_MINIMIZE_STATUS,
4+
SET_AUTO_UPDATE,
5+
SET_CAN_DRAG_DROP,
6+
SET_LANGUAGE_INDEX,
7+
SET_LANGUAGE_STATUS,
8+
SET_MAXIMIZE_STATUS,
9+
SET_MINIMIZE_STATUS,
610
SET_THEME_INDEX,
11+
SET_THEME_STYLE,
712
SET_UPDATE_CHECKED,
813
} from './Actions/actionTypes';
914

@@ -28,6 +33,12 @@ const MainReducer = (state, action) => {
2833
...state,
2934
themeIndex: action.payload,
3035
};
36+
case SET_THEME_STYLE:
37+
localStorage.themeStyle = action.payload;
38+
return {
39+
...state,
40+
themeStyle: action.payload,
41+
};
3142
case SET_AUTO_UPDATE:
3243
localStorage.autoUpdate = action.payload;
3344
return {

0 commit comments

Comments
 (0)