diff --git a/src/main/main.ts b/src/main/main.ts index 2ba9bbc49..f50cd5fac 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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') { @@ -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, }); diff --git a/src/renderer/api/jellyfin.api.ts b/src/renderer/api/jellyfin.api.ts index f939cdcf4..2efb3d9d6 100644 --- a/src/renderer/api/jellyfin.api.ts +++ b/src/renderer/api/jellyfin.api.ts @@ -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, diff --git a/src/renderer/api/navidrome.api.ts b/src/renderer/api/navidrome.api.ts index 0b9703577..e74de20b3 100644 --- a/src/renderer/api/navidrome.api.ts +++ b/src/renderer/api/navidrome.api.ts @@ -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 ( diff --git a/src/renderer/api/subsonic.api.ts b/src/renderer/api/subsonic.api.ts index 8c441bf6c..df3b4fded 100644 --- a/src/renderer/api/subsonic.api.ts +++ b/src/renderer/api/subsonic.api.ts @@ -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) => { diff --git a/src/renderer/features/servers/components/server-list.tsx b/src/renderer/features/servers/components/server-list.tsx index 2ce915cc0..4d08d7438 100644 --- a/src/renderer/features/servers/components/server-list.tsx +++ b/src/renderer/features/servers/components/server-list.tsx @@ -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) => { + setIgnoreCORS(String(e.currentTarget.checked)); + + if (isElectron()) { + localSettings?.set('ignore_cors', e.currentTarget.checked); + } + }; + + const handleUpdateIgnoreSSL = (e: ChangeEvent) => { + setIgnoreSSL(String(e.currentTarget.checked)); + + if (isElectron()) { + localSettings?.set('ignore_ssl', e.currentTarget.checked); + } + }; + return ( <> { Add server - - {serverListQuery?.map((s) => ( - - }> - - {titleCase(s.type)} - {s.name} - - - - - - - ))} - + + + {serverListQuery?.map((s) => ( + + }> + + {titleCase(s.type)} - {s.name} + + + + + + + ))} + + + + + + + + + ); };