Skip to content

Commit b6e30b5

Browse files
committed
Cleanup
Signed-off-by: Seb Julliand <[email protected]>
1 parent b03fba4 commit b6e30b5

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/api/Storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,20 @@ export class ConnectionStorage extends Storage {
198198
await this.set(RECENTLY_OPENED_FILES_KEY, undefined);
199199
}
200200

201-
async authorizeExtension(extension: string) {
201+
async addAuthorizedExtension(extension: string) {
202202
const extensions = this.get<string[]>(AUTHORISED_EXTENSIONS_KEY) || [];
203203
if (!extensions.includes(extension)) {
204204
extensions.push(extension);
205205
await this.set(AUTHORISED_EXTENSIONS_KEY, extensions);
206206
}
207207
}
208208

209-
extensionIsAuthorised(extension: string) {
209+
isExtensionAuthorised(extension: string) {
210210
const extensions = this.get<string[]>(AUTHORISED_EXTENSIONS_KEY) || [];
211211
return extensions.includes(extension);
212212
}
213213

214-
authorizedExtensions(): string[] {
214+
getAuthorizedExtensions(): string[] {
215215
return this.get<string[]>(AUTHORISED_EXTENSIONS_KEY) || [];
216216
}
217217

src/instantiate.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Instance from "./api/Instance";
88
import { Search } from "./api/Search";
99
import { Terminal } from './api/Terminal';
1010
import { refreshDiagnosticsFromServer } from './api/errors/diagnostics';
11+
import { setupGitEventHandler } from './api/local/git';
1112
import { QSysFS, getUriFromPath, parseFSOptions } from "./filesystems/qsys/QSysFs";
1213
import { init as clApiInit } from "./languages/clle/clApi";
1314
import * as clRunner from "./languages/clle/clRunner";
@@ -17,11 +18,10 @@ import { Action, BrowserItem, DeploymentMethod, MemberItem, OpenEditableOptions,
1718
import { SearchView } from "./views/searchView";
1819
import { ActionsUI } from './webviews/actions';
1920
import { VariablesUI } from "./webviews/variables";
20-
import { setupGitEventHandler } from './api/local/git';
2121

2222
export let instance: Instance;
2323

24-
let passwordAttempts: {[ext: string]: number} = {}
24+
const passwordAttempts: {[extensionId: string]: number} = {}
2525

2626
const CLEAR_RECENT = `$(trash) Clear recently opened`;
2727
const CLEAR_CACHED = `$(trash) Clear cached`;
@@ -643,42 +643,42 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
643643
if (storedPassword) {
644644

645645
const storage = instance.getStorage()!;
646-
let isAuthed = storage.extensionIsAuthorised(extensionId);
646+
let isAuthed = storage.isExtensionAuthorised(extensionId);
647647

648648
if (!isAuthed) {
649649
const displayName = extension.packageJSON.displayName || extensionId;
650650
const detail = `The ${displayName} extension is requesting access to your password for this connection. ${reason ? `\n\nReason: ${reason}` : `The extension did not provide a reason for password access.`}`;
651651
let done = false;
652-
let asModal = true;
652+
let modal = true;
653653

654654
while (!done) {
655-
let options: string[] = [`Allow`];
655+
const options: string[] = [`Allow`];
656656

657-
if (asModal) {
657+
if (modal) {
658658
options.push(`View on Marketplace`);
659659
} else {
660660
options.push(`Deny`);
661661
}
662662

663663
const result = await vscode.window.showWarningMessage(
664-
asModal ? `Password Request` : detail,
664+
modal ? `Password Request` : detail,
665665
{
666-
modal: asModal,
666+
modal,
667667
detail,
668668
},
669669
...options
670670
);
671671

672672
switch (result) {
673673
case `Allow`:
674-
await storage.authorizeExtension(extensionId);
674+
await storage.addAuthorizedExtension(extensionId);
675675
isAuthed = true;
676676
done = true;
677677
break;
678678

679679
case `View on Marketplace`:
680680
vscode.commands.executeCommand('extension.open', extensionId);
681-
asModal = false;
681+
modal = false;
682682
break;
683683

684684
default:
@@ -699,8 +699,6 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
699699
throw new Error(`Not connected to an IBM i.`);
700700
}
701701
}
702-
703-
return undefined;
704702
}
705703
}),
706704

src/webviews/settings/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import vscode from "vscode";
22
import { ConnectionConfiguration, GlobalConfiguration } from "../../api/Configuration";
3-
import { GlobalStorage } from '../../api/Storage';
43
import { ComplexTab, CustomUI, Section } from "../../api/CustomUI";
4+
import { GlobalStorage } from '../../api/Storage';
55
import { Tools } from "../../api/Tools";
66
import { isManaged } from "../../api/debug";
77
import * as certificates from "../../api/debug/certificates";
@@ -32,7 +32,7 @@ export class SettingsUI {
3232
vscode.commands.registerCommand(`code-for-ibmi.showAdditionalSettings`, async (server?: Server, tab?: string) => {
3333
const connectionSettings = GlobalConfiguration.get<ConnectionConfiguration.Parameters[]>(`connectionSettings`);
3434
const connection = instance.getConnection();
35-
const passwordAuthorisedExtensions: string[] = instance.getStorage()?.authorizedExtensions() || [];
35+
const passwordAuthorisedExtensions: string[] = instance.getStorage()?.getAuthorizedExtensions() || [];
3636

3737
let config: ConnectionConfiguration.Parameters;
3838

@@ -206,7 +206,7 @@ export class SettingsUI {
206206

207207
const ui = new CustomUI();
208208

209-
if (passwordAuthorisedExtensions.length > 0) {
209+
if (passwordAuthorisedExtensions.length) {
210210
const passwordAuthTab = new Section();
211211

212212
passwordAuthTab
@@ -236,17 +236,18 @@ export class SettingsUI {
236236
case `import`:
237237
vscode.commands.executeCommand(`code-for-ibmi.debug.setup.local`);
238238
break;
239-
239+
240240
case `clearAllowedExts`:
241-
if (instance.getStorage()) {
242-
instance.getStorage()?.removeAuthorizedExtension(instance.getStorage()?.authorizedExtensions()!);
241+
const storage = instance.getStorage();
242+
if (storage) {
243+
storage.removeAuthorizedExtension(storage.getAuthorizedExtensions());
243244
}
244245
break;
245246

246247
default:
247248
const data = page.data;
248249
for (const key in data) {
249-
250+
250251
//In case we need to play with the data
251252
switch (key) {
252253
case `sourceASP`:
@@ -266,25 +267,25 @@ export class SettingsUI {
266267
.filter(Tools.distinct);
267268
break;
268269
}
269-
270+
270271
//Refresh connection browser if not connected
271272
if (!instance.getConnection()) {
272273
vscode.commands.executeCommand(`code-for-ibmi.refreshConnections`);
273274
}
274275
}
275-
276+
276277
if (restartFields.some(item => data[item] && data[item] !== config[item])) {
277278
restart = true;
278279
}
279-
280+
280281
const reloadBrowsers = config.protectedPaths.join(",") !== data.protectedPaths.join(",");
281282
const removeCachedSettings = (!data.quickConnect && data.quickConnect !== config.quickConnect);
282-
283+
283284
Object.assign(config, data);
284285
await instance.setConfig(config);
285286
if (removeCachedSettings)
286287
GlobalStorage.get().deleteServerSettingsCache(config.name);
287-
288+
288289
if (connection) {
289290
if (restart) {
290291
vscode.window.showInformationMessage(`Some settings require a restart to take effect. Reload workspace now?`, `Reload`, `No`)

0 commit comments

Comments
 (0)