Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9146c53f
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9146c53f
编写于
12月 17, 2019
作者:
M
Marvin Heilemann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Resolved some requested changes
上级
6099ca39
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
55 deletion
+52
-55
src/vs/workbench/services/themes/browser/workbenchThemeService.ts
...orkbench/services/themes/browser/workbenchThemeService.ts
+52
-47
src/vs/workbench/services/themes/common/workbenchThemeService.ts
...workbench/services/themes/common/workbenchThemeService.ts
+0
-8
未找到文件。
src/vs/workbench/services/themes/browser/workbenchThemeService.ts
浏览文件 @
9146c53f
...
...
@@ -6,7 +6,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
{
IExtensionService
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
import
{
IWorkbenchThemeService
,
IColorTheme
,
ITokenColorCustomizations
,
IFileIconTheme
,
ExtensionData
,
VS_LIGHT_THEME
,
VS_DARK_THEME
,
VS_HC_THEME
,
COLOR_THEME_SETTING
,
ICON_THEME_SETTING
,
CUSTOM_WORKBENCH_COLORS_SETTING
,
CUSTOM_EDITOR_COLORS_SETTING
,
DETECT_HC_SETTING
,
HC_THEME_ID
,
IColorCustomizations
,
CUSTOM_EDITOR_TOKENSTYLES_SETTING
,
IExperimentalTokenStyleCustomizations
,
DETECT_AS_SETTING
,
COLOR_THEME_DARK_SETTING
,
WINDOW_MATCH_PREFERS_COLOR_SCHEME
,
COLOR_THEME_LIGHT_SETTING
,
ColorScheme
}
from
'
vs/workbench/services/themes/common/workbenchThemeService
'
;
import
{
IWorkbenchThemeService
,
IColorTheme
,
ITokenColorCustomizations
,
IFileIconTheme
,
ExtensionData
,
VS_LIGHT_THEME
,
VS_DARK_THEME
,
VS_HC_THEME
,
COLOR_THEME_SETTING
,
ICON_THEME_SETTING
,
CUSTOM_WORKBENCH_COLORS_SETTING
,
CUSTOM_EDITOR_COLORS_SETTING
,
DETECT_HC_SETTING
,
HC_THEME_ID
,
IColorCustomizations
,
CUSTOM_EDITOR_TOKENSTYLES_SETTING
,
IExperimentalTokenStyleCustomizations
,
DETECT_AS_SETTING
,
COLOR_THEME_DARK_SETTING
,
COLOR_THEME_LIGHT_SETTING
}
from
'
vs/workbench/services/themes/common/workbenchThemeService
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
...
...
@@ -14,7 +14,7 @@ import * as errors from 'vs/base/common/errors';
import
{
IConfigurationService
,
ConfigurationTarget
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigurationExtensions
,
IConfigurationPropertySchema
,
IConfigurationNode
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
{
ColorThemeData
}
from
'
vs/workbench/services/themes/common/colorThemeData
'
;
import
{
ITheme
,
Extensions
as
ThemingExtensions
,
IThemingRegistry
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
ITheme
,
Extensions
as
ThemingExtensions
,
IThemingRegistry
,
DARK
,
LIGHT
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
registerFileIconThemeSchemas
}
from
'
vs/workbench/services/themes/common/fileIconThemeSchema
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
...
...
@@ -43,6 +43,12 @@ const DEFAULT_THEME_DARK_SETTING_VALUE = 'Default Dark+';
const
DEFAULT_THEME_LIGHT_SETTING_VALUE
=
'
Default Light+
'
;
const
DEFAULT_THEME_AUTO_SWITCH_SETTING_VALUE
=
true
;
enum
ColorScheme
{
LIGHT
=
'
light
'
,
DARK
=
'
dark
'
,
NO_PREFERENCE
=
'
no-preference
'
}
const
PERSISTED_THEME_STORAGE_KEY
=
'
colorThemeData
'
;
const
PERSISTED_ICON_THEME_STORAGE_KEY
=
'
iconThemeData
'
;
...
...
@@ -75,8 +81,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
private
colorThemeStore
:
ColorThemeStore
;
private
currentColorTheme
:
ColorThemeData
;
private
autoSwitchColorTheme
=
DEFAULT_THEME_AUTO_SWITCH_SETTING_VALUE
;
private
autoSwitchColorThemeListener
:
MediaQueryList
|
undefined
=
undefined
;
private
autoSwitchColorTheme
:
MediaQueryList
|
undefined
;
private
container
:
HTMLElement
;
private
readonly
onColorThemeChange
:
Emitter
<
IColorTheme
>
;
private
watchedColorThemeLocation
:
URI
|
undefined
;
...
...
@@ -259,7 +264,6 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
let
iconThemeSetting
=
this
.
configurationService
.
getValue
<
string
|
null
>
(
ICON_THEME_SETTING
);
let
detectThemeAutoSwitch
=
this
.
configurationService
.
getValue
<
boolean
>
(
DETECT_AS_SETTING
);
this
.
autoSwitchColorTheme
=
detectThemeAutoSwitch
;
if
(
detectThemeAutoSwitch
)
{
colorThemeSetting
=
this
.
getPreferredTheme
();
}
...
...
@@ -277,7 +281,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
}
return
Promise
.
all
([
this
.
getColorThemeData
(
colorThemeSetting
).
then
(
theme
=>
{
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
return
this
.
colorThemeStore
.
findThemeDataByParentLocation
(
uri
).
then
(
devThemes
=>
{
if
(
devThemes
.
length
)
{
return
this
.
setColorTheme
(
devThemes
[
0
].
id
,
ConfigurationTarget
.
MEMORY
);
...
...
@@ -300,28 +304,32 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
private
installColorThemeSwitch
()
{
console
.
log
(
'
INSTALL
'
);
this
.
autoSwitchColorTheme
Listener
=
window
.
matchMedia
(
WINDOW_MATCH_PREFERS_COLOR_SCHEME
);
this
.
autoSwitchColorTheme
Listener
.
addListener
(
this
.
onPreferColorSchemeChange
);
this
.
autoSwitchColorTheme
=
window
.
matchMedia
(
'
(prefers-color-scheme: dark)
'
);
this
.
autoSwitchColorTheme
.
addListener
(
this
.
onPreferColorSchemeChange
);
console
.
log
(
'
INSTALLED
'
);
}
private
deinstallColorThemeSwitch
()
{
console
.
log
(
'
DEINSTALL
'
);
if
(
this
.
autoSwitchColorTheme
Listener
)
{
this
.
autoSwitchColorTheme
Listener
.
removeListener
(
this
.
onPreferColorSchemeChange
);
if
(
this
.
autoSwitchColorTheme
)
{
this
.
autoSwitchColorTheme
.
removeListener
(
this
.
onPreferColorSchemeChange
);
this
.
configurationService
.
updateValue
(
DETECT_AS_SETTING
,
false
);
console
.
log
(
'
DEINSTALLED
'
);
}
}
private
onPreferColorSchemeChange
<
MediaQueryList
>
({
matches
}:
MediaQueryListEvent
)
{
private
onPreferColorSchemeChange
({
matches
}:
MediaQueryListEvent
)
{
console
.
log
(
'
onPreferColorSchemeChange
'
,
matches
);
let
themeName
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_LIGHT_SETTING
);
let
colorThemeSetting
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_LIGHT_SETTING
);
if
(
matches
)
{
// prefers dark mode
themeName
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_DARK_SETTING
);
colorThemeSetting
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_DARK_SETTING
);
}
this
.
setTheme
(
themeName
);
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
if
(
theme
)
{
this
.
setColorTheme
(
theme
.
id
,
undefined
);
}
});
}
private
installConfigurationListener
()
{
...
...
@@ -329,23 +337,33 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
if
(
e
.
affectsConfiguration
(
COLOR_THEME_SETTING
))
{
let
colorThemeSetting
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_SETTING
);
if
(
colorThemeSetting
!==
this
.
currentColorTheme
.
settingsId
)
{
this
.
setTheme
(
colorThemeSetting
);
this
.
deinstallColorThemeSwitch
();
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
if
(
theme
)
{
if
(
this
.
autoSwitchColorTheme
&&
theme
.
type
===
DARK
)
{
this
.
configurationService
.
updateValue
(
COLOR_THEME_DARK_SETTING
,
theme
.
settingsId
);
}
if
(
this
.
autoSwitchColorTheme
&&
theme
.
type
===
LIGHT
)
{
this
.
configurationService
.
updateValue
(
COLOR_THEME_LIGHT_SETTING
,
theme
.
settingsId
);
}
this
.
setColorTheme
(
theme
.
id
,
undefined
);
}
});
}
}
if
(
e
.
affectsConfiguration
(
DETECT_AS_SETTING
))
{
let
autoSwitchColorTheme
=
this
.
configurationService
.
getValue
<
boolean
>
(
DETECT_AS_SETTING
);
console
.
log
(
autoSwitchColorTheme
);
if
(
this
.
autoSwitchColorTheme
!==
autoSwitchColorTheme
)
{
this
.
autoSwitchColorTheme
=
autoSwitchColorTheme
;
console
.
log
(
'
HAS CHANGED
'
);
if
(
autoSwitchColorTheme
)
{
this
.
installColorThemeSwitch
();
let
themeName
=
this
.
getPreferredTheme
();
this
.
setTheme
(
themeName
);
}
else
{
this
.
deinstallColorThemeSwitch
();
if
(
autoSwitchColorTheme
)
{
this
.
installColorThemeSwitch
();
let
colorThemeSetting
=
this
.
getPreferredTheme
();
if
(
colorThemeSetting
!==
this
.
currentColorTheme
.
settingsId
)
{
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
if
(
theme
)
{
this
.
setColorTheme
(
theme
.
id
,
undefined
);
}
});
}
}
else
{
this
.
deinstallColorThemeSwitch
();
}
}
if
(
e
.
affectsConfiguration
(
ICON_THEME_SETTING
))
{
...
...
@@ -398,14 +416,6 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return
ColorScheme
.
LIGHT
;
}
public
getColorThemeData
(
colorThemeSetting
:
string
):
Promise
<
IColorTheme
>
{
return
new
Promise
(
resolve
=>
{
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
resolve
(
theme
);
});
});
}
public
getColorTheme
():
IColorTheme
{
return
this
.
currentColorTheme
;
}
...
...
@@ -418,15 +428,6 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return
this
.
getColorTheme
();
}
public
setTheme
(
themeName
:
string
)
{
this
.
getColorThemeData
(
themeName
).
then
(
theme
=>
{
if
(
theme
)
{
this
.
setColorTheme
(
theme
.
id
,
undefined
);
this
.
configurationService
.
updateValue
(
COLOR_THEME_SETTING
,
themeName
);
}
});
}
public
setColorTheme
(
themeId
:
string
|
undefined
,
settingsTarget
:
ConfigurationTarget
|
undefined
|
'
auto
'
):
Promise
<
IColorTheme
|
null
>
{
if
(
!
themeId
)
{
return
Promise
.
resolve
(
null
);
...
...
@@ -437,11 +438,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
themeId
=
validateThemeId
(
themeId
);
// migrate theme ids
return
this
.
colorThemeStore
.
findThemeData
(
themeId
,
DEFAULT_THEME_ID
).
then
(
d
ata
=>
{
if
(
!
d
ata
)
{
return
this
.
colorThemeStore
.
findThemeData
(
themeId
,
DEFAULT_THEME_ID
).
then
(
themeD
ata
=>
{
if
(
!
themeD
ata
)
{
return
null
;
}
const
themeData
=
data
;
this
.
configurationService
.
updateValue
(
COLOR_THEME_SETTING
,
themeData
.
settingsId
)
;
return
themeData
.
ensureLoaded
(
this
.
extensionResourceLoaderService
).
then
(
_
=>
{
if
(
themeId
===
this
.
currentColorTheme
.
id
&&
!
this
.
currentColorTheme
.
isLoaded
&&
this
.
currentColorTheme
.
hasEqualData
(
themeData
))
{
this
.
currentColorTheme
.
clearCaches
();
...
...
@@ -475,7 +476,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
public
restoreColorTheme
()
{
let
colorThemeSetting
=
this
.
configurationService
.
getValue
<
string
>
(
COLOR_THEME_SETTING
);
if
(
colorThemeSetting
!==
this
.
currentColorTheme
.
settingsId
)
{
this
.
setTheme
(
colorThemeSetting
);
this
.
colorThemeStore
.
findThemeDataBySettingsId
(
colorThemeSetting
,
DEFAULT_THEME_ID
).
then
(
theme
=>
{
if
(
theme
)
{
this
.
setColorTheme
(
theme
.
id
,
undefined
);
}
});
}
}
...
...
src/vs/workbench/services/themes/common/workbenchThemeService.ts
浏览文件 @
9146c53f
...
...
@@ -21,19 +21,12 @@ export const COLOR_THEME_SETTING = 'workbench.colorTheme';
export
const
COLOR_THEME_DARK_SETTING
=
'
workbench.colorThemeDark
'
;
export
const
COLOR_THEME_LIGHT_SETTING
=
'
workbench.colorThemeLight
'
;
export
const
DETECT_AS_SETTING
=
'
workbench.colorThemeAutoSwitch
'
;
export
const
WINDOW_MATCH_PREFERS_COLOR_SCHEME
=
'
(prefers-color-scheme: dark)
'
;
export
const
DETECT_HC_SETTING
=
'
window.autoDetectHighContrast
'
;
export
const
ICON_THEME_SETTING
=
'
workbench.iconTheme
'
;
export
const
CUSTOM_WORKBENCH_COLORS_SETTING
=
'
workbench.colorCustomizations
'
;
export
const
CUSTOM_EDITOR_COLORS_SETTING
=
'
editor.tokenColorCustomizations
'
;
export
const
CUSTOM_EDITOR_TOKENSTYLES_SETTING
=
'
editor.tokenColorCustomizationsExperimental
'
;
export
enum
ColorScheme
{
LIGHT
=
'
light
'
,
DARK
=
'
dark
'
,
NO_PREFERENCE
=
'
no-preference
'
}
export
interface
IColorTheme
extends
ITheme
{
readonly
id
:
string
;
readonly
label
:
string
;
...
...
@@ -66,7 +59,6 @@ export interface IWorkbenchThemeService extends IThemeService {
setColorTheme
(
themeId
:
string
|
undefined
,
settingsTarget
:
ConfigurationTarget
|
undefined
):
Promise
<
IColorTheme
|
null
>
;
getColorTheme
():
IColorTheme
;
getColorThemes
():
Promise
<
IColorTheme
[]
>
;
getColorThemeData
(
colorThemeSetting
:
string
):
Promise
<
IColorTheme
|
null
>
;
onDidColorThemeChange
:
Event
<
IColorTheme
>
;
restoreColorTheme
():
void
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录