@@ -2,70 +2,69 @@ import { commands, QuickPickItemKind, ThemeColor, window } from "vscode";
22import type { QuickPickItem } from "vscode" ;
33
44import { createPlugin } from "../plugins.ts" ;
5- import { checkIsProfileConfigured } from "../utils/configure-aws .ts" ;
5+ import { checkLocalstackInstalled } from "../utils/install .ts" ;
66
77export default createPlugin (
88 "status-bar" ,
9- ( { context, statusBarItem, localStackStatusTracker, setupStatusTracker } ) => {
9+ ( {
10+ context,
11+ statusBarItem,
12+ localStackStatusTracker,
13+ setupStatusTracker,
14+ outputChannel,
15+ } ) => {
1016 context . subscriptions . push (
1117 commands . registerCommand ( "localstack.showCommands" , async ( ) => {
12- const getCommands = async ( ) => {
18+ const shouldShowLocalStackStart = ( ) =>
19+ setupStatusTracker . statuses ( ) . isInstalled &&
20+ localStackStatusTracker . status ( ) === "stopped" ;
21+ const shouldShowLocalStackStop = ( ) =>
22+ setupStatusTracker . statuses ( ) . isInstalled &&
23+ localStackStatusTracker . status ( ) === "running" ;
24+ const shouldShowRunSetupWizard = ( ) =>
25+ setupStatusTracker . status ( ) === "setup_required" ;
26+
27+ const getCommands = ( ) => {
1328 const commands : ( QuickPickItem & { command : string } ) [ ] = [ ] ;
29+
1430 commands . push ( {
15- label : "Manage " ,
31+ label : "Configure " ,
1632 command : "" ,
1733 kind : QuickPickItemKind . Separator ,
1834 } ) ;
19- const setupStatus = setupStatusTracker . status ( ) ;
20-
21- if ( setupStatus === "ok" ) {
22- if ( localStackStatusTracker . status ( ) === "stopped" ) {
23- commands . push ( {
24- label : "Start LocalStack" ,
25- command : "localstack.start" ,
26- } ) ;
27- } else {
28- commands . push ( {
29- label : "Stop LocalStack" ,
30- command : "localstack.stop" ,
31- } ) ;
32- }
35+
36+ if ( shouldShowRunSetupWizard ( ) ) {
37+ commands . push ( {
38+ label : "Run LocalStack Setup Wizard" ,
39+ command : "localstack.setup" ,
40+ } ) ;
3341 }
3442
3543 commands . push ( {
36- label : "Configure " ,
44+ label : "Manage " ,
3745 command : "" ,
3846 kind : QuickPickItemKind . Separator ,
3947 } ) ;
4048
41- if ( setupStatus === "setup_required" ) {
49+ if ( shouldShowLocalStackStart ( ) ) {
4250 commands . push ( {
43- label : "Run LocalStack setup Wizard " ,
44- command : "localstack.setup " ,
51+ label : "Start LocalStack" ,
52+ command : "localstack.start " ,
4553 } ) ;
46-
47- // show start command if stopped or stop command when running, even if setup_required (in authentication, or profile)
48- if ( localStackStatusTracker . status ( ) === "stopped" ) {
49- commands . push ( {
50- label : "Start LocalStack" ,
51- command : "localstack.start" ,
52- } ) ;
53- } else if ( localStackStatusTracker . status ( ) === "running" ) {
54- commands . push ( {
55- label : "Stop LocalStack" ,
56- command : "localstack.stop" ,
57- } ) ;
58- }
5954 }
6055
61- const isProfileConfigured = await checkIsProfileConfigured ( ) ;
62- if ( ! isProfileConfigured ) {
56+ if ( shouldShowLocalStackStop ( ) ) {
6357 commands . push ( {
64- label : "Configure AWS Profiles " ,
65- command : "localstack.configureAwsProfiles " ,
58+ label : "Stop LocalStack " ,
59+ command : "localstack.stop " ,
6660 } ) ;
6761 }
6862
63+ commands . push ( {
64+ label : "View Logs" ,
65+ command : "localstack.viewLogs" ,
66+ } ) ;
67+
6968 return commands ;
7069 } ;
7170
@@ -74,38 +73,38 @@ export default createPlugin(
7473 } ) ;
7574
7675 if ( selected ) {
77- commands . executeCommand ( selected . command ) ;
76+ void commands . executeCommand ( selected . command ) ;
7877 }
7978 } ) ,
8079 ) ;
8180
8281 context . subscriptions . push (
8382 commands . registerCommand ( "localstack.refreshStatusBar" , ( ) => {
8483 const setupStatus = setupStatusTracker . status ( ) ;
85-
86- if ( setupStatus === "setup_required" ) {
87- statusBarItem . command = "localstack.showCommands" ;
88- statusBarItem . text = "$(error) LocalStack " ;
89- statusBarItem . backgroundColor = new ThemeColor (
90- "statusBarItem.errorBackground" ,
91- ) ;
92- } else {
93- statusBarItem . command = "localstack.showCommands" ;
94- statusBarItem . backgroundColor = undefined ;
95- const localStackStatus = localStackStatusTracker . status ( ) ;
96- if (
97- localStackStatus === "starting" ||
98- localStackStatus === "stopping "
99- ) {
100- statusBarItem . text = ` $(sync~spin) LocalStack ( ${ localStackStatus } )` ;
101- } else if (
102- localStackStatus === "running" ||
103- localStackStatus === "stopped"
104- ) {
105- statusBarItem . text = `$(localstack-logo) LocalStack ( ${ localStackStatus } )` ;
106- }
107- }
108-
84+ const localStackStatus = localStackStatusTracker . status ( ) ;
85+ const localStackInstalled = setupStatusTracker . statuses ( ) . isInstalled ;
86+
87+ statusBarItem . command = "localstack.showCommands " ;
88+ statusBarItem . backgroundColor =
89+ setupStatus === "setup_required"
90+ ? new ThemeColor ( "statusBarItem.errorBackground" )
91+ : undefined ;
92+
93+ const shouldSpin =
94+ localStackStatus === "starting" || localStackStatus === "stopping" ;
95+ const icon =
96+ setupStatus === "setup_required"
97+ ? "$(error) "
98+ : shouldSpin
99+ ? " $(sync~spin)"
100+ : "$(localstack-logo)" ;
101+
102+ const statusText = localStackInstalled
103+ ? ` ${ localStackStatus } `
104+ : "not installed" ;
105+ statusBarItem . text = ` ${ icon } LocalStack: ${ statusText } ` ;
106+
107+ statusBarItem . tooltip = "Show LocalStack commands" ;
109108 statusBarItem . show ( ) ;
110109 } ) ,
111110 ) ;
@@ -119,6 +118,7 @@ export default createPlugin(
119118 } ) ;
120119 }
121120 } ;
121+
122122 context . subscriptions . push ( {
123123 dispose ( ) {
124124 clearImmediate ( refreshStatusBarImmediateId ) ;
@@ -128,10 +128,12 @@ export default createPlugin(
128128 refreshStatusBarImmediate ( ) ;
129129
130130 localStackStatusTracker . onChange ( ( ) => {
131+ outputChannel . trace ( "[status-bar]: localStackStatusTracker changed" ) ;
131132 refreshStatusBarImmediate ( ) ;
132133 } ) ;
133134
134135 setupStatusTracker . onChange ( ( ) => {
136+ outputChannel . trace ( "[status-bar]: setupStatusTracker changed" ) ;
135137 refreshStatusBarImmediate ( ) ;
136138 } ) ;
137139 } ,
0 commit comments