This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcard.tsx
More file actions
92 lines (82 loc) · 2.38 KB
/
card.tsx
File metadata and controls
92 lines (82 loc) · 2.38 KB
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
import "./card.scss";
import DiscordComponents from "./discord";
import Icon from "./icons";
const kernel: any = (window as any).kernel;
const Electron = SettingsNative.requireModule("electron");
export function ToolButton({ label, icon, onClick, danger = false }) {
const { Tooltips, Button } = DiscordComponents;
return (
<Tooltips text={label} position="top">
{(props) => (
<Button
{...props}
className="kernel-toolbutton"
look={Button.Looks.BLANK}
size={Button.Sizes.NONE}
onClick={onClick}
>
<Icon size="20" name={icon} color={danger ? "#ed4245" : undefined} />
</Button>
)}
</Tooltips>
);
}
export function SwitchWrapper({ value, onChange, disabled }) {
const { Switch } = DiscordComponents;
const [isChecked, setChecked] = React.useState(value);
return (
<Switch
checked={isChecked}
disabled={disabled}
value={value}
onChange={React.useCallback(() => {
if (disabled) return;
onChange(!isChecked);
setChecked((value: boolean) => !value);
}, [onChange, isChecked])}
/>
);
}
export function openItem(path: string) {
if (path.endsWith(".asar")) return Electron.showItemInFolder(path);
Electron.openPath(path);
}
export default function KernelCard({ pkg }) {
const { Markdown, Text } = DiscordComponents;
return (
<div className="kernel-card">
<div className="kernel-card-tools">
<ToolButton
label="Open Path"
icon="Folder"
onClick={() => openItem(pkg.path)}
/>
<ToolButton
danger
label="Delete"
icon="Trash"
onClick={() => Electron.trashItem(pkg.path)}
/>
</div>
<div className="kernel-card-header">
<Text className="kernel-card-name">{pkg.name}</Text>
</div>
{pkg.description != null && (
<Text className="kernel-card-desc">
<Markdown>{pkg.description}</Markdown>
</Text>
)}
<div className="kernel-footer">
<SwitchWrapper
value={pkg.enabled}
enabled={pkg.enabled}
disabled={pkg.id === "kernel-settings"}
onChange={(value: boolean) => {
if (!value) kernel.packages.stopPackage(pkg.id);
else kernel.packages.startPackage(pkg.id);
}}
/>
</div>
</div>
);
}