1
- import { Storage } from "@plasmohq/storage" ;
2
1
import { useStorage } from "@plasmohq/storage/hook" ;
3
2
import classNames from "classnames" ;
4
3
import { useEffect , useMemo , useRef , useState } from "react" ;
5
4
import { useHotkeys } from "react-hotkeys-hook" ;
6
5
import Logo from "react:./logo-mark.svg" ;
7
- import { DEFAULT_GITPOD_ENDPOINT , EVENT_CURRENT_URL_CHANGED } from "~constants" ;
6
+ import { EVENT_CURRENT_URL_CHANGED } from "~constants" ;
8
7
import { FeatureFlags , useFlag } from "~hooks/use-configcat" ;
9
8
import { OnaLettermark } from "~icons/OnaLettermark" ;
10
9
import { STORAGE_KEY_ADDRESS , STORAGE_KEY_ALWAYS_OPTIONS , STORAGE_KEY_NEW_TAB } from "~storage" ;
10
+ import { isOnaEndpoint } from "~utils/parse-endpoint" ;
11
11
import type { SupportedApplication } from "./button-contributions" ;
12
12
import { CaretForProvider } from "./CaretForProvider" ;
13
13
@@ -38,18 +38,6 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
38
38
} ;
39
39
} , [ ] ) ;
40
40
41
- // if the user has no address configured, set it to the default endpoint
42
- useEffect ( ( ) => {
43
- ( async ( ) => {
44
- // we don't use the useStorage hook because it does not offer a way see if the value is set (it could just be loading), meaning we could end up setting the default endpoint even if it's already set
45
- const storage = new Storage ( ) ;
46
- const persistedAddress = await storage . get ( STORAGE_KEY_ADDRESS ) ;
47
- if ( ! persistedAddress ) {
48
- await storage . set ( STORAGE_KEY_ADDRESS , DEFAULT_GITPOD_ENDPOINT ) ;
49
- }
50
- } ) ( ) ;
51
- } , [ ] ) ;
52
-
53
41
const actions = useMemo ( ( ) => {
54
42
const parsedHref = ! urlTransformer ? currentHref : urlTransformer ( currentHref ) ;
55
43
return [
@@ -66,6 +54,10 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
66
54
const dropdownRef = useRef < HTMLDivElement | null > ( null ) ;
67
55
const firstActionRef = useRef < HTMLAnchorElement | null > ( null ) ;
68
56
57
+ const target = openInNewTab ? "_blank" : "_self" ;
58
+ const isOna = useMemo ( ( ) => address && isOnaEndpoint ( address ) , [ address ] ) ;
59
+ const effectiveDisableAutostart = isOna ? true : disableAutostart ;
60
+
69
61
const toggleDropdown = ( ) => {
70
62
setShowDropdown ( ! showDropdown ) ;
71
63
} ;
@@ -89,8 +81,6 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
89
81
}
90
82
} , [ showDropdown ] ) ;
91
83
92
- const target = openInNewTab ? "_blank" : "_self" ;
93
-
94
84
useHotkeys ( "alt+g" , ( ) => linkRef . current ?. click ( ) , [ linkRef . current ] ) ;
95
85
96
86
return (
@@ -101,7 +91,7 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
101
91
>
102
92
< div className = { classNames ( "button" ) } >
103
93
< a
104
- className = { classNames ( "button-part" , disableAutostart ? "action-no-options" : "action" ) }
94
+ className = { classNames ( "button-part" , effectiveDisableAutostart ? "action-no-options" : "action" ) }
105
95
href = { actions [ 0 ] . href }
106
96
target = { target }
107
97
rel = "noreferrer"
@@ -115,7 +105,7 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
115
105
{ actions [ 0 ] . label }
116
106
</ span >
117
107
</ a >
118
- { ! disableAutostart && (
108
+ { ! effectiveDisableAutostart && (
119
109
< button
120
110
className = { classNames ( "button-part" , "action-chevron" ) }
121
111
onClick = { ( e ) => {
0 commit comments