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

refactor: remove sync service calls around add source flow #5053

Open
wants to merge 3 commits into
base: master
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
10 changes: 7 additions & 3 deletions app/components-react/root/StudioEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ export default function StudioEditor() {
const [studioModeStacked, setStudioModeStacked] = useState(false);
const [verticalPlaceholder, setVerticalPlaceholder] = useState(false);
const [messageActive, setMessageActive] = useState(false);
const studioModeTransitionName = useMemo(() => TransitionsService.getStudioTransitionName(), [
v.studioMode,
]);

const [studioModeTransitionName, setStudioModeTransitionName] = useState<string>();
useEffect(() => {
if (!studioModeTransitionName) {
TransitionsService.actions.return.getStudioTransitionName().then(setStudioModeTransitionName);
}
}, [v.studioMode]);

const sourceId = useMemo(() => {
const dualOutputMode = v.showHorizontalDisplay && v.showVerticalDisplay;
Expand Down
16 changes: 12 additions & 4 deletions app/components-react/windows/AddSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import styles from './AddSource.m.less';
import { TextInput, SwitchInput } from 'components-react/shared/inputs';
import Form, { useForm } from 'components-react/shared/inputs/Form';
import Scrollable from 'components-react/shared/Scrollable';
import { IObsListOption } from '../../components/obs/inputs/ObsInput';

export default function AddSource() {
const {
Expand Down Expand Up @@ -57,6 +58,15 @@ export default function AddSource() {

const existingSources = sources.map(source => ({ name: source.name, value: source.sourceId }));

// TODO: maybe refactor into a `useSourceTypes` hook
const [sourceTypes, setSourceTypes] = useState<IObsListOption<TSourceType>[]>([]);

useEffect(() => {
if (!sourceTypes.length) {
SourcesService.actions.return.getAvailableSourcesTypesList().then(setSourceTypes);
}
}, []);

useEffect(() => {
const suggestName = (name: string) => SourcesService.views.suggestName(name);
let name;
Expand All @@ -80,14 +90,12 @@ export default function AddSource() {
} else {
const sourceDescription =
sourceType &&
SourcesService.getAvailableSourcesTypesList().find(
sourceTypeDef => sourceTypeDef.value === sourceType,
)?.description;
sourceTypes.find(sourceTypeDef => sourceTypeDef.value === sourceType)?.description;

name = suggestName(sourceDescription || '');
}
setName(name);
}, []);
}, [sourceTypes]);

function close() {
WindowsService.actions.closeChildWindow();
Expand Down
14 changes: 11 additions & 3 deletions app/components-react/windows/source-showcase/SourceGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import { Empty, Row, Col, PageHeader, Button } from 'antd';
import Scrollable from 'components-react/shared/Scrollable';
import { Services } from 'components-react/service-provider';
Expand All @@ -16,6 +16,8 @@ import { EAvailableFeatures } from 'services/incremental-rollout';
import { useRealmObject } from 'components-react/hooks/realm';

export default function SourceGrid(p: { activeTab: string }) {
const [sourceTypes, setSourceTypes] = useState<IObsListOption<TSourceType>[]>([]);

const {
SourcesService,
UserService,
Expand Down Expand Up @@ -71,13 +73,19 @@ export default function SourceGrid(p: { activeTab: string }) {
[],
);

useEffect(() => {
if (!sourceTypes.length) {
SourcesService.actions.return.getAvailableSourcesTypesList().then(setSourceTypes);
}
}, []);

const availableSources = useMemo(() => {
const guestCamAvailable =
(IncrementalRolloutService.views.featureIsEnabled(EAvailableFeatures.guestCamBeta) ||
IncrementalRolloutService.views.featureIsEnabled(EAvailableFeatures.guestCaProduction)) &&
UserService.views.isLoggedIn;

return SourcesService.getAvailableSourcesTypesList().filter(type => {
return sourceTypes.filter(type => {
// Freetype on windows is hidden
if (type.value === 'text_ft2_source' && byOS({ [OS.Windows]: true, [OS.Mac]: false })) {
return;
Expand All @@ -89,7 +97,7 @@ export default function SourceGrid(p: { activeTab: string }) {

return !(type.value === 'scene' && ScenesService.views.scenes.length <= 1);
});
}, []);
}, [sourceTypes]);

const essentialSources = useMemo(() => {
const essentialDefaults = availableSources.filter(source =>
Expand Down
14 changes: 10 additions & 4 deletions app/components-react/windows/source-showcase/useSourceShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WidgetType } from 'services/widgets';
import { byOS, OS } from 'util/operating-systems';
import { IAppSource } from 'services/platform-apps';
import { initStore, useController } from 'components-react/hooks/zustand';
import { IObsListOption } from '../../../components/obs/inputs/ObsInput';

interface ISelectSourceOptions {
propertiesManager?: TPropertiesManager;
Expand All @@ -26,8 +27,15 @@ export class SourceShowcaseController {
: 'ffmpeg_source') as TInspectableSource,
inspectedAppId: '',
inspectedAppSourceId: '',
availableSourceTypes: [] as TSourceType[],
});

init() {
this.sourcesService.actions.return.getAvailableSourcesTypes().then(sourceTypes => {
this.store.setState({ availableSourceTypes: sourceTypes });
});
}

private get sourcesService() {
return Services.SourcesService;
}
Expand Down Expand Up @@ -70,9 +78,7 @@ export class SourceShowcaseController {
this.selectSource('image_source', { propertiesManager: 'iconLibrary' });
} else if (inspectedSource === 'app_source') {
this.selectAppSource(this.store.inspectedAppId, this.store.inspectedAppSourceId);
} else if (
this.sourcesService.getAvailableSourcesTypes().includes(inspectedSource as TSourceType)
) {
} else if (this.store.availableSourceTypes.includes(inspectedSource as TSourceType)) {
this.selectSource(inspectedSource as TSourceType);
}
}
Expand All @@ -81,7 +87,7 @@ export class SourceShowcaseController {
const managerType = options.propertiesManager || 'default';
const propertiesManagerSettings: Dictionary<any> = { ...omit(options, 'propertiesManager') };

this.sourcesService.showAddSource(sourceType, {
this.sourcesService.actions.showAddSource(sourceType, {
propertiesManagerSettings,
propertiesManager: managerType,
});
Expand Down
6 changes: 4 additions & 2 deletions app/util/menus/EditMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class EditMenu extends Menu {
this.appendEditMenuItems();
}

private appendEditMenuItems() {
private async appendEditMenuItems() {
if (this.scene) {
this.append({
label: $t('Paste (Reference)'),
Expand Down Expand Up @@ -356,7 +356,9 @@ export class EditMenu extends Menu {
},
});

const filtersCount = this.sourceFiltersService.getFilters(this.source.sourceId).length;
const filtersCount = (
await this.sourceFiltersService.actions.return.getFilters(this.source.sourceId)
).length;

this.append({
label: $t('Filters') + (filtersCount > 0 ? ` (${filtersCount})` : ''),
Expand Down
10 changes: 5 additions & 5 deletions test/helpers/webdriver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export function useWebdriver(options: ITestRunnerOptions = {}) {
await focusMain();

// await t.context.app.webContents.executeJavaScript(disableTransitionsCode);
app.client.execute(disableTransitionsCode);
await app.client.execute(disableTransitionsCode);
await focusMain();

// Wait up to N seconds before giving up looking for an element.
Expand All @@ -296,7 +296,7 @@ export function useWebdriver(options: ITestRunnerOptions = {}) {
await focusChild();

// await t.context.app.webContents.executeJavaScript(disableTransitionsCode);
app.client.execute(disableTransitionsCode);
await app.client.execute(disableTransitionsCode);
await focusMain();
appIsRunning = true;

Expand Down Expand Up @@ -332,7 +332,7 @@ export function useWebdriver(options: ITestRunnerOptions = {}) {
*/
async function checkErrorsInLogFile(t: TExecutionContext) {
await sleep(1000); // electron-log needs some time to write down logs
const logs: string = await readLogs();
const logs: string = readLogs();
lastLogs = logs;
let ignoringErrors = false;
const errors = logs
Expand Down Expand Up @@ -428,7 +428,7 @@ export function useWebdriver(options: ITestRunnerOptions = {}) {
}
}
} catch (e: unknown) {
fail('Test finalization failed');
fail('Test finalization failed ' + (e as Error)?.message);
console.error(e);
}

Expand All @@ -451,7 +451,7 @@ export function useWebdriver(options: ITestRunnerOptions = {}) {
test.after.always(async t => {
if (appIsRunning) await stopAppFn(t);
if (!testPassed) saveFailedTestsToFile([testName]);
await saveTestStatsToFile(testStats);
saveTestStatsToFile(testStats);
});

/**
Expand Down
Loading