This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: oauth support * fix: token fetch Co-authored-by: Rahul Kadyan <hey@znck.me>
- Loading branch information
Showing
22 changed files
with
389 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,35 @@ | ||
import { GrammarlyLanguageClient } from 'unofficial-grammarly-language-client' | ||
import { ExtensionContext, Uri, workspace } from 'vscode' | ||
import { Disposable, ExtensionContext, Uri, workspace } from 'vscode' | ||
import { AuthenticationService } from '../services/AuthenticationService' | ||
import { Registerable } from '../interfaces' | ||
import { getKeyTar } from '../keytar' | ||
|
||
export class GrammarlyClient extends GrammarlyLanguageClient implements Registerable { | ||
constructor(context: ExtensionContext) { | ||
constructor (context: ExtensionContext, private readonly auth: AuthenticationService) { | ||
|
||
super(context.asAbsolutePath('dist/server/index.js'), { | ||
info: { | ||
name: 'Grammarly' | ||
}, | ||
getCredentials: async () => { | ||
if (process.env.EXTENSION_TEST_MODE) return null | ||
|
||
const credentials = (await getKeyTar().findCredentials('vscode-grammarly')) || [] | ||
|
||
return credentials.length | ||
? { | ||
username: credentials[0].account, | ||
password: credentials[0].password, | ||
} | ||
: null | ||
return null | ||
}, | ||
loadToken: async () => { | ||
if (process.env.EXTENSION_TEST_MODE) { | ||
return await getKeyTar().findPassword('vscode-grammarly-cookie') | ||
} else { | ||
return null | ||
} | ||
console.log('Get token...') | ||
if (process.env.EXTENSION_TEST_MODE) return null | ||
|
||
return await this.auth.getCookie() | ||
}, | ||
saveToken: async (cookie) => { | ||
if (cookie != null) { | ||
getKeyTar().setPassword('vscode-grammarly-cookie', 'default', cookie) | ||
} else { | ||
getKeyTar().deletePassword('vscode-grammarly-cookie', 'default') | ||
} | ||
await this.auth.setCookie(cookie) | ||
}, | ||
getIgnoredDocuments: (uri) => | ||
workspace.getConfiguration('grammarly', Uri.parse(uri)).get<string[]>('ignore') ?? [], | ||
}) | ||
} | ||
|
||
register() { | ||
return this.grammarly.start() | ||
return Disposable.from(this.start()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.