diff --git a/lib/gui/app/components/settings/settings.tsx b/lib/gui/app/components/settings/settings.tsx index dd9473aa..f736c392 100644 --- a/lib/gui/app/components/settings/settings.tsx +++ b/lib/gui/app/components/settings/settings.tsx @@ -27,7 +27,6 @@ import * as settings from '../../models/settings'; import * as analytics from '../../modules/analytics'; import { open as openExternal } from '../../os/open-external/services/open-external'; import { Modal } from '../../styled-components'; -import { unlinkSync, readFileSync } from 'fs'; interface Setting { name: string; @@ -66,13 +65,9 @@ const InfoBox = (props: any) => ( export function SettingsModal({ toggleModal }: SettingsModalProps) { const [settingsList, setCurrentSettingsList] = React.useState([]); const [showDiagScreen, setShowDiagScreen] = React.useState(false); - const [diagApiIsUp, setDiagApiIsUp] = React.useState(false); - const [showDiagButton, setShowDiagButton] = React.useState(false); const [currentSettings, setCurrentSettings] = React.useState< _.Dictionary >({}); - const [errorMessage, setErrorMessage] = React.useState(''); - let diagCount = 0; React.useEffect(() => { (async () => { @@ -90,20 +85,6 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { })(); }); - React.useEffect(() => { - (async () => { - try { - const result = await fetch('http://localhost:3000/api/ping'); - if (result.ok) { - setShowDiagButton(true); - setDiagApiIsUp(true); - } - } catch { - // no diag container - } - })(); - }, []); - const toggleSetting = async (setting: string) => { const value = currentSettings[setting]; analytics.logEvent('Toggle setting', { setting, value }); @@ -122,82 +103,6 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { setShowDiagScreen(true); }; - const prepareDiag = () => { - if (++diagCount > 5) { - setShowDiagButton(true); - } - }; - - const startDiag = async () => { - try { - unlinkSync('/usr/src/diag-data/startup.lock'); - } catch (error) { - console.log("Can't remove diag lock", error); - } - - try { - const supUrl: string = readFileSync('/usr/src/diag-data/start.url', { - encoding: 'utf8', - flag: 'r', - }); - - const startRes = await fetch(supUrl, { - method: 'POST', - body: JSON.stringify({ serviceName: 'diag-runner', force: true }), - headers: { - 'Content-Type': 'application/json', - }, - }); - - if (startRes.ok) { - // good - } else { - setErrorMessage(`${errorMessage} :: ${startRes.statusText}`); - } - } catch (error) { - console.log('Error in starting diag', error); - } - }; - - const removeDiag = async () => { - setErrorMessage(''); - try { - const supervisorUrl = await ( - await fetch(`http://localhost:3000/api/supervisor/url`) - ).text(); - const supervisorApiKey = await ( - await fetch(`http://localhost:3000/api/supervisor/apiKey`) - ).text(); - const appId = await ( - await fetch(`http://localhost:3000/api/supervisor/appid`) - ).text(); - const createLock = await fetch( - `http://localhost:3000/api/supervisor/createlock`, - ); - - const stopRes = await fetch( - `${supervisorUrl}/v2/applications/${appId}/stop-service?apikey=${supervisorApiKey}`, - { - method: 'POST', - body: JSON.stringify({ serviceName: 'diag-runner', force: true }), - headers: { - 'Content-Type': 'application/json', - }, - }, - ); - - if (!stopRes.ok) { - setErrorMessage(`Stop call failed | ${stopRes.statusText}`); - } - - if (!createLock.ok) { - setErrorMessage(`${errorMessage} :: Create lock file failed :: `); - } - } catch (err) { - setErrorMessage(err); - } - }; - return ( {version} - {showDiagButton ? ( - - {diagApiIsUp ? ( - <> - - - ) : ( - <> - - - )} - {errorMessage} - - ) : ( - <> - )} + + + + {showDiagScreen ? (