From b0a600352476c76bd6085fc6de6430a90cefd75c Mon Sep 17 00:00:00 2001 From: Giovanni D'Andrea Date: Fri, 12 Apr 2024 18:56:34 +0200 Subject: [PATCH] fix: Configured the Auth settings to true when logged correctly - updated the configuration directly into the handler - created generic function to wrap the configuration updates --- codeishot_extension/.gitignore | 5 ++++- codeishot_extension/package-lock.json | 4 ++-- codeishot_extension/package.json | 29 ++++++++++++++------------- codeishot_extension/src/extension.ts | 2 +- codeishot_extension/src/handlers.ts | 12 +++++++++-- codeishot_extension/src/utils.ts | 15 +++++++++++++- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/codeishot_extension/.gitignore b/codeishot_extension/.gitignore index 0a7b3d9..5b2f5a8 100644 --- a/codeishot_extension/.gitignore +++ b/codeishot_extension/.gitignore @@ -5,5 +5,8 @@ out/ ./out out +## Bundlers +*vsix + ## Testing -.vscode-test \ No newline at end of file +.vscode-test diff --git a/codeishot_extension/package-lock.json b/codeishot_extension/package-lock.json index 2e8d42e..1b301cd 100644 --- a/codeishot_extension/package-lock.json +++ b/codeishot_extension/package-lock.json @@ -1,12 +1,12 @@ { "name": "codeshot", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "codeshot", - "version": "0.4.0", + "version": "0.5.0", "dependencies": { "axios": "^1.5.1" }, diff --git a/codeishot_extension/package.json b/codeishot_extension/package.json index 48b2e41..46c8e20 100644 --- a/codeishot_extension/package.json +++ b/codeishot_extension/package.json @@ -4,7 +4,7 @@ "publisher": "codeishot", "description": "Share you code in one click", "icon": "./assets/logo.png", - "version": "0.4.0", + "version": "0.5.0", "repository": { "type": "git", "url": "https://github.com/Exifly/codeishot_vscode_ext" @@ -15,7 +15,9 @@ "categories": [ "Other" ], - "activationEvents": ["onUri"], + "activationEvents": [ + "onUri" + ], "main": "./out/extension.js", "contributes": { "commands": [ @@ -27,7 +29,6 @@ "command": "extension.postSnippet", "title": "Share on Codeishot ✨" } - ], "menus": { "editor/context": [ @@ -54,18 +55,18 @@ "type": "object", "title": "Codeishot", "properties": { - "jwt": { - "type": "string", - "default": "", - "description": "Token to login into codeishot." - }, - "Authentication": { - "type": "boolean", - "default": false, - "description": "Choose whether to authenticate the snippets or not." - } + "jwt": { + "type": "string", + "default": "", + "description": "Token to login into codeishot." + }, + "Authentication": { + "type": "boolean", + "default": false, + "description": "Choose whether to authenticate the snippets or not." + } } - } + } }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/codeishot_extension/src/extension.ts b/codeishot_extension/src/extension.ts index 8f5015f..a1beabd 100644 --- a/codeishot_extension/src/extension.ts +++ b/codeishot_extension/src/extension.ts @@ -1,6 +1,6 @@ /** * MIT License - * Copyright (c) [2024] [Codeishot] + * Copyright (c) 2024 Codeishot * Giovanni D'Andrea => @gdjohn4s * Flavio Adamo => @FlavioAdamo * Gianluca Andretta => @gnlca diff --git a/codeishot_extension/src/handlers.ts b/codeishot_extension/src/handlers.ts index e1c21fa..8cfa8c1 100644 --- a/codeishot_extension/src/handlers.ts +++ b/codeishot_extension/src/handlers.ts @@ -2,8 +2,9 @@ * Defines various handlers for this vscode extension. */ -import { window, Uri, type Disposable } from "vscode"; -import { updateUserConfiguration } from "./utils"; +import { updateUserConfiguration, updateConfiguration } from "./utils"; +import { window, Uri, type Disposable, ConfigurationTarget } from "vscode"; +import { isAuthApproved } from "./preferences"; export const loginUriHandler: Disposable = window.registerUriHandler({ handleUri(uri: Uri) { @@ -12,6 +13,13 @@ export const loginUriHandler: Disposable = window.registerUriHandler({ if (jwtParam) { window.showInformationMessage("Logged Successfully! ✨"); updateUserConfiguration(jwtParam); + + if (!isAuthApproved()) + updateConfiguration( + "Authentication", + true, + ConfigurationTarget.Global + ); } } }, diff --git a/codeishot_extension/src/utils.ts b/codeishot_extension/src/utils.ts index ae729b8..419dc2d 100644 --- a/codeishot_extension/src/utils.ts +++ b/codeishot_extension/src/utils.ts @@ -19,6 +19,14 @@ function useConfig(): WorkspaceConfiguration { return config; } +function updateConfiguration( + section: string, + value: string | number | boolean, + target: ConfigurationTarget +) { + workspace.getConfiguration().update(section, value, target); +} + function updateUserConfiguration(token: string) { workspace.getConfiguration().update("jwt", token, ConfigurationTarget.Global); } @@ -39,4 +47,9 @@ function getTokenFromConfiguration(): string { return token; } -export { useConfig, updateUserConfiguration, getTokenFromConfiguration }; +export { + useConfig, + updateUserConfiguration, + updateConfiguration, + getTokenFromConfiguration, +};