CloudTab: Add Default Buttons
This commit is contained in:
parent
7e65edd4da
commit
8ba78d2de4
4 changed files with 35 additions and 48 deletions
4
.github/ISSUE_TEMPLATE/blank.yml
vendored
4
.github/ISSUE_TEMPLATE/blank.yml
vendored
|
|
@ -5,9 +5,9 @@ body:
|
|||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||

|
||||

|
||||
|
||||
GitHub Issues are for development, not support! Please use our [support server](https://vencord.dev/discord) unless you are a Vencord Developer.
|
||||
GitHub Issues are for development, not support! Please use our [support server](https://equicord.org/discord) unless you are a Vencord Developer.
|
||||
|
||||
- type: textarea
|
||||
id: content
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ import { CheckedTextInput } from "@components/CheckedTextInput";
|
|||
import { Grid } from "@components/Grid";
|
||||
import { Link } from "@components/Link";
|
||||
import { SettingsTab, wrapTab } from "@components/settings/tabs/BaseTab";
|
||||
import { authorizeCloud, checkCloudUrlCsp, cloudLogger, deauthorizeCloud, getCloudAuth, getCloudUrl } from "@utils/cloud";
|
||||
import { authorizeCloud, cloudLogger, deauthorizeCloud, getCloudAuth, getCloudUrl } from "@utils/cloud";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { deleteCloudSettings, getCloudSettings, putCloudSettings } from "@utils/settingsSync";
|
||||
import { Alerts, Button, Forms, Switch, Tooltip } from "@webpack/common";
|
||||
import { Alerts, Button, Forms, Switch, Tooltip, useState } from "@webpack/common";
|
||||
|
||||
function validateUrl(url: string) {
|
||||
try {
|
||||
|
|
@ -37,8 +37,6 @@ function validateUrl(url: string) {
|
|||
}
|
||||
|
||||
async function eraseAllData() {
|
||||
if (!await checkCloudUrlCsp()) return;
|
||||
|
||||
const res = await fetch(new URL("/v1/", getCloudUrl()), {
|
||||
method: "DELETE",
|
||||
headers: { Authorization: await getCloudAuth() }
|
||||
|
|
@ -119,15 +117,31 @@ function SettingsSyncSection() {
|
|||
|
||||
function CloudTab() {
|
||||
const settings = useSettings(["cloud.authenticated", "cloud.url"]);
|
||||
const [inputKey, setInputKey] = useState(0);
|
||||
|
||||
async function changeUrl(url: string) {
|
||||
settings.cloud.url = url;
|
||||
settings.cloud.authenticated = false;
|
||||
|
||||
await deauthorizeCloud();
|
||||
await authorizeCloud();
|
||||
|
||||
setInputKey(prev => prev + 1);
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsTab title="Equicord Cloud">
|
||||
<Forms.FormSection title="Cloud Settings" className={Margins.top16}>
|
||||
<Forms.FormText variant="text-md/normal" className={Margins.bottom20}>
|
||||
Equicord comes with a cloud integration that adds goodies like settings sync across devices.
|
||||
It <Link href="https://vencord.dev/cloud/privacy">respects your privacy</Link>, and
|
||||
the <Link href="https://github.com/Vencord/Backend">source code</Link> is AGPL 3.0 licensed so you
|
||||
can host it yourself.
|
||||
Equicord comes with a cloud integration allowing settings to be synced across apps and devices.
|
||||
<br />
|
||||
We use Vencord's <Link href="https://github.com/Vencord/Backend">cloud source code</Link> to provide our cloud instance which has a 32MB backup cap.
|
||||
<br />
|
||||
Our <Link href="https://vencord.dev/cloud/privacy">privacy policy</Link> allows you to see what information we store, how we use it, and data retention.
|
||||
<br />
|
||||
The Vencord Cloud repository is AGPL 3.0 licensed so you can host it yourself it you would like.
|
||||
<br />
|
||||
You can swap between Equicord and Vencord's different cloud instances below if needed.
|
||||
</Forms.FormText>
|
||||
<Switch
|
||||
key="backend"
|
||||
|
|
@ -147,12 +161,12 @@ function CloudTab() {
|
|||
Which backend to use when using cloud integrations.
|
||||
</Forms.FormText>
|
||||
<CheckedTextInput
|
||||
key="backendUrl"
|
||||
key={`backendUrl-${inputKey}`}
|
||||
value={settings.cloud.url}
|
||||
onChange={async v => {
|
||||
settings.cloud.url = v;
|
||||
settings.cloud.authenticated = false;
|
||||
deauthorizeCloud();
|
||||
await deauthorizeCloud();
|
||||
}}
|
||||
validate={validateUrl}
|
||||
/>
|
||||
|
|
@ -162,8 +176,8 @@ function CloudTab() {
|
|||
size={Button.Sizes.MEDIUM}
|
||||
disabled={!settings.cloud.authenticated}
|
||||
onClick={async () => {
|
||||
await deauthorizeCloud();
|
||||
settings.cloud.authenticated = false;
|
||||
await deauthorizeCloud();
|
||||
await authorizeCloud();
|
||||
}}
|
||||
>
|
||||
|
|
@ -184,6 +198,12 @@ function CloudTab() {
|
|||
>
|
||||
Erase All Data
|
||||
</Button>
|
||||
<Button size={Button.Sizes.MEDIUM} onClick={() => changeUrl("https://cloud.equicord.org/")}>
|
||||
Use Equicord's Cloud
|
||||
</Button>
|
||||
<Button size={Button.Sizes.MEDIUM} onClick={() => changeUrl("https://api.vencord.dev/")}>
|
||||
Use Vencord's Cloud
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Forms.FormDivider className={Margins.top16} />
|
||||
|
|
|
|||
|
|
@ -19,41 +19,16 @@
|
|||
import * as DataStore from "@api/DataStore";
|
||||
import { showNotification } from "@api/Notifications";
|
||||
import { Settings } from "@api/Settings";
|
||||
import { Alerts, OAuth2AuthorizeModal, UserStore } from "@webpack/common";
|
||||
import { OAuth2AuthorizeModal, UserStore } from "@webpack/common";
|
||||
|
||||
import { Logger } from "./Logger";
|
||||
import { openModal } from "./modal";
|
||||
import { relaunch } from "./native";
|
||||
|
||||
export const cloudLogger = new Logger("Cloud", "#39b7e0");
|
||||
|
||||
export const getCloudUrl = () => new URL(Settings.cloud.url);
|
||||
const getCloudUrlOrigin = () => getCloudUrl().origin;
|
||||
|
||||
export async function checkCloudUrlCsp() {
|
||||
if (IS_WEB) return true;
|
||||
|
||||
const { host } = getCloudUrl();
|
||||
if (host === "api.vencord.dev") return true;
|
||||
if (host === "cloud.equicord.org") return true;
|
||||
|
||||
if (await VencordNative.csp.isDomainAllowed(Settings.cloud.url, ["connect-src"])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const res = await VencordNative.csp.requestAddOverride(Settings.cloud.url, ["connect-src"], "Cloud Sync");
|
||||
if (res === "ok") {
|
||||
Alerts.show({
|
||||
title: "Cloud Integration enabled",
|
||||
body: `${host} has been added to the whitelist. Please restart the app for the changes to take effect.`,
|
||||
confirmText: "Restart now",
|
||||
cancelText: "Later!",
|
||||
onConfirm: relaunch
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const getUserId = () => {
|
||||
const id = UserStore.getCurrentUser()?.id;
|
||||
if (!id) throw new Error("User not yet logged in");
|
||||
|
|
@ -104,8 +79,6 @@ export async function authorizeCloud() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!await checkCloudUrlCsp()) return;
|
||||
|
||||
try {
|
||||
const oauthConfiguration = await fetch(new URL("/v1/oauth/settings", getCloudUrl()));
|
||||
var { clientId, redirectUri } = await oauthConfiguration.json();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { PlainSettings, Settings } from "@api/Settings";
|
|||
import { moment, SettingsRouter, Toasts } from "@webpack/common";
|
||||
import { deflateSync, inflateSync } from "fflate";
|
||||
|
||||
import { checkCloudUrlCsp, getCloudAuth, getCloudUrl } from "./cloud";
|
||||
import { getCloudAuth, getCloudUrl } from "./cloud";
|
||||
import { Logger } from "./Logger";
|
||||
import { relaunch } from "./native";
|
||||
import { chooseFile, saveFile } from "./web";
|
||||
|
|
@ -118,8 +118,6 @@ const cloudSettingsLogger = new Logger("Cloud:Settings", "#39b7e0");
|
|||
export async function putCloudSettings(manual?: boolean) {
|
||||
const settings = await exportSettings({ minify: true });
|
||||
|
||||
if (!await checkCloudUrlCsp()) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(new URL("/v1/settings", getCloudUrl()), {
|
||||
method: "PUT",
|
||||
|
|
@ -164,8 +162,6 @@ export async function putCloudSettings(manual?: boolean) {
|
|||
}
|
||||
|
||||
export async function getCloudSettings(shouldNotify = true, force = false) {
|
||||
if (!await checkCloudUrlCsp()) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(new URL("/v1/settings", getCloudUrl()), {
|
||||
method: "GET",
|
||||
|
|
@ -268,8 +264,6 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
|
|||
}
|
||||
|
||||
export async function deleteCloudSettings() {
|
||||
if (!await checkCloudUrlCsp()) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(new URL("/v1/settings", getCloudUrl()), {
|
||||
method: "DELETE",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue