microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/appCenterExtensionManager.ts
58lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import { Disposable, StatusBarAlignment, StatusBarItem, window } from "vscode"; |
| 5 | import Auth from "../appcenter/auth/auth"; |
| 6 | import { ACStrings } from "./appCenterStrings"; |
| 7 | import * as Q from "q"; |
| 8 | import { ACCommandNames, ACConstants } from "./appCenterConstants"; |
| 9 | import { Profile } from "./auth/profile/profile"; |
| 10 | import { ACUtils } from "./helpers/utils"; |
| 11 | import { VsCodeUtils } from "./helpers/vscodeUtils"; |
| 12 | |
| 13 | export class AppCenterExtensionManager implements Disposable { |
| 14 | private appCenterStatusBarItem: StatusBarItem; |
| 15 | private _projectRootPath: string; |
| 16 | |
| 17 | public constructor(projectRootPath: string) { |
| 18 | this._projectRootPath = projectRootPath; |
| 19 | } |
| 20 | |
| 21 | public get projectRootPath(): string { |
| 22 | return this._projectRootPath; |
| 23 | } |
| 24 | |
| 25 | public setup(): Q.Promise<void> { |
| 26 | return ACUtils.isCodePushProject(this._projectRootPath).then((isCodePush: boolean) => { |
| 27 | if (!isCodePush) { |
| 28 | return Q.resolve(void 0); |
| 29 | } else { |
| 30 | this.appCenterStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 12); |
| 31 | return Auth.getProfile(this._projectRootPath).then((profile: Profile | null) => { |
| 32 | return this.setupAppCenterStatusBar(profile); |
| 33 | }); |
| 34 | } |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | public dispose() { |
| 39 | if (this.appCenterStatusBarItem) { |
| 40 | this.appCenterStatusBarItem.dispose(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public setupAppCenterStatusBar(profile: Profile | null): Q.Promise<void> { |
| 45 | if (profile && profile.userName) { |
| 46 | return VsCodeUtils.setStatusBar(this.appCenterStatusBarItem, |
| 47 | `$(icon octicon-person) ${profile.userName}`, |
| 48 | ACStrings.YouAreLoggedInMsg(profile.userName), |
| 49 | `${ACConstants.ExtensionPrefixName}.${ACCommandNames.ShowMenu}` |
| 50 | ); |
| 51 | } |
| 52 | return VsCodeUtils.setStatusBar(this.appCenterStatusBarItem, |
| 53 | `$(icon octicon-sign-in) ${ACStrings.LoginToAppCenterButton}`, |
| 54 | ACStrings.UserMustSignIn, |
| 55 | `${ACConstants.ExtensionPrefixName}.${ACCommandNames.Login}` |
| 56 | ); |
| 57 | } |
| 58 | } |