diff --git a/src/commons.ts b/src/commons.ts index 4aef1182..d8dc5645 100644 --- a/src/commons.ts +++ b/src/commons.ts @@ -113,14 +113,6 @@ export default class Commons { const extSettings = this.GetSettings(); const cusSettings = await this.GetCustomSettings(); - if ( - cusSettings.downloadPublicGist - ? !extSettings.gist - : !cusSettings.token || !extSettings.gist - ) { - this.webviewService.OpenLandingPage(); - } - settings.customConfig = cusSettings; settings.extConfig = extSettings; return settings; diff --git a/src/service/github.oauth.service.ts b/src/service/github.oauth.service.ts index 8fee007d..4123f545 100644 --- a/src/service/github.oauth.service.ts +++ b/src/service/github.oauth.service.ts @@ -14,7 +14,7 @@ export class GitHubOAuthService { this.app.use(express.json(), express.urlencoded({ extended: false })); } - public async StartProcess() { + public async StartProcess(cmd?: string) { const customSettings = await state.commons.GetCustomSettings(); const host = customSettings.githubEnterpriseUrl ? new URL(customSettings.githubEnterpriseUrl) @@ -60,9 +60,7 @@ export class GitHubOAuthService { const gists: any[] = await this.getGists(token, user, host); - if (gists.length) { - state.commons.webviewService.OpenGistSelectionpage(gists); - } + state.commons.webviewService.OpenGistSelectionpage(gists, cmd); } catch (err) { const error = new Error(err); Commons.LogException(error, state.commons.ERROR_MESSAGE, true); diff --git a/src/service/webview.service.ts b/src/service/webview.service.ts index e2062f8e..20af74a4 100644 --- a/src/service/webview.service.ts +++ b/src/service/webview.service.ts @@ -157,6 +157,10 @@ export class WebviewService { { find: "@RELEASE_NOTES", replace: "releaseNotes" + }, + { + find: "@CHECKED", + replace: "checked" } ] }, @@ -189,6 +193,10 @@ export class WebviewService { { find: "@GISTS", replace: "gists" + }, + { + find: "@SKIP", + replace: "skip" } ] } @@ -306,28 +314,24 @@ export class WebviewService { } public IsLandingPageEnabled(): boolean { - const dontShowThisAgain = state.context.globalState.get( + return !state.context.globalState.get( "landingPage.dontShowThisAgain" ); - if (dontShowThisAgain) { - return false; - } else { - return true; - } } - public OpenLandingPage() { + public OpenLandingPage(cmd?: string) { const webview = this.webviews[0]; const releaseNotes = require("../../release-notes.json"); const content: string = this.GenerateContent({ content: webview.htmlContent, items: webview.replaceables, - releaseNotes + releaseNotes, + checked: this.IsLandingPageEnabled() }); if (webview.webview) { webview.webview.webview.html = content; webview.webview.reveal(); - return webview; + return webview.webview; } const landingPanel = vscode.window.createWebviewPanel( "landingPage", @@ -341,7 +345,7 @@ export class WebviewService { landingPanel.webview.onDidReceiveMessage(async message => { switch (message.command) { case "loginWithGitHub": - new GitHubOAuthService(54321).StartProcess(); + new GitHubOAuthService(54321).StartProcess(cmd); const customSettings = await state.commons.GetCustomSettings(); const host = customSettings.githubEnterpriseUrl ? new URL(customSettings.githubEnterpriseUrl) @@ -398,17 +402,21 @@ export class WebviewService { return landingPanel; } - public OpenGistSelectionpage(gists: any) { + public OpenGistSelectionpage(gists: any, cmd?: string) { const webview = this.webviews[2]; const content: string = this.GenerateContent({ content: webview.htmlContent, items: webview.replaceables, - gists + gists, + skip: + cmd !== "extension.downloadSettings" + ? `Skip (new one will be created upon first upload)` + : "" }); if (webview.webview) { webview.webview.webview.html = content; webview.webview.reveal(); - return webview; + return webview.webview; } const gistSelectionPanel = vscode.window.createWebviewPanel( "selectGist", @@ -428,6 +436,9 @@ export class WebviewService { } else { gistSelectionPanel.dispose(); } + if (cmd) { + vscode.commands.executeCommand(cmd); + } }); webview.webview = gistSelectionPanel; gistSelectionPanel.onDidDispose(() => (webview.webview = null)); diff --git a/src/sync.ts b/src/sync.ts index 780f62e4..aa1e3eed 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -69,7 +69,13 @@ export class Sync { // @ts-ignore const args = arguments; let github: GitHubService = null; - let localConfig = new LocalConfig(); + const localConfig = await state.commons.InitalizeSettings(); + + if (!localConfig.customConfig.token) { + state.commons.webviewService.OpenLandingPage("extension.updateSettings"); + return; + } + const allSettingFiles: File[] = []; let uploadedExtensions: ExtensionInformation[] = []; const ignoredExtensions: ExtensionInformation[] = []; @@ -77,7 +83,6 @@ export class Sync { await state.commons.HandleStopWatching(); try { - localConfig = await state.commons.InitalizeSettings(); localConfig.publicGist = false; if (args.length > 0) { if (args[0] === "publicGIST") { @@ -434,11 +439,22 @@ export class Sync { * Download setting from github gist */ public async download(): Promise { - let localSettings: LocalConfig = new LocalConfig(); + const localSettings: LocalConfig = await state.commons.InitalizeSettings(); + + if ( + localSettings.customConfig.downloadPublicGist + ? !localSettings.extConfig.gist + : !localSettings.customConfig.token || !localSettings.extConfig.gist + ) { + state.commons.webviewService.OpenLandingPage( + "extension.downloadSettings" + ); + return; + } + await state.commons.HandleStopWatching(); try { - localSettings = await state.commons.InitalizeSettings(); await StartDownload(localSettings.extConfig, localSettings.customConfig); } catch (err) { Commons.LogException(err, state.commons.ERROR_MESSAGE, true); diff --git a/ui/gist-selection/gist-selection.html b/ui/gist-selection/gist-selection.html index 5c3ccc1e..3106ae0b 100644 --- a/ui/gist-selection/gist-selection.html +++ b/ui/gist-selection/gist-selection.html @@ -30,13 +30,7 @@

Select Your Existing Gist

- Skip (new one will be created automatically) +