mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-04-27 15:50:57 -07:00
feat: getStorageServiceUserInfo
This commit is contained in:
parent
bf64b2bb61
commit
af69465549
2 changed files with 32 additions and 1 deletions
|
|
@ -2,13 +2,14 @@
|
|||
import { injectable } from 'inversify';
|
||||
import getDecorators from 'inversify-inject-decorators';
|
||||
import settings from 'electron-settings';
|
||||
import { IAuthingUserInfo as IAuthingUserInfo } from '@services/types';
|
||||
import { IAuthingUserInfo as IAuthingUserInfo, SupportedStorageServices } from '@services/types';
|
||||
import { container } from '@services/container';
|
||||
import type { IWindowService } from '@services/windows/interface';
|
||||
import serviceIdentifier from '@services/serviceIdentifier';
|
||||
import { AuthenticationChannel } from '@/constants/channels';
|
||||
import { IAuthenticationService, IUserInfos } from './interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { IGitUserInfos } from '@services/git/interface';
|
||||
|
||||
const { lazyInject } = getDecorators(container);
|
||||
|
||||
|
|
@ -34,6 +35,27 @@ export class Authentication implements IAuthenticationService {
|
|||
this.userInfo$.next(this.cachedUserInfo);
|
||||
}
|
||||
|
||||
public getStorageServiceUserInfo(serviceName: SupportedStorageServices): IGitUserInfos | undefined {
|
||||
switch (serviceName) {
|
||||
case SupportedStorageServices.github:
|
||||
const gitUserName = this.get('github-userName');
|
||||
const email = this.get('email');
|
||||
const accessToken = this.get('github-token');
|
||||
if (gitUserName && email && accessToken) {
|
||||
return {
|
||||
gitUserName,
|
||||
email,
|
||||
accessToken,
|
||||
};
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load UserInfos in sync, and ensure it is an Object
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,10 +2,17 @@
|
|||
import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common';
|
||||
import { AuthenticationChannel } from '@/constants/channels';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { IGitUserInfos } from '@services/git/interface';
|
||||
import { SupportedStorageServices } from '@services/types';
|
||||
|
||||
export interface IUserInfos {
|
||||
/** UserName in TiddlyWiki */
|
||||
userName: string;
|
||||
/** Git commit message email */
|
||||
email: string;
|
||||
/** Github Login: token */
|
||||
'github-token'?: string;
|
||||
/** Github Login: username , this is also used to filter user's repo when searching repo */
|
||||
'github-userName'?: string;
|
||||
}
|
||||
|
||||
|
|
@ -14,6 +21,7 @@ export interface IUserInfos {
|
|||
*/
|
||||
export interface IAuthenticationService {
|
||||
userInfo$: BehaviorSubject<IUserInfos>;
|
||||
getStorageServiceUserInfo(serviceName: SupportedStorageServices): IGitUserInfos | undefined;
|
||||
getUserInfos: () => IUserInfos;
|
||||
get<K extends keyof IUserInfos>(key: K): IUserInfos[K] | undefined;
|
||||
set<K extends keyof IUserInfos>(key: K, value: IUserInfos[K]): void;
|
||||
|
|
@ -23,6 +31,7 @@ export const AuthenticationServiceIPCDescriptor = {
|
|||
channel: AuthenticationChannel.name,
|
||||
properties: {
|
||||
userInfo$: ProxyPropertyType.Value$,
|
||||
getStorageServiceUserInfo: ProxyPropertyType.Function,
|
||||
getUserInfos: ProxyPropertyType.Function,
|
||||
get: ProxyPropertyType.Function,
|
||||
set: ProxyPropertyType.Function,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue