From 79ef07d5d4faff093b43bdbc327d86f552674b75 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 30 Jan 2018 02:30:41 -0500 Subject: [PATCH] Shows welcome page on first start Fixes settings migration --- src/commands/common.ts | 2 ++ src/extension.ts | 46 +++++++++++++++++++++++++++++----------------- src/messages.ts | 9 --------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/commands/common.ts b/src/commands/common.ts index c931d51..52ad101 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -45,6 +45,8 @@ export enum Commands { ShowQuickCurrentBranchHistory = 'gitlens.showQuickRepoHistory', ShowQuickRepoStatus = 'gitlens.showQuickRepoStatus', ShowQuickStashList = 'gitlens.showQuickStashList', + ShowSettingsPage = 'gitlens.showSettingsPage', + ShowWelcomePage = 'gitlens.showWelcomePage', StashApply = 'gitlens.stashApply', StashDelete = 'gitlens.stashDelete', StashSave = 'gitlens.stashSave', diff --git a/src/extension.ts b/src/extension.ts index cc470e2..f24cdd4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,9 +1,9 @@ 'use strict'; import { Objects, Versions } from './system'; -import { ConfigurationTarget, ExtensionContext, extensions, window, workspace } from 'vscode'; +import { commands, ConfigurationTarget, ExtensionContext, extensions, window, workspace } from 'vscode'; import { CodeLensLanguageScope, CodeLensScopes, configuration, Configuration, IConfig } from './configuration'; import { CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants'; -import { configureCommands } from './commands'; +import { Commands, configureCommands } from './commands'; import { Container } from './container'; import { GitService } from './gitService'; import { Logger } from './logger'; @@ -46,6 +46,10 @@ export async function activate(context: ExtensionContext) { return; } + Container.initialize(context, cfg); + + configureCommands(); + const gitVersion = GitService.getGitVersion(); // Telemetry.configure(ApplicationInsightsKey); @@ -55,15 +59,11 @@ export async function activate(context: ExtensionContext) { // telemetryContext['git.version'] = gitVersion; // Telemetry.setContext(telemetryContext); - notifyOnUnsupportedGitVersion(context, gitVersion); - notifyOnNewGitLensVersion(context, gitlensVersion, previousVersion); + notifyOnUnsupportedGitVersion(gitVersion); + notifyOnNewGitLensVersion(gitlensVersion, previousVersion); context.globalState.update(GlobalState.GitLensVersion, gitlensVersion); - Container.initialize(context, cfg); - - configureCommands(); - // Constantly over my data cap so stop collecting initialized event // Telemetry.trackEvent('initialized', Objects.flatten(cfg, 'config', true)); @@ -120,7 +120,12 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin await configuration.migrate('gitExplorer.gravatarsDefault', configuration.name('defaultGravatarsStyle').value); } - if (Versions.compare(previous, Versions.from(8, 0, 0, 'beta')) !== 1) { + if (Versions.compare(previous, Versions.from(7, 5, 9)) !== 1) { + const section = configuration.name('advanced')('messages').value; + const messages = configuration.get<{ [key: string]: boolean }>(section); + messages[SuppressedMessages.WelcomeNotice] = false; + await configuration.update(section, messages, ConfigurationTarget.Global); + await configuration.migrate('annotations.file.gutter.gravatars', configuration.name('blame')('avatars').value); await configuration.migrate('annotations.file.gutter.compact', configuration.name('blame')('compact').value); await configuration.migrate('annotations.file.gutter.dateFormat', configuration.name('blame')('dateFormat').value); @@ -174,19 +179,26 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin } } -async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string, previousVersion: string | undefined) { - if (configuration.get(configuration.name('advanced')('messages')(SuppressedMessages.UpdateNotice).value)) return; - +async function notifyOnNewGitLensVersion(version: string, previousVersion: string | undefined) { if (previousVersion === undefined) { Logger.log(`GitLens first-time install`); - await Messages.showWelcomeMessage(); + } + else if (previousVersion !== version) { + Logger.log(`GitLens upgraded from v${previousVersion} to v${version}`); + } + + if (!Container.config.advanced.messages.suppressWelcomeNotice) { + const section = configuration.name('advanced')('messages').value; + const messages = configuration.get<{ [key: string]: boolean }>(section); + messages[SuppressedMessages.WelcomeNotice] = true; + await configuration.update(section, messages, ConfigurationTarget.Global); + + await commands.executeCommand(Commands.ShowWelcomePage); return; } - if (previousVersion !== version) { - Logger.log(`GitLens upgraded from v${previousVersion} to v${version}`); - } + if (previousVersion === undefined || Container.config.advanced.messages.suppressUpdateNotice) return; const [major, minor] = version.split('.'); const [prevMajor, prevMinor] = previousVersion.split('.'); @@ -197,7 +209,7 @@ async function notifyOnNewGitLensVersion(context: ExtensionContext, version: str await Messages.showUpdateMessage(version); } -async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version: string) { +async function notifyOnUnsupportedGitVersion(version: string) { if (GitService.validateGitVersion(2, 2)) return; // If git is less than v2.2.0 diff --git a/src/messages.ts b/src/messages.ts index a9fa655..2419b8d 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -57,15 +57,6 @@ export class Messages { return result; } - static async showWelcomeMessage(): Promise { - const viewDocs = 'View Docs'; - const result = await Messages.showMessage('info', `Thank you for choosing GitLens! GitLens is powerful, feature rich, and highly configurable, so please be sure to view the docs and tailor it to suit your needs`, SuppressedMessages.WelcomeNotice, null, viewDocs); - if (result === viewDocs) { - commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://marketplace.visualstudio.com/items/eamodio.gitlens')); - } - return result; - } - private static async showMessage(type: 'info' | 'warn' | 'error', message: string, suppressionKey: SuppressedMessages, dontShowAgain: string | null = 'Don\'t Show Again', ...actions: any[]): Promise { Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`);