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

Ignore CORS #23

Merged
merged 2 commits into from
Feb 10, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class AppUpdater {
}
}

if (store.get('ignore_ssl')) {
app.commandLine.appendSwitch('ignore-certificate-errors');
}

let mainWindow: BrowserWindow | null = null;

if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -81,6 +85,7 @@ const createWindow = async () => {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
webSecurity: store.get('ignore_cors') ? false : undefined,
},
width: 1440,
});
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/api/jellyfin.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
import { parseSearchParams } from '/@/renderer/utils';
import packageJson from '../../../package.json';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const getCommaDelimitedString = (value: string[]) => {
return value.join(',');
};

const api = ky.create({});
const api = ky.create({
mode: IGNORE_CORS ? 'cors' : undefined,
});

const authenticate = async (
url: string,
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/api/navidrome.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
import { parseSearchParams } from '/@/renderer/utils';
import { subsonicApi } from '/@/renderer/api/subsonic.api';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const api = ky.create({
hooks: {
afterResponse: [
Expand Down Expand Up @@ -122,6 +124,7 @@ const api = ky.create({
},
],
},
mode: IGNORE_CORS ? 'cors' : undefined,
});

const authenticate = async (
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/api/subsonic.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
import { toast } from '/@/renderer/components/toast';
import { nanoid } from 'nanoid/non-secure';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const getCoverArtUrl = (args: {
baseUrl: string;
coverArtId: string;
Expand Down Expand Up @@ -93,6 +95,7 @@ const api = ky.create({
},
],
},
mode: IGNORE_CORS ? 'cors' : undefined,
});

const getDefaultParams = (server: ServerListItem | null) => {
Expand Down
86 changes: 67 additions & 19 deletions src/renderer/features/servers/components/server-list.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Group } from '@mantine/core';
import { Accordion, Button, ContextModalVars } from '/@/renderer/components';
import { ChangeEvent } from 'react';
import { Divider, Group, Stack } from '@mantine/core';
import { Accordion, Button, ContextModalVars, Switch } from '/@/renderer/components';
import { useLocalStorage } from '@mantine/hooks';
import { openContextModal } from '@mantine/modals';
import isElectron from 'is-electron';
import { RiAddFill, RiServerFill } from 'react-icons/ri';
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
import { ServerListItem } from '/@/renderer/features/servers/components/server-list-item';
import { useServerList } from '/@/renderer/store';
import { titleCase } from '/@/renderer/utils';

const localSettings = isElectron() ? window.electron.localSettings : null;

export const ServerList = () => {
const serverListQuery = useServerList();

Expand All @@ -22,6 +27,32 @@ export const ServerList = () => {
});
};

const [ignoreCORS, setIgnoreCORS] = useLocalStorage({
defaultValue: 'false',
key: 'ignore_cors',
});

const [ignoreSSL, setIgnoreSSL] = useLocalStorage({
defaultValue: 'false',
key: 'ignore_ssl',
});

const handleUpdateIgnoreCORS = (e: ChangeEvent<HTMLInputElement>) => {
setIgnoreCORS(String(e.currentTarget.checked));

if (isElectron()) {
localSettings?.set('ignore_cors', e.currentTarget.checked);
}
};

const handleUpdateIgnoreSSL = (e: ChangeEvent<HTMLInputElement>) => {
setIgnoreSSL(String(e.currentTarget.checked));

if (isElectron()) {
localSettings?.set('ignore_ssl', e.currentTarget.checked);
}
};

return (
<>
<Group
Expand All @@ -44,23 +75,40 @@ export const ServerList = () => {
Add server
</Button>
</Group>
<Accordion variant="separated">
{serverListQuery?.map((s) => (
<Accordion.Item
key={s.id}
value={s.name}
>
<Accordion.Control icon={<RiServerFill size={15} />}>
<Group position="apart">
{titleCase(s.type)} - {s.name}
</Group>
</Accordion.Control>
<Accordion.Panel>
<ServerListItem server={s} />
</Accordion.Panel>
</Accordion.Item>
))}
</Accordion>
<Stack>
<Accordion variant="separated">
{serverListQuery?.map((s) => (
<Accordion.Item
key={s.id}
value={s.name}
>
<Accordion.Control icon={<RiServerFill size={15} />}>
<Group position="apart">
{titleCase(s.type)} - {s.name}
</Group>
</Accordion.Control>
<Accordion.Panel>
<ServerListItem server={s} />
</Accordion.Panel>
</Accordion.Item>
))}
</Accordion>
<Divider />
<Group>
<Switch
checked={ignoreCORS === 'true'}
label="Ignore CORS (requires restart)"
onChange={handleUpdateIgnoreCORS}
/>
</Group>
<Group>
<Switch
checked={ignoreSSL === 'true'}
label="Ignore SSL (requires restart)"
onChange={handleUpdateIgnoreSSL}
/>
</Group>
</Stack>
</>
);
};