revite/src/pages/settings/panes/Native.tsx

207 lines
7.6 KiB
TypeScript
Raw Normal View History

import { Refresh } from "@styled-icons/boxicons-regular";
2021-08-01 14:22:08 +01:00
import { useEffect, useState } from "preact/hooks";
2022-05-30 12:56:47 +01:00
import { Button, CategoryButton, Checkbox, Tip } from "@revoltchat/ui";
2022-05-29 16:34:54 +01:00
import RLogo from "../assets/revolt_r.svg";
2021-08-05 14:47:00 +01:00
export function Native() {
if (typeof window.native === "undefined") return null;
/* eslint-disable react-hooks/rules-of-hooks */
2021-08-01 14:22:08 +01:00
const [config, setConfig] = useState(window.native.getConfig());
const [autoStart, setAutoStart] = useState<boolean | undefined>();
const fetchValue = () => window.native.getAutoStart().then(setAutoStart);
const [hintReload, setHintReload] = useState(false);
const [hintRelaunch, setHintRelaunch] = useState(false);
const [confirmDev, setConfirmDev] = useState(false);
useEffect(() => {
fetchValue();
}, []);
return (
<div style={{ marginTop: "10px" }}>
2022-05-30 12:47:13 +01:00
<Tip>Some options might require a restart.</Tip>
2021-08-01 20:41:53 +02:00
<h3>App Behavior</h3>
2021-08-01 14:22:08 +01:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={autoStart ?? false}
2021-08-01 14:22:08 +01:00
disabled={typeof autoStart === "undefined"}
onChange={async (v) => {
if (v) {
await window.native.enableAutoStart();
} else {
await window.native.disableAutoStart();
}
setAutoStart(v);
}}
2022-05-29 16:34:54 +01:00
title="Start with computer"
description="Launch Revolt when you log into your computer."
/>
2021-08-05 14:47:00 +01:00
2022-05-10 12:26:57 +01:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={config.minimiseToTray}
2022-05-10 12:26:57 +01:00
onChange={(minimiseToTray) => {
window.native.set("minimiseToTray", minimiseToTray);
setConfig({
...config,
minimiseToTray,
});
}}
2022-05-29 16:34:54 +01:00
title="Minimise to Tray"
description="Instead of closing, Revolt will hide in your tray."
/>
2021-08-03 20:04:46 +01:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={config.discordRPC}
2021-08-04 10:01:17 +02:00
onChange={(discordRPC) => {
window.native.set("discordRPC", discordRPC);
2021-08-03 20:04:46 +01:00
setConfig({
...config,
2021-08-04 10:01:17 +02:00
discordRPC,
2021-08-03 20:04:46 +01:00
});
}}
2022-05-29 16:34:54 +01:00
title="Enable Discord status"
description="Rep Revolt on your Discord status."
/>
2021-08-04 10:01:17 +02:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={config.build === "nightly"}
2021-08-04 10:01:17 +02:00
onChange={(nightly) => {
const build = nightly ? "nightly" : "stable";
window.native.set("build", build);
setHintReload(true);
setConfig({
...config,
build,
});
}}
2022-05-29 16:34:54 +01:00
title="Revolt Nightly"
description="Use the beta branch of Revolt."
/>
2021-08-04 10:01:17 +02:00
<h3>Titlebar</h3>
2021-08-01 14:22:08 +01:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={!config.frame}
2021-08-01 14:22:08 +01:00
onChange={(frame) => {
2021-08-03 20:04:46 +01:00
window.native.set("frame", !frame);
2021-08-01 14:22:08 +01:00
setHintRelaunch(true);
setConfig({
...config,
frame: !frame,
});
}}
2022-05-29 16:34:54 +01:00
title="Custom window frame"
description="Let Revolt use its own window frame."
/>
2021-08-04 10:01:17 +02:00
<Checkbox //FIXME: In Titlebar.tsx, enable .quick css
disabled={true}
2022-05-29 16:34:54 +01:00
value={!config.frame}
2021-08-04 10:01:17 +02:00
onChange={(frame) => {
window.native.set("frame", !frame);
setHintRelaunch(true);
2021-08-03 20:04:46 +01:00
setConfig({
...config,
2021-08-04 10:01:17 +02:00
frame: !frame,
2021-08-03 20:04:46 +01:00
});
}}
2022-05-29 16:34:54 +01:00
title="Enable quick action buttons"
description="Show mute/deafen buttons on the titlebar."
/>
2021-08-04 10:01:17 +02:00
<h3>Advanced</h3>
2021-08-01 14:22:08 +01:00
<Checkbox
2022-05-29 16:34:54 +01:00
value={config.hardwareAcceleration}
2021-08-04 10:01:17 +02:00
onChange={async (hardwareAcceleration) => {
window.native.set(
"hardwareAcceleration",
hardwareAcceleration,
);
setHintRelaunch(true);
2021-08-01 14:22:08 +01:00
setConfig({
...config,
2021-08-04 10:01:17 +02:00
hardwareAcceleration,
2021-08-01 14:22:08 +01:00
});
}}
2022-05-29 16:34:54 +01:00
title="Hardware Acceleration"
description="Uses your GPU to render the app, disable if you run into visual issues."
/>
2021-08-01 14:22:08 +01:00
<p style={{ display: "flex", gap: "8px" }}>
<Button
palette="secondary"
2021-08-01 14:22:08 +01:00
compact
disabled={!hintReload}
onClick={window.native.reload}>
Reload Page
</Button>
<Button
palette="secondary"
2021-08-01 14:22:08 +01:00
compact
disabled={!hintRelaunch}
onClick={window.native.relaunch}>
Reload App
</Button>
</p>
<h3 style={{ marginTop: "4em" }}>Local Development Mode</h3>
{config.build === "dev" ? (
2021-08-04 10:01:17 +02:00
<>
<h5>Development mode is currently on.</h5>
2021-08-01 14:22:08 +01:00
<Button
palette="secondary"
2021-08-01 14:22:08 +01:00
compact
onClick={() => {
2021-08-03 20:04:46 +01:00
window.native.set("build", "stable");
2021-08-01 14:22:08 +01:00
window.native.reload();
}}>
Exit Development Mode
</Button>
2021-08-04 10:01:17 +02:00
</>
2021-08-01 14:22:08 +01:00
) : (
<>
<Checkbox
2022-05-29 16:34:54 +01:00
value={confirmDev}
2021-08-01 14:22:08 +01:00
onChange={setConfirmDev}
2022-05-29 16:34:54 +01:00
title="I understand there's no going back."
2021-08-01 14:22:08 +01:00
description={
<>
This will change the app to the 'dev' branch,
instead loading the app from a local server on
your machine.
<br />
<b>
Without a server running,{" "}
<span style={{ color: "var(--error)" }}>
the app will not load!
</span>
</b>
<br />
<code>yarn dev --port 3001</code>
2021-08-01 14:22:08 +01:00
</>
2022-05-29 16:34:54 +01:00
}
/>
2021-08-01 14:22:08 +01:00
<p>
<Button
palette="error"
2021-08-01 14:22:08 +01:00
compact
disabled={!confirmDev}
onClick={() => {
2021-08-03 20:04:46 +01:00
window.native.set("build", "dev");
2021-08-01 14:22:08 +01:00
window.native.reload();
}}>
Enter Development Mode
</Button>
</p>
</>
)}
<hr />
<CategoryButton
icon={<img src={RLogo} draggable={false} />}
description={<span>version {window.nativeVersion}</span>}
action={<Refresh size={24} />}>
Revolt for Desktop
</CategoryButton>
2021-08-01 14:22:08 +01:00
</div>
);
2021-08-05 14:47:00 +01:00
}