-
Notifications
You must be signed in to change notification settings - Fork 29
/
DesktopMenu.tsx
161 lines (149 loc) · 5.31 KB
/
DesktopMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { Button, Classes, Icon } from "@blueprintjs/core";
import React from "react";
import styled from "styled-components";
import { isRunningInElectron } from "../../utils/electron";
import { useTheme } from "../shared/Themes";
const MenuContainer = styled.div`
-webkit-app-region: drag;
z-index: 1;
position: fixed;
align-items: center;
top: 0;
right: 0;
left: 0;
display: flex;
height: 30px;
width: 100%;
background: ${props => (props.theme === Classes.DARK ? "#293742" : "#BFCCD6")};
justify-content: space-between;
.menu-container {
display: flex;
align-items: center;
&: first;
.menu-button {
-webkit-app-region: no-drag;
&:hover {
cursor: pointer;
}
}
.title {
padding-left: 10px;
}
}
.theme-changer {
-webkit-app-region: no-drag;
margin-left: auto;
margin-right: 50px;
}
.window-effects-container {
display: flex;
align-items: center;
justify-content: space-between;
-webkit-app-region: no-drag;
.theme-changer {
&:hover {
cursor: pointer;
}
}
.window-button {
border-radius: 0;
width: 3.2em;
}
}
`;
type TMinMaxIconType = "duplicate" | "square";
const DesktopMenu = () => {
// Importing electron here so that code doesn't give compilation error when running in browser
const { remote, ipcRenderer } = require("electron");
const currentWindow = remote.getCurrentWindow();
const startingIcon: TMinMaxIconType = currentWindow.isMaximized() ? "duplicate" : "square";
const openAppMenu = e => {
ipcRenderer.send(`display-app-menu`, {
x: e.x,
y: e.y,
});
};
const { theme, setTheme } = useTheme();
const [maximizeIcon, setMaximizeIcon] = React.useState<TMinMaxIconType>(startingIcon);
const [isCloseButtonMinimal, setIsCloseButtonMinimal] = React.useState<boolean>(true);
return (
<MenuContainer theme={theme}>
<span className="menu-container">
<Button
className="menu-button"
icon="menu"
minimal={true}
onContextMenu={openAppMenu}
onClick={openAppMenu}
/>
<span className="title">Ten Hands</span>
</span>
<div className="theme-changer">
{theme === Classes.DARK ? (
<Button data-testid="theme-light" icon="moon" onClick={() => setTheme(`light`)} minimal={true}>
Dark
</Button>
) : (
<Button data-testid="theme-dark" icon="flash" onClick={() => setTheme(Classes.DARK)} minimal={true}>
Light
</Button>
)}
</div>
<span className="window-effects-container">
<Button
minimal={true}
className="window-button minimize-button"
onClick={() => {
currentWindow.isMinimizable() && currentWindow.minimize();
}}
>
<Icon icon="minus" />
</Button>
<Button
minimal={true}
className="window-button min-max-button"
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
onClick={() => {
if (currentWindow.isMaximized()) {
currentWindow.unmaximize();
setMaximizeIcon("square");
} else {
currentWindow.maximize();
setMaximizeIcon("duplicate");
}
}}
>
<Icon icon={maximizeIcon} iconSize={10} className="all-center" />
</Button>
<Button
minimal={isCloseButtonMinimal}
className="window-button close-button"
intent={!isCloseButtonMinimal ? "danger" : "none"}
onMouseOver={() => setIsCloseButtonMinimal(false)}
onMouseOut={() => setIsCloseButtonMinimal(true)}
onClick={() => {
const response = remote.dialog.showMessageBox({
type: "info",
title: "Warning",
message: "Are you sure you want to exit?",
detail: "Any running tasks will keep running.",
buttons: ["Cancel", "Exit"],
});
// Cancel = 0
// Exit = 1
if (response === 1) {
remote.app.quit();
}
}}
>
<Icon icon="cross" />
</Button>
</span>
</MenuContainer>
);
};
export default DesktopMenu;