Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/renderer/api/cadt/v1/system/system.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ const systemApi = cadtApi.injectEndpoints({
method: 'GET',
}),
transformResponse(baseQueryReturnValue: BaseQueryResult<Config>): Config | undefined {
// Check if response is empty, null, or HTML content (which would indicate a 404 served as index.html)
if (_.isEmpty(baseQueryReturnValue) || _.isNil(baseQueryReturnValue)) {
return undefined;
}
return baseQueryReturnValue;

if (typeof baseQueryReturnValue === 'string' && baseQueryReturnValue.includes('<!doctype html>')) {
return undefined;
}

// Ensure it's a valid config object with expected structure
if (typeof baseQueryReturnValue === 'object' && baseQueryReturnValue !== null) {
return baseQueryReturnValue as Config;
}

return undefined;
},
}),
getThemeColors: builder.query<any, void>({
Expand All @@ -64,10 +75,19 @@ const systemApi = cadtApi.injectEndpoints({
method: 'GET',
}),
transformResponse(baseQueryReturnValue: BaseQueryResult<any>): any {
if (_.isEmpty(baseQueryReturnValue) || _.isNil(baseQueryReturnValue)) {
// Check if response is empty, null, or HTML content (which would indicate a 404 served as index.html)
if (
_.isEmpty(baseQueryReturnValue) ||
_.isNil(baseQueryReturnValue) ||
(typeof baseQueryReturnValue === 'string' && baseQueryReturnValue.includes('<!doctype html>'))
) {
return undefined;
}
return baseQueryReturnValue;
// Ensure it's a valid object
if (typeof baseQueryReturnValue === 'object' && baseQueryReturnValue !== null) {
return baseQueryReturnValue;
}
return undefined;
},
}),
}),
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/components/blocks/buttons/ConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useGetHealthQuery } from '@/api/cadt/v1/system';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '@/store';
import { resetApiHost } from '@/store/slices/app';
import { cadtApi } from '@/api/cadt/v1';

const ConnectButton: React.FC = () => {
const location = useLocation();
Expand All @@ -32,6 +33,13 @@ const ConnectButton: React.FC = () => {

const handleDisconnect = () => {
dispatch(resetApiHost());
// Clear persisted storage to prevent auto-reconnection
localStorage.removeItem('persist:app');
sessionStorage.removeItem('persist:app');

// Clear RTK Query cache to force fresh health check
dispatch(cadtApi.util.resetApiState());

setTimeout(() => window.location.reload(), 0);
};

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/store/slices/app/app.initialstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface AppState {

const initialState: AppState = {
locale: null,
apiHost: 'http://localhost:31310',
apiHost: '', // Empty string means no default API host
apiKey: null,
configFileLoaded: false,
isDarkTheme: false,
Expand Down
Loading