Ignore CORS & SSL (#23)
* Add toggle to ignore CORS * Add option to ignore SSL
This commit is contained in:
parent
8eec6b6b8a
commit
c878e36015
5 changed files with 83 additions and 20 deletions
|
@ -31,6 +31,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') {
|
||||
|
@ -85,6 +89,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,
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: [
|
||||
|
@ -122,6 +124,7 @@ const api = ky.create({
|
|||
},
|
||||
],
|
||||
},
|
||||
mode: IGNORE_CORS ? 'cors' : undefined,
|
||||
});
|
||||
|
||||
const authenticate = async (
|
||||
|
|
|
@ -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;
|
||||
|
@ -93,6 +95,7 @@ const api = ky.create({
|
|||
},
|
||||
],
|
||||
},
|
||||
mode: IGNORE_CORS ? 'cors' : undefined,
|
||||
});
|
||||
|
||||
const getDefaultParams = (server: ServerListItem | null) => {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Reference in a new issue