|
5 | 5 |
|
6 | 6 | import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; |
7 | 7 | import { MainContext, MainThreadKeytarShape, IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; |
8 | | - |
9 | | -interface IKeytarModule { |
10 | | - getPassword(service: string, account: string): Promise<string | null>; |
11 | | - setPassword(service: string, account: string, password: string): Promise<void>; |
12 | | - deletePassword(service: string, account: string): Promise<boolean>; |
13 | | - findPassword(service: string): Promise<string | null>; |
14 | | -} |
| 8 | +import { ICredentialsService } from 'vs/platform/credentials/common/credentials'; |
| 9 | +import { optional } from 'vs/platform/instantiation/common/instantiation'; |
15 | 10 |
|
16 | 11 | @extHostNamedCustomer(MainContext.MainThreadKeytar) |
17 | 12 | export class MainThreadKeytar implements MainThreadKeytarShape { |
18 | 13 |
|
19 | | - private _keytar: Promise<IKeytarModule | null>; |
| 14 | + private readonly _credentialsService?: ICredentialsService; |
20 | 15 |
|
21 | 16 | constructor( |
22 | | - extHostContext: IExtHostContext |
| 17 | + _extHostContext: IExtHostContext, |
| 18 | + @optional(ICredentialsService) credentialsService: ICredentialsService, |
23 | 19 | ) { |
24 | | - // tslint:disable-next-line:import-patterns |
25 | | - this._keytar = import('keytar') |
26 | | - .catch(e => null); |
| 20 | + this._credentialsService = credentialsService; |
27 | 21 | } |
28 | 22 |
|
29 | 23 | dispose(): void { |
30 | 24 | // |
31 | 25 | } |
32 | 26 |
|
33 | 27 | async $getPassword(service: string, account: string): Promise<string | null> { |
34 | | - const keytar = await this._keytar; |
35 | | - if (keytar) { |
36 | | - return keytar.getPassword(service, account); |
| 28 | + if (this._credentialsService) { |
| 29 | + return this._credentialsService.getPassword(service, account); |
37 | 30 | } |
38 | 31 | return null; |
39 | 32 | } |
40 | 33 |
|
41 | 34 | async $setPassword(service: string, account: string, password: string): Promise<void> { |
42 | | - const keytar = await this._keytar; |
43 | | - if (keytar) { |
44 | | - return keytar.setPassword(service, account, password); |
| 35 | + if (this._credentialsService) { |
| 36 | + return this._credentialsService.setPassword(service, account, password); |
45 | 37 | } |
46 | 38 | } |
47 | 39 |
|
48 | 40 | async $deletePassword(service: string, account: string): Promise<boolean> { |
49 | | - const keytar = await this._keytar; |
50 | | - if (keytar) { |
51 | | - return keytar.deletePassword(service, account); |
| 41 | + if (this._credentialsService) { |
| 42 | + return this._credentialsService.deletePassword(service, account); |
52 | 43 | } |
53 | 44 | return false; |
54 | 45 | } |
55 | 46 |
|
56 | 47 | async $findPassword(service: string): Promise<string | null> { |
57 | | - const keytar = await this._keytar; |
58 | | - if (keytar) { |
59 | | - return keytar.findPassword(service); |
| 48 | + if (this._credentialsService) { |
| 49 | + return this._credentialsService.findPassword(service); |
60 | 50 | } |
61 | 51 | return null; |
62 | 52 | } |
|
0 commit comments