Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes7k75 authored Apr 27, 2024
2 parents 9249455 + d294128 commit 41929d3
Show file tree
Hide file tree
Showing 29 changed files with 976 additions and 73 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vencord",
"private": "true",
"version": "1.7.8",
"version": "1.7.9",
"description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": {
Expand Down
20 changes: 9 additions & 11 deletions src/Vencord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { PlainSettings, Settings };
import "./utils/quickCss";
import "./webpack/patchWebpack";

import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab";
import { StartAt } from "@utils/types";

import { get as dsGet } from "./api/DataStore";
Expand Down Expand Up @@ -85,7 +86,7 @@ async function init() {

syncSettings();

if (!IS_WEB) {
if (!IS_WEB && !IS_UPDATER_DISABLED) {
try {
const isOutdated = await checkForUpdates();
if (!isOutdated) return;
Expand All @@ -103,16 +104,13 @@ async function init() {
return;
}

if (Settings.notifyAboutUpdates)
setTimeout(() => showNotification({
title: "A Vencord update is available!",
body: "Click here to view the update",
permanent: true,
noPersist: true,
onClick() {
SettingsRouter.open("VencordUpdater");
}
}), 10_000);
setTimeout(() => showNotification({
title: "A Vencord update is available!",
body: "Click here to view the update",
permanent: true,
noPersist: true,
onClick: openUpdaterModal!
}), 10_000);
} catch (err) {
UpdateLogger.error("Failed to check for updates", err);
}
Expand Down
4 changes: 1 addition & 3 deletions src/api/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import plugins from "~plugins";

const logger = new Logger("Settings");
export interface Settings {
notifyAboutUpdates: boolean;
autoUpdate: boolean;
autoUpdateNotification: boolean,
useQuickCss: boolean;
Expand Down Expand Up @@ -78,8 +77,7 @@ export interface Settings {
}

const DefaultSettings: Settings = {
notifyAboutUpdates: true,
autoUpdate: false,
autoUpdate: true,
autoUpdateNotification: true,
useQuickCss: true,
themeLinks: [],
Expand Down
41 changes: 27 additions & 14 deletions src/components/VencordSettings/UpdaterTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import { Flex } from "@components/Flex";
import { Link } from "@components/Link";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import { ModalCloseButton, ModalContent, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { relaunch } from "@utils/native";
import { useAwaiter } from "@utils/react";
import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater";
import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common";

import gitHash from "~git-hash";

import { SettingsTab, wrapTab } from "./shared";
import { handleSettingsTabError, SettingsTab, wrapTab } from "./shared";

function withDispatcher(dispatcher: React.Dispatch<React.SetStateAction<boolean>>, action: () => any) {
return async () => {
Expand All @@ -38,21 +39,24 @@ function withDispatcher(dispatcher: React.Dispatch<React.SetStateAction<boolean>
await action();
} catch (e: any) {
UpdateLogger.error("Failed to update", e);

let err: string;
if (!e) {
var err = "An unknown error occurred (error is undefined).\nPlease try again.";
err = "An unknown error occurred (error is undefined).\nPlease try again.";
} else if (e.code && e.cmd) {
const { code, path, cmd, stderr } = e;

if (code === "ENOENT")
var err = `Command \`${path}\` not found.\nPlease install it and try again`;
err = `Command \`${path}\` not found.\nPlease install it and try again`;
else {
var err = `An error occurred while running \`${cmd}\`:\n`;
err = `An error occurred while running \`${cmd}\`:\n`;
err += stderr || `Code \`${code}\`. See the console for more info`;
}

} else {
var err = "An unknown error occurred. See the console for more info.";
err = "An unknown error occurred. See the console for more info.";
}

Alerts.show({
title: "Oops!",
body: (
Expand Down Expand Up @@ -186,7 +190,7 @@ function Newer(props: CommonProps) {
}

function Updater() {
const settings = useSettings(["notifyAboutUpdates", "autoUpdate", "autoUpdateNotification"]);
const settings = useSettings(["autoUpdate", "autoUpdateNotification"]);

const [repo, err, repoPending] = useAwaiter(getRepo, { fallbackValue: "Loading..." });

Expand All @@ -203,14 +207,6 @@ function Updater() {
return (
<SettingsTab title="Vencord Updater">
<Forms.FormTitle tag="h5">Updater Settings</Forms.FormTitle>
<Switch
value={settings.notifyAboutUpdates}
onChange={(v: boolean) => settings.notifyAboutUpdates = v}
note="Shows a notification on startup"
disabled={settings.autoUpdate}
>
Get notified about new updates
</Switch>
<Switch
value={settings.autoUpdate}
onChange={(v: boolean) => settings.autoUpdate = v}
Expand Down Expand Up @@ -253,3 +249,20 @@ function Updater() {
}

export default IS_UPDATER_DISABLED ? null : wrapTab(Updater, "Updater");

export const openUpdaterModal = IS_UPDATER_DISABLED ? null : function () {
const UpdaterTab = wrapTab(Updater, "Updater");

try {
openModal(wrapTab((modalProps: ModalProps) => (
<ModalRoot {...modalProps} size={ModalSize.MEDIUM}>
<ModalContent className="vc-updater-modal">
<ModalCloseButton onClick={modalProps.onClose} className="vc-updater-modal-close-button" />
<UpdaterTab />
</ModalContent>
</ModalRoot>
), "UpdaterModal"));
} catch {
handleSettingsTabError();
}
};
8 changes: 8 additions & 0 deletions src/components/VencordSettings/settingsStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@
/* discord also sets cursor: default which prevents the cursor from showing as text */
cursor: initial;
}

.vc-updater-modal {
padding: 1.5em !important;
}

.vc-updater-modal-close-button {
float: right;
}
6 changes: 3 additions & 3 deletions src/components/VencordSettings/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function SettingsTab({ title, children }: PropsWithChildren<{ title: stri
);
}

const onError = onlyOnce(handleComponentFailed);
export const handleSettingsTabError = onlyOnce(handleComponentFailed);

export function wrapTab(component: ComponentType, tab: string) {
export function wrapTab(component: ComponentType<any>, tab: string) {
return ErrorBoundary.wrap(component, {
message: `Failed to render the ${tab} tab. If this issue persists, try using the installer to reinstall!`,
onError,
onError: handleSettingsTabError,
});
}
2 changes: 1 addition & 1 deletion src/plugins/_api/badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default definePlugin({
patches: [
/* Patch the badge list component on user profiles */
{
find: "Messages.PROFILE_USER_BADGES,role:",
find: 'id:"premium",',
replacement: [
{
match: /&&(\i)\.push\(\{id:"premium".+?\}\);/,
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/betterSessions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# BetterSessions

Enhances the sessions (devices) menu. Allows you to view exact timestamps, give each session a custom name, and receive notifications about new sessions.

![](https://github.com/Vendicated/Vencord/assets/9750071/4a44b617-bb8f-4dcb-93f1-b7d2575ed3d8)
37 changes: 37 additions & 0 deletions src/plugins/betterSessions/components/RenameButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { openModal } from "@utils/modal";
import { Button } from "@webpack/common";

import { SessionInfo } from "../types";
import { RenameModal } from "./RenameModal";

export function RenameButton({ session, state }: { session: SessionInfo["session"], state: [string, React.Dispatch<React.SetStateAction<string>>]; }) {
return (
<Button
look={Button.Looks.LINK}
color={Button.Colors.LINK}
size={Button.Sizes.NONE}
style={{
paddingTop: "0px",
paddingBottom: "0px",
top: "-2px"
}}
onClick={() =>
openModal(props => (
<RenameModal
props={props}
session={session}
state={state}
/>
))
}
>
Rename
</Button>
);
}
94 changes: 94 additions & 0 deletions src/plugins/betterSessions/components/RenameModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot } from "@utils/modal";
import { Button, Forms, React, TextInput } from "@webpack/common";
import { KeyboardEvent } from "react";

import { SessionInfo } from "../types";
import { getDefaultName, savedSessionsCache, saveSessionsToDataStore } from "../utils";

export function RenameModal({ props, session, state }: { props: ModalProps, session: SessionInfo["session"], state: [string, React.Dispatch<React.SetStateAction<string>>]; }) {
const [title, setTitle] = state;
const [value, setValue] = React.useState(savedSessionsCache.get(session.id_hash)?.name ?? "");

function onSaveClick() {
savedSessionsCache.set(session.id_hash, { name: value, isNew: false });
if (value !== "") {
setTitle(`${value}*`);
} else {
setTitle(getDefaultName(session.client_info));
}

saveSessionsToDataStore();
props.onClose();
}

return (
<ModalRoot {...props}>
<ModalHeader>
<Forms.FormTitle tag="h4">Rename</Forms.FormTitle>
</ModalHeader>

<ModalContent>
<Forms.FormTitle tag="h5" style={{ marginTop: "10px" }}>New device name</Forms.FormTitle>
<TextInput
style={{ marginBottom: "10px" }}
placeholder={getDefaultName(session.client_info)}
value={value}
onChange={setValue}
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
onSaveClick();
}
}}
/>
<Button
style={{
marginBottom: "20px",
paddingLeft: "1px",
paddingRight: "1px",
opacity: 0.6
}}
look={Button.Looks.LINK}
color={Button.Colors.LINK}
size={Button.Sizes.NONE}
onClick={() => setValue("")}
>
Reset Name
</Button>
</ModalContent>

<ModalFooter>
<Button
color={Button.Colors.BRAND}
onClick={onSaveClick}
>
Save
</Button>
<Button
color={Button.Colors.TRANSPARENT}
look={Button.Looks.LINK}
onClick={() => props.onClose()}
>
Cancel
</Button>
</ModalFooter>
</ModalRoot >
);
}
Loading

0 comments on commit 41929d3

Please sign in to comment.