@@ -2,23 +2,25 @@ import { commands, QuickPickItemKind, ThemeColor, window } from "vscode";
22import type { QuickPickItem } from "vscode" ;
33
44import { createPlugin } from "../plugins.ts" ;
5+ import { immediateOnce } from "../utils/immediate-once.ts" ;
56
67export default createPlugin (
78 "status-bar" ,
89 ( {
910 context,
1011 statusBarItem,
12+ cliStatusTracker,
1113 localStackStatusTracker,
1214 setupStatusTracker,
1315 outputChannel,
1416 } ) => {
1517 context . subscriptions . push (
1618 commands . registerCommand ( "localstack.showCommands" , async ( ) => {
1719 const shouldShowLocalStackStart = ( ) =>
18- setupStatusTracker . statuses ( ) . isInstalled &&
20+ cliStatusTracker . status ( ) === "ok" &&
1921 localStackStatusTracker . status ( ) === "stopped" ;
2022 const shouldShowLocalStackStop = ( ) =>
21- setupStatusTracker . statuses ( ) . isInstalled &&
23+ cliStatusTracker . status ( ) === "ok" &&
2224 localStackStatusTracker . status ( ) === "running" ;
2325 const shouldShowRunSetupWizard = ( ) =>
2426 setupStatusTracker . status ( ) === "setup_required" ;
@@ -77,63 +79,84 @@ export default createPlugin(
7779 } ) ,
7880 ) ;
7981
80- context . subscriptions . push (
81- commands . registerCommand ( "localstack.refreshStatusBar" , ( ) => {
82- const setupStatus = setupStatusTracker . status ( ) ;
83- const localStackStatus = localStackStatusTracker . status ( ) ;
84- const localStackInstalled = setupStatusTracker . statuses ( ) . isInstalled ;
85-
86- statusBarItem . command = "localstack.showCommands" ;
87- statusBarItem . backgroundColor =
88- setupStatus === "setup_required"
89- ? new ThemeColor ( "statusBarItem.errorBackground" )
90- : undefined ;
91-
92- const shouldSpin =
93- localStackStatus === "starting" || localStackStatus === "stopping" ;
94- const icon =
95- setupStatus === "setup_required"
96- ? "$(error)"
97- : shouldSpin
98- ? "$(sync~spin)"
99- : "$(localstack-logo)" ;
100-
101- const statusText = localStackInstalled
102- ? `${ localStackStatus } `
103- : "not installed" ;
104- statusBarItem . text = `${ icon } LocalStack: ${ statusText } ` ;
105-
106- statusBarItem . tooltip = "Show LocalStack commands" ;
107- statusBarItem . show ( ) ;
108- } ) ,
109- ) ;
110-
111- let refreshStatusBarImmediateId : NodeJS . Immediate | undefined ;
112- const refreshStatusBarImmediate = ( ) => {
113- if ( ! refreshStatusBarImmediateId ) {
114- refreshStatusBarImmediateId = setImmediate ( ( ) => {
115- void commands . executeCommand ( "localstack.refreshStatusBar" ) ;
116- refreshStatusBarImmediateId = undefined ;
117- } ) ;
82+ // context.subscriptions.push(
83+ // commands.registerCommand("localstack.refreshStatusBar", () => {
84+ // const setupStatus = setupStatusTracker.status();
85+ // const localStackStatus = localStackStatusTracker.status();
86+ // const localStackInstalled = cliStatusTracker.status() === "ok"
87+
88+ // statusBarItem.command = "localstack.showCommands";
89+ // statusBarItem.backgroundColor =
90+ // setupStatus === "setup_required"
91+ // ? new ThemeColor("statusBarItem.errorBackground")
92+ // : undefined;
93+
94+ // const shouldSpin =
95+ // localStackStatus === "starting" || localStackStatus === "stopping";
96+ // const icon =
97+ // setupStatus === "setup_required"
98+ // ? "$(error)"
99+ // : shouldSpin
100+ // ? "$(sync~spin)"
101+ // : "$(localstack-logo)";
102+
103+ // const statusText = localStackInstalled
104+ // ? `${localStackStatus}`
105+ // : "not installed";
106+ // statusBarItem.text = `${icon} LocalStack: ${statusText}`;
107+
108+ // statusBarItem.tooltip = "Show LocalStack commands";
109+ // statusBarItem.show();
110+ // }),
111+ // );
112+
113+ const refreshStatusBar = immediateOnce ( ( ) => {
114+ // await commands.executeCommand("localstack.refreshStatusBar");
115+ const setupStatus = setupStatusTracker . status ( ) ;
116+ const localStackStatus = localStackStatusTracker . status ( ) ;
117+ const cliStatus = cliStatusTracker . status ( ) ;
118+
119+ if (
120+ setupStatus === undefined ||
121+ localStackStatus === undefined ||
122+ cliStatus === undefined
123+ ) {
124+ return ;
118125 }
119- } ;
120126
121- context . subscriptions . push ( {
122- dispose ( ) {
123- clearImmediate ( refreshStatusBarImmediateId ) ;
124- } ,
127+ statusBarItem . command = "localstack.showCommands" ;
128+ statusBarItem . backgroundColor =
129+ setupStatus === "setup_required"
130+ ? new ThemeColor ( "statusBarItem.errorBackground" )
131+ : undefined ;
132+
133+ const shouldSpin =
134+ localStackStatus === "starting" || localStackStatus === "stopping" ;
135+ const icon =
136+ setupStatus === "setup_required"
137+ ? "$(error)"
138+ : shouldSpin
139+ ? "$(sync~spin)"
140+ : "$(localstack-logo)" ;
141+
142+ const statusText =
143+ cliStatus === "ok" ? `${ localStackStatus } ` : "not installed" ;
144+ statusBarItem . text = `${ icon } LocalStack: ${ statusText } ` ;
145+
146+ statusBarItem . tooltip = "Show LocalStack commands" ;
147+ // statusBarItem.show();
125148 } ) ;
126149
127- refreshStatusBarImmediate ( ) ;
150+ // refreshStatusBar ();
128151
129152 localStackStatusTracker . onChange ( ( ) => {
130153 outputChannel . trace ( "[status-bar]: localStackStatusTracker changed" ) ;
131- refreshStatusBarImmediate ( ) ;
154+ refreshStatusBar ( ) ;
132155 } ) ;
133156
134157 setupStatusTracker . onChange ( ( ) => {
135158 outputChannel . trace ( "[status-bar]: setupStatusTracker changed" ) ;
136- refreshStatusBarImmediate ( ) ;
159+ refreshStatusBar ( ) ;
137160 } ) ;
138161 } ,
139162) ;
0 commit comments