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;
|
let mainWindow: BrowserWindow | null = null;
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
@ -85,6 +89,7 @@ const createWindow = async () => {
|
||||||
preload: app.isPackaged
|
preload: app.isPackaged
|
||||||
? path.join(__dirname, 'preload.js')
|
? path.join(__dirname, 'preload.js')
|
||||||
: path.join(__dirname, '../../.erb/dll/preload.js'),
|
: path.join(__dirname, '../../.erb/dll/preload.js'),
|
||||||
|
webSecurity: store.get('ignore_cors') ? false : undefined,
|
||||||
},
|
},
|
||||||
width: 1440,
|
width: 1440,
|
||||||
});
|
});
|
||||||
|
|
|
@ -78,11 +78,15 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
|
||||||
import { parseSearchParams } from '/@/renderer/utils';
|
import { parseSearchParams } from '/@/renderer/utils';
|
||||||
import packageJson from '../../../package.json';
|
import packageJson from '../../../package.json';
|
||||||
|
|
||||||
|
const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';
|
||||||
|
|
||||||
const getCommaDelimitedString = (value: string[]) => {
|
const getCommaDelimitedString = (value: string[]) => {
|
||||||
return value.join(',');
|
return value.join(',');
|
||||||
};
|
};
|
||||||
|
|
||||||
const api = ky.create({});
|
const api = ky.create({
|
||||||
|
mode: IGNORE_CORS ? 'cors' : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
const authenticate = async (
|
const authenticate = async (
|
||||||
url: string,
|
url: string,
|
||||||
|
|
|
@ -88,6 +88,8 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
|
||||||
import { parseSearchParams } from '/@/renderer/utils';
|
import { parseSearchParams } from '/@/renderer/utils';
|
||||||
import { subsonicApi } from '/@/renderer/api/subsonic.api';
|
import { subsonicApi } from '/@/renderer/api/subsonic.api';
|
||||||
|
|
||||||
|
const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';
|
||||||
|
|
||||||
const api = ky.create({
|
const api = ky.create({
|
||||||
hooks: {
|
hooks: {
|
||||||
afterResponse: [
|
afterResponse: [
|
||||||
|
@ -122,6 +124,7 @@ const api = ky.create({
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
mode: IGNORE_CORS ? 'cors' : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const authenticate = async (
|
const authenticate = async (
|
||||||
|
|
|
@ -52,6 +52,8 @@ import {
|
||||||
import { toast } from '/@/renderer/components/toast';
|
import { toast } from '/@/renderer/components/toast';
|
||||||
import { nanoid } from 'nanoid/non-secure';
|
import { nanoid } from 'nanoid/non-secure';
|
||||||
|
|
||||||
|
const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';
|
||||||
|
|
||||||
const getCoverArtUrl = (args: {
|
const getCoverArtUrl = (args: {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
coverArtId: string;
|
coverArtId: string;
|
||||||
|
@ -93,6 +95,7 @@ const api = ky.create({
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
mode: IGNORE_CORS ? 'cors' : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getDefaultParams = (server: ServerListItem | null) => {
|
const getDefaultParams = (server: ServerListItem | null) => {
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import { Group } from '@mantine/core';
|
import { ChangeEvent } from 'react';
|
||||||
import { Accordion, Button, ContextModalVars } from '/@/renderer/components';
|
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 { openContextModal } from '@mantine/modals';
|
||||||
|
import isElectron from 'is-electron';
|
||||||
import { RiAddFill, RiServerFill } from 'react-icons/ri';
|
import { RiAddFill, RiServerFill } from 'react-icons/ri';
|
||||||
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
|
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
|
||||||
import { ServerListItem } from '/@/renderer/features/servers/components/server-list-item';
|
import { ServerListItem } from '/@/renderer/features/servers/components/server-list-item';
|
||||||
import { useServerList } from '/@/renderer/store';
|
import { useServerList } from '/@/renderer/store';
|
||||||
import { titleCase } from '/@/renderer/utils';
|
import { titleCase } from '/@/renderer/utils';
|
||||||
|
|
||||||
|
const localSettings = isElectron() ? window.electron.localSettings : null;
|
||||||
|
|
||||||
export const ServerList = () => {
|
export const ServerList = () => {
|
||||||
const serverListQuery = useServerList();
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Group
|
<Group
|
||||||
|
@ -44,6 +75,7 @@ export const ServerList = () => {
|
||||||
Add server
|
Add server
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Stack>
|
||||||
<Accordion variant="separated">
|
<Accordion variant="separated">
|
||||||
{serverListQuery?.map((s) => (
|
{serverListQuery?.map((s) => (
|
||||||
<Accordion.Item
|
<Accordion.Item
|
||||||
|
@ -61,6 +93,22 @@ export const ServerList = () => {
|
||||||
</Accordion.Item>
|
</Accordion.Item>
|
||||||
))}
|
))}
|
||||||
</Accordion>
|
</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