From 91feb411b3902d59fce2549fb98a611fd365fb86 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Tue, 7 Feb 2023 22:58:18 -0800 Subject: [PATCH 1/2] Add toggle to ignore CORS --- src/main/main.ts | 3 + src/renderer/api/jellyfin.api.ts | 6 +- src/renderer/api/navidrome.api.ts | 3 + src/renderer/api/subsonic.api.ts | 3 + .../servers/components/server-list.tsx | 62 +++++++++++++------ 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 2ba9bbc49..618a908e5 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -66,6 +66,8 @@ const createWindow = async () => { return path.join(RESOURCES_PATH, ...paths); }; + console.log(store.get('ignore_cors'), 'ignore_cors'); + mainWindow = new BrowserWindow({ frame: false, height: 900, @@ -81,6 +83,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..2a19bb853 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 { 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,16 @@ export const ServerList = () => { }); }; + const [ignoreCORS, setIgnoreCORS] = useLocalStorage({ + defaultValue: 'false', + key: 'ignore_cors', + }); + + const handleUpdateIgnoreCORS = (e: ChangeEvent) => { + localSettings.set('ignore_cors', e.currentTarget.checked); + setIgnoreCORS(String(e.currentTarget.checked)); + }; + return ( <> { Add server - - {serverListQuery?.map((s) => ( - - }> - - {titleCase(s.type)} - {s.name} - - - - - - - ))} - + + + {serverListQuery?.map((s) => ( + + }> + + {titleCase(s.type)} - {s.name} + + + + + + + ))} + + + + + ); }; From 796d0a72d14af344654005b3500066cc9fbc1751 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 8 Feb 2023 14:21:55 -0800 Subject: [PATCH 2/2] Add option to ignore SSL --- src/main/main.ts | 6 ++-- .../servers/components/server-list.tsx | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 618a908e5..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') { @@ -66,8 +70,6 @@ const createWindow = async () => { return path.join(RESOURCES_PATH, ...paths); }; - console.log(store.get('ignore_cors'), 'ignore_cors'); - mainWindow = new BrowserWindow({ frame: false, height: 900, diff --git a/src/renderer/features/servers/components/server-list.tsx b/src/renderer/features/servers/components/server-list.tsx index 2a19bb853..4d08d7438 100644 --- a/src/renderer/features/servers/components/server-list.tsx +++ b/src/renderer/features/servers/components/server-list.tsx @@ -1,5 +1,5 @@ import { ChangeEvent } from 'react'; -import { Group, Stack } from '@mantine/core'; +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'; @@ -32,9 +32,25 @@ export const ServerList = () => { key: 'ignore_cors', }); + const [ignoreSSL, setIgnoreSSL] = useLocalStorage({ + defaultValue: 'false', + key: 'ignore_ssl', + }); + const handleUpdateIgnoreCORS = (e: ChangeEvent) => { - localSettings.set('ignore_cors', e.currentTarget.checked); 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 ( @@ -77,13 +93,21 @@ export const ServerList = () => { ))} - + + + + + );