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

207 lines
7.8 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";
import Button from "../../../components/ui/Button";
2021-07-31 22:39:15 +01:00
import Checkbox from "../../../components/ui/Checkbox";
import Tip from "../../../components/ui/Tip";
import CategoryButton from "../../../components/ui/fluent/CategoryButton";
import RLogo from "../assets/revolt_r.svg";
2021-07-31 22:39:15 +01:00
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" }}>
<Tip hideSeparator>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
checked={autoStart ?? false}
disabled={typeof autoStart === "undefined"}
onChange={async (v) => {
if (v) {
await window.native.enableAutoStart();
} else {
await window.native.disableAutoStart();
}
setAutoStart(v);
}}
description="Launch Revolt when you log into your computer.">
Start with computer
</Checkbox>
2021-08-05 14:47:00 +01:00
2022-05-10 12:26:57 +01:00
<Checkbox
checked={config.minimiseToTray}
onChange={(minimiseToTray) => {
window.native.set("minimiseToTray", minimiseToTray);
setConfig({
...config,
minimiseToTray,
});
}}
description="Instead of closing, Revolt will hide in your tray.">
Minimise to Tray
</Checkbox>
2021-08-03 20:04:46 +01:00
<Checkbox
2021-08-04 10:01:17 +02:00
checked={config.discordRPC}
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
});
}}
2021-08-04 10:01:17 +02:00
description="Rep Revolt on your Discord status.">
Enable Discord status
</Checkbox>
<Checkbox
checked={config.build === "nightly"}
onChange={(nightly) => {
const build = nightly ? "nightly" : "stable";
window.native.set("build", build);
setHintReload(true);
setConfig({
...config,
build,
});
}}
description="Use the beta branch of Revolt.">
Revolt Nightly
2021-08-03 20:04:46 +01:00
</Checkbox>
2021-08-04 10:01:17 +02:00
<h3>Titlebar</h3>
2021-08-01 14:22:08 +01:00
<Checkbox
checked={!config.frame}
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,
});
}}
description={<>Let Revolt use its own window frame.</>}>
Custom window frame
</Checkbox>
2021-08-04 10:01:17 +02:00
<Checkbox //FIXME: In Titlebar.tsx, enable .quick css
disabled={true}
checked={!config.frame}
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
});
}}
2021-08-04 10:01:17 +02:00
description="Show mute/deafen buttons on the titlebar.">
Enable quick action buttons
2021-08-03 20:04:46 +01:00
</Checkbox>
2021-08-04 10:01:17 +02:00
<h3>Advanced</h3>
2021-08-01 14:22:08 +01:00
<Checkbox
2021-08-04 10:01:17 +02:00
checked={config.hardwareAcceleration}
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
});
}}
2021-08-04 10:01:17 +02:00
description="Uses your GPU to render the app, disable if you run into visual issues.">
Hardware Acceleration
2021-08-01 14:22:08 +01:00
</Checkbox>
<p style={{ display: "flex", gap: "8px" }}>
<Button
contrast
compact
disabled={!hintReload}
onClick={window.native.reload}>
Reload Page
</Button>
<Button
contrast
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
contrast
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
checked={confirmDev}
onChange={setConfirmDev}
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
</>
}>
I understand there's no going back.
</Checkbox>
<p>
<Button
error
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
}