mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-28 05:36:34 +00:00
patch: cleaned up settings page from diag
This commit is contained in:
parent
7690f0e861
commit
708750cc85
@ -27,7 +27,6 @@ import * as settings from '../../models/settings';
|
|||||||
import * as analytics from '../../modules/analytics';
|
import * as analytics from '../../modules/analytics';
|
||||||
import { open as openExternal } from '../../os/open-external/services/open-external';
|
import { open as openExternal } from '../../os/open-external/services/open-external';
|
||||||
import { Modal } from '../../styled-components';
|
import { Modal } from '../../styled-components';
|
||||||
import { unlinkSync, readFileSync } from 'fs';
|
|
||||||
|
|
||||||
interface Setting {
|
interface Setting {
|
||||||
name: string;
|
name: string;
|
||||||
@ -66,13 +65,9 @@ const InfoBox = (props: any) => (
|
|||||||
export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
||||||
const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
|
const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
|
||||||
const [showDiagScreen, setShowDiagScreen] = React.useState<boolean>(false);
|
const [showDiagScreen, setShowDiagScreen] = React.useState<boolean>(false);
|
||||||
const [diagApiIsUp, setDiagApiIsUp] = React.useState<boolean>(false);
|
|
||||||
const [showDiagButton, setShowDiagButton] = React.useState<boolean>(false);
|
|
||||||
const [currentSettings, setCurrentSettings] = React.useState<
|
const [currentSettings, setCurrentSettings] = React.useState<
|
||||||
_.Dictionary<boolean>
|
_.Dictionary<boolean>
|
||||||
>({});
|
>({});
|
||||||
const [errorMessage, setErrorMessage] = React.useState<string>('');
|
|
||||||
let diagCount = 0;
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
(async () => {
|
(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 toggleSetting = async (setting: string) => {
|
||||||
const value = currentSettings[setting];
|
const value = currentSettings[setting];
|
||||||
analytics.logEvent('Toggle setting', { setting, value });
|
analytics.logEvent('Toggle setting', { setting, value });
|
||||||
@ -122,82 +103,6 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
setShowDiagScreen(true);
|
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 (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
titleElement={
|
titleElement={
|
||||||
@ -240,7 +145,6 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
openExternal(
|
openExternal(
|
||||||
'https://github.com/balena-io/etcher/blob/master/CHANGELOG.md',
|
'https://github.com/balena-io/etcher/blob/master/CHANGELOG.md',
|
||||||
);
|
);
|
||||||
prepareDiag();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<GithubSvg
|
<GithubSvg
|
||||||
@ -250,10 +154,8 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
/>
|
/>
|
||||||
<Txt style={{ borderBottom: '1px solid #00aeef' }}>{version}</Txt>
|
<Txt style={{ borderBottom: '1px solid #00aeef' }}>{version}</Txt>
|
||||||
</Flex>
|
</Flex>
|
||||||
{showDiagButton ? (
|
|
||||||
<Box>
|
<Box>
|
||||||
{diagApiIsUp ? (
|
|
||||||
<>
|
|
||||||
<Button
|
<Button
|
||||||
icon={<FontAwesomeIcon icon={faChartBar} />}
|
icon={<FontAwesomeIcon icon={faChartBar} />}
|
||||||
onClick={() => openDiagFrame()}
|
onClick={() => openDiagFrame()}
|
||||||
@ -261,23 +163,7 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
|
|||||||
>
|
>
|
||||||
Run self-test
|
Run self-test
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
icon={<FontAwesomeIcon icon={faChartBar} />}
|
|
||||||
plain
|
|
||||||
onClick={() => startDiag()}
|
|
||||||
>
|
|
||||||
Start diag container
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Txt>{errorMessage}</Txt>
|
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{showDiagScreen ? (
|
{showDiagScreen ? (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user