Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab3f897

Browse files
committed
feat: default workspace proxy based on latency
Auto select the proxy on first load, then defer to user selection.The auto selected proxy will not update again once set.
1 parent67e4024 commitab3f897

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

‎site/src/contexts/ProxyContext.tsx‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,30 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
128128
// updateProxy is a helper function that when called will
129129
// update the proxy being used.
130130
constupdateProxy=useCallback(()=>{
131+
constuserProxy=loadUserSelectedProxy();
131132
// Update the saved user proxy for the caller.
132-
setUserSavedProxy(loadUserSelectedProxy());
133-
setProxy(
134-
getPreferredProxy(
135-
proxiesResp??[],
136-
loadUserSelectedProxy(),
137-
proxyLatencies,
138-
// Do not auto select based on latencies, as inconsistent latencies can cause this
139-
// to behave poorly.
140-
false,
141-
),
142-
);
133+
setUserSavedProxy(userProxy);
134+
135+
// preferred proxy is the proxy that will be used.
136+
// 1. It first selects from the user selected proxy.
137+
// 2. If no user selected proxy is found, it will select
138+
// the best proxy based on latency.
139+
// 2a. The auto select is saved to local storage. So latency changes will not change
140+
// the selected proxy, unless the user manually changes it from the auto selected.
141+
constpreferred=getPreferredProxy(
142+
proxiesResp??[],
143+
userProxy,
144+
proxyLatencies,
145+
// Autoselect iff the user has not selected a proxy yet. We will save this to local storage.
146+
// If the user disagrees with the auto selected proxy, they can always change it.
147+
true,
148+
)
149+
150+
if(userProxy===undefined){
151+
setUserSavedProxy(preferred.proxy);
152+
}
153+
154+
setProxy(preferred);
143155
},[proxiesResp,proxyLatencies]);
144156

145157
// This useEffect ensures the proxy to be used is updated whenever the state changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp