1
1
import * as vscode from "vscode" ;
2
2
import { spawnSync } from "child_process" ;
3
3
import * as semver from "semver" ;
4
+ import * as path from "path" ;
4
5
5
6
import { ExtensionBroker } from "./extension-broker" ;
6
7
import { createBroker } from "../common/messaging/broker" ;
@@ -23,62 +24,68 @@ import { env } from "./core/env";
23
24
24
25
import { suggestGraphqlSyntaxExtension } from "./data-connect/graphql-syntax-highlighter" ;
25
26
import { registerSession } from "./session" ;
27
+ import { computed , ReadonlySignal , Signal , signal } from "@preact/signals-core" ;
28
+ import { checkLogin , User } from "./core/user" ;
29
+ import { requireAuthWrapper } from "./cli" ;
30
+ import { _readRC , getConfigPath } from "./core/config" ;
31
+ import { RC } from "../src/rc" ;
32
+ import { Result , ResultValue } from "./result" ;
33
+ import { Emulators , registerEmulators } from "./emulators" ;
26
34
27
35
// This method is called when your extension is activated
28
- export async function activate ( context : vscode . ExtensionContext ) {
29
- const analyticsLogger = new AnalyticsLogger ( context ) ;
30
-
31
- // Suggest installing the GraphQL syntax highlighter extension
32
- await suggestGraphqlSyntaxExtension ( ) ;
33
-
34
- await setupFirebasePath ( analyticsLogger ) ;
36
+ export async function activate ( ctx : vscode . ExtensionContext ) {
37
+ await setupFirebasePath ( ) ;
35
38
const settings = getSettings ( ) ;
39
+
36
40
logSetup ( ) ;
37
41
pluginLogger . debug ( "Activating Firebase extension." ) ;
38
42
39
- const broker = createBroker <
40
- ExtensionToWebviewParamsMap ,
41
- WebviewToExtensionParamsMap ,
42
- vscode . Webview
43
- > ( new ExtensionBroker ( ) ) ;
43
+ await checkCLIInstallation ( ) ;
44
44
45
- const authService = new AuthService ( broker ) ;
45
+ const user = await createUser ( ) ;
46
+ const rc = await createRC ( ctx ) ;
47
+ const project = await createProject ( rc ) ;
48
+ const emulators = signal < Emulators > ( { status : "stopped" } ) ;
46
49
47
- // show IDX data collection notice
48
- if ( settings . shouldShowIdxMetricNotice && env . value . isMonospace ) {
49
- // don't await/block on this
50
- vscode . window . showInformationMessage ( IDX_METRIC_NOTICE , "Ok" ) . then ( ( ) => {
51
- updateIdxSetting ( false ) ; // don't show message again
52
- } ) ;
53
- }
50
+ ctx . subscriptions . push (
51
+ registerEmulators ( emulators , rc ) ,
52
+ registerSession ( user , project ) ,
53
+ ) ;
54
+ }
54
55
55
- await checkCLIInstallation ( ) ;
56
+ async function createUser ( ) : Promise < Signal < User | undefined > > {
57
+ const user = await requireAuthWrapper ( ) ;
58
+ return signal ( user ?? undefined ) ;
59
+ }
56
60
57
- const [ emulatorsController , coreDisposable ] = await registerCore (
58
- broker ,
59
- context ,
60
- analyticsLogger ,
61
+ async function createRC (
62
+ ctx : vscode . ExtensionContext ,
63
+ ) : Promise < Signal < Result < RC | undefined > > > {
64
+ // const folderPath = path.dirname(getConfigPath() ?? "");
65
+ const rcUri = vscode . Uri . file (
66
+ path . join ( getConfigPath ( ) ?? "" , ".firebaserc" ) ,
61
67
) ;
68
+ console . log ( "WOWOWOWOWOW" ) ;
69
+ console . log ( rcUri . fsPath ) ;
70
+ const watcher = vscode . workspace . createFileSystemWatcher ( rcUri . fsPath ) ;
71
+ ctx . subscriptions . push ( watcher ) ;
62
72
63
- context . subscriptions . push (
64
- { dispose : analyticsLogger . endSession } ,
65
- { dispose : analyticsLogger . onDispose } ,
66
- coreDisposable ,
67
- registerWebview ( {
68
- name : "fdc_sidebar" ,
69
- broker,
70
- context,
71
- } ) ,
72
- authService ,
73
- registerSession ( ) ,
74
- registerFdc (
75
- context ,
76
- broker ,
77
- authService ,
78
- emulatorsController ,
79
- analyticsLogger ,
80
- ) ,
81
- ) ;
73
+ const rc = signal < Result < RC | undefined > > ( _readRC ( rcUri ) ) ;
74
+ watcher . onDidChange ( ( ) => ( rc . value = _readRC ( rcUri ) ) ) ;
75
+ watcher . onDidCreate ( ( ) => ( rc . value = _readRC ( rcUri ) ) ) ;
76
+ watcher . onDidDelete ( ( ) => ( rc . value = new ResultValue ( undefined ) ) ) ;
77
+
78
+ return rc ;
79
+ }
80
+
81
+ async function createProject (
82
+ rc : Signal < Result < RC | undefined > > ,
83
+ ) : Promise < ReadonlySignal < string | undefined > > {
84
+ return computed ( ( ) => {
85
+ if ( rc . value . tryReadValue ) {
86
+ return rc . value . tryReadValue . projects . default ;
87
+ }
88
+ } ) ;
82
89
}
83
90
84
91
async function checkCLIInstallation ( ) : Promise < void > {
0 commit comments