Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
8e822e10
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8e822e10
编写于
11月 19, 2019
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clarify statuses for AuthTokenService
上级
dda39439
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
28 addition
and
27 deletion
+28
-27
src/vs/platform/auth/common/auth.ts
src/vs/platform/auth/common/auth.ts
+4
-3
src/vs/platform/auth/electron-browser/authTokenService.ts
src/vs/platform/auth/electron-browser/authTokenService.ts
+7
-7
src/vs/platform/userDataSync/common/userDataSyncService.ts
src/vs/platform/userDataSync/common/userDataSyncService.ts
+3
-3
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
...vs/workbench/contrib/userDataSync/browser/userDataSync.ts
+8
-8
src/vs/workbench/services/authToken/browser/authTokenService.ts
.../workbench/services/authToken/browser/authTokenService.ts
+5
-5
src/vs/workbench/services/authToken/electron-browser/authTokenService.ts
...h/services/authToken/electron-browser/authTokenService.ts
+1
-1
未找到文件。
src/vs/platform/auth/common/auth.ts
浏览文件 @
8e822e10
...
...
@@ -8,10 +8,11 @@ import { Event, Emitter } from 'vs/base/common/event';
import
{
URI
}
from
'
vs/base/common/uri
'
;
export
const
enum
AuthTokenStatus
{
Inactive
=
'
Inactive
'
,
Active
=
'
Active
'
,
Initializing
=
'
Initializing
'
,
SignedOut
=
'
SignedOut
'
,
SignedIn
=
'
SignedIn
'
,
SigningIn
=
'
SigningIn
'
,
Refreshing
=
'
Refreshing
'
Refreshing
Token
=
'
RefreshingToken
'
}
export
const
IAuthTokenService
=
createDecorator
<
IAuthTokenService
>
(
'
IAuthTokenService
'
);
...
...
src/vs/platform/auth/electron-browser/authTokenService.ts
浏览文件 @
8e822e10
...
...
@@ -49,7 +49,7 @@ export interface IToken {
export
class
AuthTokenService
extends
Disposable
implements
IAuthTokenService
{
_serviceBrand
:
undefined
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
Refresh
ing
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
Initializ
ing
;
get
status
():
AuthTokenStatus
{
return
this
.
_status
;
}
private
_onDidChangeStatus
:
Emitter
<
AuthTokenStatus
>
=
this
.
_register
(
new
Emitter
<
AuthTokenStatus
>
());
readonly
onDidChangeStatus
:
Event
<
AuthTokenStatus
>
=
this
.
_onDidChangeStatus
.
event
;
...
...
@@ -67,7 +67,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
if
(
storedRefreshToken
)
{
this
.
refresh
(
storedRefreshToken
);
}
else
{
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
}
});
}
...
...
@@ -91,7 +91,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
const
timeoutPromise
=
new
Promise
((
resolve
:
(
value
:
IToken
)
=>
void
,
reject
)
=>
{
const
wait
=
setTimeout
(()
=>
{
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
clearTimeout
(
wait
);
reject
(
'
Login timed out.
'
);
},
1000
*
60
*
5
);
...
...
@@ -117,7 +117,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
private
setToken
(
token
:
IToken
)
{
this
.
_activeToken
=
token
;
this
.
credentialsService
.
setPassword
(
SERVICE_NAME
,
ACCOUNT
,
token
.
refreshToken
);
this
.
setStatus
(
AuthTokenStatus
.
Active
);
this
.
setStatus
(
AuthTokenStatus
.
SignedIn
);
}
private
async
exchangeCodeForToken
(
clientId
:
string
,
tenantId
:
string
,
codeVerifier
:
string
,
state
:
string
):
Promise
<
IToken
>
{
...
...
@@ -190,7 +190,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
private
async
refresh
(
refreshToken
:
string
):
Promise
<
void
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
setStatus
(
AuthTokenStatus
.
Refreshing
);
this
.
setStatus
(
AuthTokenStatus
.
Refreshing
Token
);
const
postData
=
toQuery
({
refresh_token
:
refreshToken
,
client_id
:
clientId
,
...
...
@@ -231,7 +231,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
post
.
end
();
post
.
on
(
'
error
'
,
err
=>
{
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
reject
(
err
);
});
});
...
...
@@ -240,7 +240,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
async
logout
():
Promise
<
void
>
{
await
this
.
credentialsService
.
deletePassword
(
SERVICE_NAME
,
ACCOUNT
);
this
.
_activeToken
=
undefined
;
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
}
private
setStatus
(
status
:
AuthTokenStatus
):
void
{
...
...
src/vs/platform/userDataSync/common/userDataSyncService.ts
浏览文件 @
8e822e10
...
...
@@ -56,7 +56,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
if
(
!
this
.
userDataSyncStoreService
.
enabled
)
{
throw
new
Error
(
'
Not enabled
'
);
}
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
Inactive
)
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SignedOut
)
{
throw
new
Error
(
'
Not Authenticated. Please sign in to start sync.
'
);
}
for
(
const
synchroniser
of
this
.
synchronisers
)
{
...
...
@@ -116,7 +116,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
}
private
onDidChangeAuthTokenStatus
():
void
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
Inactive
)
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SignedOut
)
{
this
.
stop
();
}
}
...
...
@@ -180,7 +180,7 @@ export class UserDataAutoSync extends Disposable {
private
isSyncEnabled
():
boolean
{
return
this
.
configurationService
.
getValue
<
boolean
>
(
'
configurationSync.enable
'
)
&&
this
.
userDataSyncService
.
status
!==
SyncStatus
.
Uninitialized
&&
this
.
authTokenService
.
status
!==
AuthTokenStatus
.
Inactive
;
&&
this
.
authTokenService
.
status
!==
AuthTokenStatus
.
SignedOut
;
}
}
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
浏览文件 @
8e822e10
...
...
@@ -31,7 +31,7 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import
{
IQuickInputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IProductService
}
from
'
vs/platform/product/common/productService
'
;
const
CONTEXT_AUTH_TOKEN_STATE
=
new
RawContextKey
<
string
>
(
'
authTokenStatus
'
,
AuthTokenStatus
.
Inactive
);
const
CONTEXT_AUTH_TOKEN_STATE
=
new
RawContextKey
<
string
>
(
'
authTokenStatus
'
,
AuthTokenStatus
.
SignedOut
);
const
SYNC_PUSH_LIGHT_ICON_URI
=
URI
.
parse
(
registerAndGetAmdImageURL
(
`vs/workbench/contrib/userDataSync/browser/media/check-light.svg`
));
const
SYNC_PUSH_DARK_ICON_URI
=
URI
.
parse
(
registerAndGetAmdImageURL
(
`vs/workbench/contrib/userDataSync/browser/media/check-dark.svg`
));
...
...
@@ -75,7 +75,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
private
onDidChangeAuthTokenStatus
(
status
:
AuthTokenStatus
)
{
this
.
authTokenContext
.
set
(
status
);
if
(
status
===
AuthTokenStatus
.
Active
)
{
if
(
status
===
AuthTokenStatus
.
SignedIn
)
{
this
.
signInNotificationDisposable
.
clear
();
}
this
.
updateBadge
();
...
...
@@ -111,7 +111,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
this
.
updateBadge
();
const
enabled
=
this
.
configurationService
.
getValue
<
boolean
>
(
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
);
if
(
enabled
)
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
Inactive
)
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SignedOut
)
{
const
handle
=
this
.
notificationService
.
prompt
(
Severity
.
Info
,
localize
(
'
ask to sign in
'
,
"
Please sign in with your {0} account to sync configuration across all your machines
"
,
this
.
productService
.
settingsSyncStore
!
.
account
),
[
{
...
...
@@ -133,7 +133,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
let
badge
:
IBadge
|
undefined
=
undefined
;
let
clazz
:
string
|
undefined
;
if
(
this
.
userDataSyncService
.
status
!==
SyncStatus
.
Uninitialized
&&
this
.
configurationService
.
getValue
<
boolean
>
(
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
)
&&
this
.
authTokenService
.
status
===
AuthTokenStatus
.
Inactive
)
{
if
(
this
.
userDataSyncService
.
status
!==
SyncStatus
.
Uninitialized
&&
this
.
configurationService
.
getValue
<
boolean
>
(
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
)
&&
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SignedOut
)
{
badge
=
new
NumberBadge
(
1
,
()
=>
localize
(
'
sign in
'
,
"
Sync: Sign in...
"
));
}
else
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SigningIn
)
{
badge
=
new
ProgressBadge
(()
=>
localize
(
'
signing in
'
,
"
Signin in...
"
));
...
...
@@ -151,7 +151,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}
private
async
turnOn
():
Promise
<
void
>
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
Inactive
)
{
if
(
this
.
authTokenService
.
status
===
AuthTokenStatus
.
SignedOut
)
{
const
result
=
await
this
.
dialogService
.
confirm
({
type
:
'
info
'
,
message
:
localize
(
'
sign in to account
'
,
"
Sign in to {0}
"
,
this
.
productService
.
settingsSyncStore
!
.
name
),
...
...
@@ -290,7 +290,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
startSyncMenuItem
);
const
signInCommandId
=
'
workbench.userData.actions.signin
'
;
const
signInWhenContext
=
ContextKeyExpr
.
and
(
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
Uninitialized
),
ContextKeyExpr
.
has
(
`config.
${
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
}
`
),
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
Inactive
));
const
signInWhenContext
=
ContextKeyExpr
.
and
(
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
Uninitialized
),
ContextKeyExpr
.
has
(
`config.
${
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
}
`
),
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
SignedOut
));
CommandsRegistry
.
registerCommand
(
signInCommandId
,
()
=>
this
.
signIn
());
MenuRegistry
.
appendMenuItem
(
MenuId
.
GlobalActivity
,
{
group
:
'
5_sync
'
,
...
...
@@ -328,7 +328,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
MenuRegistry
.
appendMenuItem
(
MenuId
.
GlobalActivity
,
{
group
:
'
5_sync
'
,
command
:
stopSyncCommand
,
when
:
ContextKeyExpr
.
and
(
ContextKeyExpr
.
has
(
`config.
${
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
}
`
),
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
Active
),
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
Uninitialized
),
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
HasConflicts
))
when
:
ContextKeyExpr
.
and
(
ContextKeyExpr
.
has
(
`config.
${
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
}
`
),
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
SignedIn
),
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
Uninitialized
),
CONTEXT_SYNC_STATE
.
notEqualsTo
(
SyncStatus
.
HasConflicts
))
});
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
{
command
:
stopSyncCommand
,
...
...
@@ -383,7 +383,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
id
:
'
workbench.userData.actions.signout
'
,
title
:
localize
(
'
sign out
'
,
"
Sign Out
"
)
},
when
:
ContextKeyExpr
.
and
(
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
Active
)),
when
:
ContextKeyExpr
.
and
(
CONTEXT_AUTH_TOKEN_STATE
.
isEqualTo
(
AuthTokenStatus
.
SignedIn
)),
};
CommandsRegistry
.
registerCommand
(
signOutMenuItem
.
command
.
id
,
()
=>
this
.
signOut
());
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
signOutMenuItem
);
...
...
src/vs/workbench/services/authToken/browser/authTokenService.ts
浏览文件 @
8e822e10
...
...
@@ -17,7 +17,7 @@ const ACCOUNT = 'MyAccount';
export
class
AuthTokenService
extends
Disposable
implements
IAuthTokenService
{
_serviceBrand
:
undefined
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
Refresh
ing
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
Initializ
ing
;
get
status
():
AuthTokenStatus
{
return
this
.
_status
;
}
private
_onDidChangeStatus
:
Emitter
<
AuthTokenStatus
>
=
this
.
_register
(
new
Emitter
<
AuthTokenStatus
>
());
readonly
onDidChangeStatus
:
Event
<
AuthTokenStatus
>
=
this
.
_onDidChangeStatus
.
event
;
...
...
@@ -31,9 +31,9 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
super
();
this
.
getToken
().
then
(
token
=>
{
if
(
token
)
{
this
.
setStatus
(
AuthTokenStatus
.
Active
);
this
.
setStatus
(
AuthTokenStatus
.
SignedIn
);
}
else
{
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
}
});
}
...
...
@@ -51,7 +51,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
const
token
=
await
this
.
quickInputService
.
input
({
placeHolder
:
localize
(
'
enter token
'
,
"
Please provide the auth bearer token
"
),
ignoreFocusLost
:
true
,
});
if
(
token
)
{
await
this
.
credentialsService
.
setPassword
(
SERVICE_NAME
,
ACCOUNT
,
token
);
this
.
setStatus
(
AuthTokenStatus
.
Active
);
this
.
setStatus
(
AuthTokenStatus
.
SignedIn
);
}
}
...
...
@@ -61,7 +61,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
async
logout
():
Promise
<
void
>
{
await
this
.
credentialsService
.
deletePassword
(
SERVICE_NAME
,
ACCOUNT
);
this
.
setStatus
(
AuthTokenStatus
.
Inactive
);
this
.
setStatus
(
AuthTokenStatus
.
SignedOut
);
}
private
setStatus
(
status
:
AuthTokenStatus
):
void
{
...
...
src/vs/workbench/services/authToken/electron-browser/authTokenService.ts
浏览文件 @
8e822e10
...
...
@@ -18,7 +18,7 @@ export class AuthTokenService extends Disposable implements IAuthTokenService {
private
readonly
channel
:
IChannel
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
In
active
;
private
_status
:
AuthTokenStatus
=
AuthTokenStatus
.
In
itializing
;
get
status
():
AuthTokenStatus
{
return
this
.
_status
;
}
private
_onDidChangeStatus
:
Emitter
<
AuthTokenStatus
>
=
this
.
_register
(
new
Emitter
<
AuthTokenStatus
>
());
readonly
onDidChangeStatus
:
Event
<
AuthTokenStatus
>
=
this
.
_onDidChangeStatus
.
event
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录