Skip to content

Commit c5c3eee

Browse files
Update useSettings.tsx
if it has not been set by the user yet set it correctly for them
1 parent 69b1dc4 commit c5c3eee

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

app/lib/hooks/useSettings.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useCallback, useEffect, useState } from 'react';
1111
import Cookies from 'js-cookie';
1212
import type { IProviderSetting, ProviderInfo } from '~/types/model';
1313
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
14+
import commit from '~/commit.json';
1415

1516
export function useSettings() {
1617
const providers = useStore(providersStore);
@@ -20,6 +21,22 @@ export function useSettings() {
2021
const useLatest = useStore(useLatestBranch);
2122
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
2223

24+
// Function to check if we're on stable version
25+
const checkIsStableVersion = async () => {
26+
try {
27+
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
28+
if (!stableResponse.ok) {
29+
console.warn('Failed to fetch stable commit info');
30+
return false;
31+
}
32+
const stableData = await stableResponse.json();
33+
return commit.commit === stableData.commit;
34+
} catch (error) {
35+
console.warn('Error checking stable version:', error);
36+
return false;
37+
}
38+
};
39+
2340
// reading values from cookies on mount
2441
useEffect(() => {
2542
const savedProviders = Cookies.get('providers');
@@ -63,10 +80,16 @@ export function useSettings() {
6380
isLocalModelsEnabled.set(savedLocalModels === 'true');
6481
}
6582

66-
// load latest branch setting from cookies
83+
// load latest branch setting from cookies or determine based on version
6784
const savedLatestBranch = Cookies.get('useLatestBranch');
68-
69-
if (savedLatestBranch) {
85+
if (savedLatestBranch === undefined) {
86+
// If setting hasn't been set by user, check version
87+
checkIsStableVersion().then(isStable => {
88+
const shouldUseLatest = !isStable;
89+
useLatestBranch.set(shouldUseLatest);
90+
Cookies.set('useLatestBranch', String(shouldUseLatest));
91+
});
92+
} else {
7093
useLatestBranch.set(savedLatestBranch === 'true');
7194
}
7295
}, []);

0 commit comments

Comments
 (0)