Skip to content

Commit b4aff7f

Browse files
committed
Set an explicit default Gitpod host for existing users
1 parent 100a2f3 commit b4aff7f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/button/button.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Props = {
1717
urlTransformer?: (url: string) => string;
1818
};
1919
export const GitpodButton = ({ application, additionalClassNames, urlTransformer }: Props) => {
20-
const [address] = useStorage<string>(STORAGE_KEY_ADDRESS, DEFAULT_GITPOD_ENDPOINT);
20+
const [address, setAddress] = useStorage<string>(STORAGE_KEY_ADDRESS);
2121
const [openInNewTab] = useStorage<boolean>(STORAGE_KEY_NEW_TAB, true);
2222
const [disableAutostart] = useStorage<boolean>(STORAGE_KEY_ALWAYS_OPTIONS, false);
2323
const [showDropdown, setShowDropdown] = useState(false);
@@ -37,6 +37,13 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
3737
};
3838
}, []);
3939

40+
// if the user has no address configured, set it to the default endpoint
41+
useEffect(() => {
42+
if (!address) {
43+
setAddress(DEFAULT_GITPOD_ENDPOINT);
44+
}
45+
}, [address]);
46+
4047
const actions = useMemo(() => {
4148
const parsedHref = !urlTransformer ? currentHref : urlTransformer(currentHref);
4249
return [

src/contents/gitpod-dashboard.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import type { PlasmoCSConfig } from "plasmo";
2-
31
import { Storage } from "@plasmohq/storage";
4-
5-
import { DEFAULT_GITPOD_ENDPOINT } from "~constants";
2+
import type { PlasmoCSConfig } from "plasmo";
63
import { STORAGE_AUTOMATICALLY_DETECT_GITPOD, STORAGE_KEY_ADDRESS } from "~storage";
74
import { parseEndpoint } from "~utils/parse-endpoint";
85

@@ -25,15 +22,10 @@ const automaticallyUpdateEndpoint = async () => {
2522
}
2623

2724
const currentHost = window.location.host;
28-
if (currentHost !== new URL(DEFAULT_GITPOD_ENDPOINT).host) {
29-
const currentlyStoredEndpoint = await storage.get<string>(STORAGE_KEY_ADDRESS);
30-
if (
31-
(currentlyStoredEndpoint && new URL(currentlyStoredEndpoint).host !== currentHost) ||
32-
!currentlyStoredEndpoint
33-
) {
34-
console.log(`Gitpod extension: switching default endpoint to ${currentHost}.`);
35-
await storage.set(STORAGE_KEY_ADDRESS, parseEndpoint(window.location.origin));
36-
}
25+
const currentlyStoredEndpoint = await storage.get<string>(STORAGE_KEY_ADDRESS);
26+
if (!currentlyStoredEndpoint || new URL(currentlyStoredEndpoint).host !== currentHost) {
27+
console.log(`Gitpod extension: switching default endpoint to ${currentHost}.`);
28+
await storage.set(STORAGE_KEY_ADDRESS, parseEndpoint(window.location.origin));
3729
}
3830
};
3931

0 commit comments

Comments
 (0)