Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preferred stream settings #1060

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/renderer/components/ScreenSharePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import "./screenSharePicker.css";

import { closeModal, Logger, Modals, ModalSize, openModal, useAwaiter } from "@vencord/types/utils";
import { findStoreLazy, onceReady } from "@vencord/types/webpack";
import { findExportedComponentLazy, findStoreLazy, onceReady } from "@vencord/types/webpack";
import {
Button,
Card,
Expand Down Expand Up @@ -255,11 +255,11 @@ function AudioSettingsModal({
<Switch
hideBorder
onChange={v =>
(Settings.audio = {
...Settings.audio,
ignoreDevices: v,
deviceSelect: v ? false : Settings.audio?.deviceSelect
})
(Settings.audio = {
...Settings.audio,
ignoreDevices: v,
deviceSelect: v ? false : Settings.audio?.deviceSelect
})
}
value={Settings.audio?.ignoreDevices ?? true}
note={<>Exclude device nodes, such as nodes belonging to microphones or speakers.</>}
Expand Down Expand Up @@ -315,6 +315,8 @@ function StreamSettings({
setSettings: Dispatch<SetStateAction<StreamSettings>>;
skipPicker: boolean;
}) {
const Checkbox = findExportedComponentLazy("Checkbox", "Switch");

const Settings = useSettings();

const [thumb] = useAwaiter(
Expand Down Expand Up @@ -453,6 +455,18 @@ function StreamSettings({
/>
)}
</Card>

<div className="vcd-screen-picker-save-settings">
<Checkbox
onChange={(v: React.ChangeEvent<HTMLInputElement>) => {
Settings.stream = { ...Settings.stream, preferred: v.target.checked };
}}
value={Settings.stream?.preferred ?? true}
type={"inverted"}
>
Remember stream settings
</Checkbox>
</div>
</div>
);
}
Expand Down Expand Up @@ -632,9 +646,9 @@ function AudioSourcePickerLinux({

const allSources = sources.ok
? [...specialSources, ...sources.targets]
.map(target => mapToAudioItem(target, granularSelect, deviceSelect))
.flat()
.filter(uniqueName)
.map(target => mapToAudioItem(target, granularSelect, deviceSelect))
.flat()
.filter(uniqueName)
: [];

return (
Expand Down Expand Up @@ -699,11 +713,13 @@ function ModalComponent({
close: () => void;
skipPicker: boolean;
}) {
const Settings = useSettings();

const [selected, setSelected] = useState<string | undefined>(skipPicker ? screens[0].id : void 0);
const [settings, setSettings] = useState<StreamSettings>({
resolution: "720",
fps: "30",
contentHint: "motion",
resolution: Settings.stream?.preferred ? (Settings.stream.resolution as StreamResolution) : "720",
fps: Settings.stream?.preferred ? (Settings.stream.fps as StreamFps) : "30",
contentHint: Settings.stream?.preferred ? Settings.stream.contentHint : "motion",
audio: true,
includeSources: "None"
});
Expand Down Expand Up @@ -779,6 +795,18 @@ function ModalComponent({
logger.error("Failed to apply constraints.", e);
}
}, 100);

if (Settings.stream?.preferred) {
if (settings.resolution !== Settings.stream?.resolution) {
Settings.stream.resolution = settings.resolution;
}
if (settings.fps !== Settings.stream?.fps) {
Settings.stream.fps = settings.fps;
}
if (settings.contentHint !== Settings.stream?.contentHint) {
Settings.stream.contentHint = settings.contentHint;
}
}
} catch (error) {
logger.error("Error while submitting stream.", error);
}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/screenSharePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@
line-height: 20px;
font-weight: 400;
}

.vcd-screen-picker-save-settings{
margin-top: 0.5em;
}
7 changes: 7 additions & 0 deletions src/shared/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export interface Settings {
onlySpeakers?: boolean;
onlyDefaultSpeakers?: boolean;
};

stream?: {
preferred?: boolean;
resolution?: string;
fps?: string;
contentHint?: string;
};
}

export interface State {
Expand Down