@opensumi/ide-core-browser 2.24.6-rc-1685671765.0 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application/application.service.d.ts +1 -0
- package/lib/application/application.service.d.ts.map +1 -1
- package/lib/application/application.service.js +10 -0
- package/lib/application/application.service.js.map +1 -1
- package/lib/bootstrap/app.d.ts.map +1 -1
- package/lib/bootstrap/app.js +10 -0
- package/lib/bootstrap/app.js.map +1 -1
- package/lib/bootstrap/inner-providers-electron.d.ts +3 -0
- package/lib/bootstrap/inner-providers-electron.d.ts.map +1 -0
- package/lib/bootstrap/inner-providers-electron.js +33 -0
- package/lib/bootstrap/inner-providers-electron.js.map +1 -0
- package/lib/bootstrap/inner-providers.d.ts.map +1 -1
- package/lib/bootstrap/inner-providers.js +11 -26
- package/lib/bootstrap/inner-providers.js.map +1 -1
- package/lib/common/common.command.d.ts.map +1 -1
- package/lib/common/common.command.js +1 -0
- package/lib/common/common.command.js.map +1 -1
- package/lib/common/common.contribution.d.ts.map +1 -1
- package/lib/common/common.contribution.js +0 -91
- package/lib/common/common.contribution.js.map +1 -1
- package/lib/common/common.module.d.ts +7 -5
- package/lib/common/common.module.d.ts.map +1 -1
- package/lib/common/common.module.js +5 -0
- package/lib/common/common.module.js.map +1 -1
- package/lib/common/electron.contribution.d.ts +6 -0
- package/lib/common/electron.contribution.d.ts.map +1 -0
- package/lib/common/electron.contribution.js +88 -0
- package/lib/common/electron.contribution.js.map +1 -0
- package/lib/common/web.contribution.d.ts +5 -0
- package/lib/common/web.contribution.d.ts.map +1 -0
- package/lib/common/web.contribution.js +37 -0
- package/lib/common/web.contribution.js.map +1 -0
- package/lib/components/actions/index.d.ts +1 -0
- package/lib/components/actions/index.d.ts.map +1 -1
- package/lib/components/actions/index.js +15 -8
- package/lib/components/actions/index.js.map +1 -1
- package/lib/components/actions/styles.module.less +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/menu/next/menu.interface.d.ts +4 -0
- package/lib/menu/next/menu.interface.d.ts.map +1 -1
- package/lib/menu/next/menu.interface.js +12 -1
- package/lib/menu/next/menu.interface.js.map +1 -1
- package/lib/opener/opener-electron.contribution.d.ts +7 -0
- package/lib/opener/opener-electron.contribution.d.ts.map +1 -0
- package/lib/opener/opener-electron.contribution.js +33 -0
- package/lib/opener/opener-electron.contribution.js.map +1 -0
- package/lib/opener/opener.contribution.d.ts.map +1 -1
- package/lib/opener/opener.contribution.js +0 -10
- package/lib/opener/opener.contribution.js.map +1 -1
- package/lib/preferences/early-preferences.d.ts.map +1 -1
- package/lib/preferences/early-preferences.js +6 -1
- package/lib/preferences/early-preferences.js.map +1 -1
- package/lib/static-resource/index.d.ts +8 -0
- package/lib/static-resource/index.d.ts.map +1 -0
- package/lib/static-resource/index.js +30 -0
- package/lib/static-resource/index.js.map +1 -0
- package/lib/static-resource/static.definition.d.ts +60 -0
- package/lib/static-resource/static.definition.d.ts.map +1 -0
- package/lib/static-resource/static.definition.js +24 -0
- package/lib/static-resource/static.definition.js.map +1 -0
- package/lib/static-resource/static.service.d.ts +11 -0
- package/lib/static-resource/static.service.d.ts.map +1 -0
- package/lib/static-resource/static.service.js +40 -0
- package/lib/static-resource/static.service.js.map +1 -0
- package/lib/utils/env.d.ts +2 -2
- package/lib/utils/env.js +2 -2
- package/lib/utils/schema.d.ts +3 -0
- package/lib/utils/schema.d.ts.map +1 -0
- package/lib/utils/schema.js +14 -0
- package/lib/utils/schema.js.map +1 -0
- package/package.json +5 -5
- package/src/application/application.service.ts +10 -0
- package/src/bootstrap/app.ts +12 -0
- package/src/bootstrap/inner-providers-electron.ts +48 -0
- package/src/bootstrap/inner-providers.ts +10 -44
- package/src/common/common.command.ts +1 -0
- package/src/common/common.contribution.ts +0 -91
- package/src/common/common.module.ts +9 -2
- package/src/common/electron.contribution.ts +82 -0
- package/src/common/web.contribution.ts +32 -0
- package/src/components/actions/index.tsx +41 -22
- package/src/components/actions/styles.module.less +5 -0
- package/src/index.ts +2 -0
- package/src/menu/next/menu.interface.ts +12 -0
- package/src/opener/opener-electron.contribution.ts +26 -0
- package/src/opener/opener.contribution.ts +0 -11
- package/src/preferences/early-preferences.ts +8 -3
- package/src/static-resource/index.ts +24 -0
- package/src/static-resource/static.definition.ts +70 -0
- package/src/static-resource/static.service.ts +37 -0
- package/src/utils/env.ts +2 -2
- package/src/utils/schema.ts +11 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import { localize, Domain } from '@opensumi/ide-core-common';
|
|
3
|
+
|
|
4
|
+
import { MenuContribution, IMenuRegistry } from '../menu/next/base';
|
|
5
|
+
import { MenuId } from '../menu/next/menu-id';
|
|
6
|
+
import { AppConfig } from '../react-providers/config-provider';
|
|
7
|
+
|
|
8
|
+
@Domain(MenuContribution)
|
|
9
|
+
export class ClientElectronCommonContribution implements MenuContribution {
|
|
10
|
+
@Autowired(AppConfig)
|
|
11
|
+
private appConfig: AppConfig;
|
|
12
|
+
|
|
13
|
+
registerMenus(menus: IMenuRegistry): void {
|
|
14
|
+
// 注册 Menubar
|
|
15
|
+
menus.registerMenubarItem(MenuId.MenubarAppMenu, {
|
|
16
|
+
label: localize('app.name', this.appConfig.appName),
|
|
17
|
+
order: 0,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Edit 菜单
|
|
21
|
+
menus.registerMenuItems(MenuId.MenubarEditMenu, [
|
|
22
|
+
{
|
|
23
|
+
command: {
|
|
24
|
+
id: 'electron.undo',
|
|
25
|
+
label: localize('editor.undo'),
|
|
26
|
+
},
|
|
27
|
+
nativeRole: 'undo',
|
|
28
|
+
group: '1_undo',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
command: {
|
|
32
|
+
id: 'electron.redo',
|
|
33
|
+
label: localize('editor.redo'),
|
|
34
|
+
},
|
|
35
|
+
group: '1_undo',
|
|
36
|
+
nativeRole: 'redo',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
command: {
|
|
40
|
+
label: localize('edit.cut'),
|
|
41
|
+
id: 'electron.cut',
|
|
42
|
+
},
|
|
43
|
+
nativeRole: 'cut',
|
|
44
|
+
group: '2_clipboard',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
command: {
|
|
48
|
+
label: localize('edit.copy'),
|
|
49
|
+
id: 'electron.copy',
|
|
50
|
+
},
|
|
51
|
+
nativeRole: 'copy',
|
|
52
|
+
group: '2_clipboard',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
command: {
|
|
56
|
+
label: localize('edit.paste'),
|
|
57
|
+
id: 'electron.paste',
|
|
58
|
+
},
|
|
59
|
+
nativeRole: 'paste',
|
|
60
|
+
group: '2_clipboard',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
command: {
|
|
64
|
+
label: localize('edit.selectAll'),
|
|
65
|
+
id: 'electron.selectAll',
|
|
66
|
+
},
|
|
67
|
+
nativeRole: 'selectAll',
|
|
68
|
+
group: '2_clipboard',
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
menus.registerMenuItems(MenuId.MenubarAppMenu, [
|
|
72
|
+
{
|
|
73
|
+
command: {
|
|
74
|
+
id: 'electron.quit',
|
|
75
|
+
label: localize('app.quit'),
|
|
76
|
+
},
|
|
77
|
+
nativeRole: 'quit',
|
|
78
|
+
group: '4_quit',
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Domain } from '@opensumi/ide-core-common';
|
|
2
|
+
|
|
3
|
+
import { MenuContribution, IMenuRegistry } from '../menu/next/base';
|
|
4
|
+
import { MenuId } from '../menu/next/menu-id';
|
|
5
|
+
|
|
6
|
+
import { COMMON_COMMANDS, EDITOR_COMMANDS } from './common.command';
|
|
7
|
+
|
|
8
|
+
@Domain(MenuContribution)
|
|
9
|
+
export class ClientWebCommonContribution implements MenuContribution {
|
|
10
|
+
registerMenus(menus: IMenuRegistry): void {
|
|
11
|
+
// Edit 菜单
|
|
12
|
+
menus.registerMenuItems(MenuId.MenubarEditMenu, [
|
|
13
|
+
{
|
|
14
|
+
command: EDITOR_COMMANDS.REDO.id,
|
|
15
|
+
group: '1_undo',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
command: EDITOR_COMMANDS.UNDO.id,
|
|
19
|
+
group: '1_undo',
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
// 帮助菜单
|
|
23
|
+
menus.registerMenuItem(MenuId.MenubarHelpMenu, {
|
|
24
|
+
command: {
|
|
25
|
+
id: COMMON_COMMANDS.ABOUT_COMMAND.id,
|
|
26
|
+
label: COMMON_COMMANDS.ABOUT_COMMAND.label!,
|
|
27
|
+
},
|
|
28
|
+
nativeRole: 'about',
|
|
29
|
+
group: '0_about',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -29,11 +29,20 @@ const MenuAction: React.FC<{
|
|
|
29
29
|
data: MenuNode;
|
|
30
30
|
disabled?: boolean;
|
|
31
31
|
hasSubmenu?: boolean;
|
|
32
|
-
|
|
32
|
+
iconService?: IMenubarIconService;
|
|
33
|
+
}> = ({ data, hasSubmenu, disabled, iconService }) => (
|
|
33
34
|
// 这里遵循 native menu 的原则,保留一个 icon 位置
|
|
34
35
|
<div className={clsx(styles.menuAction, { [styles.disabled]: disabled, [styles.checked]: data.checked })}>
|
|
35
36
|
<div className={styles.icon}>{data.checked ? <Icon icon='check' /> : null}</div>
|
|
36
|
-
<div className={styles.label}>
|
|
37
|
+
<div className={styles.label}>
|
|
38
|
+
{data.label
|
|
39
|
+
? transformLabelWithCodicon(
|
|
40
|
+
strings.mnemonicButtonLabel(data.label, true),
|
|
41
|
+
{ margin: '0 3px' },
|
|
42
|
+
iconService?.fromString.bind(iconService),
|
|
43
|
+
)
|
|
44
|
+
: ''}
|
|
45
|
+
</div>
|
|
37
46
|
<div className={styles.tip}>
|
|
38
47
|
{data.keybinding ? <div className={styles.shortcut}>{data.keybinding}</div> : null}
|
|
39
48
|
{hasSubmenu ? (
|
|
@@ -53,7 +62,8 @@ export const MenuActionList: React.FC<{
|
|
|
53
62
|
afterClick?: (item: MenuNode) => void;
|
|
54
63
|
context?: any[];
|
|
55
64
|
style?: React.CSSProperties;
|
|
56
|
-
|
|
65
|
+
iconService?: IMenubarIconService;
|
|
66
|
+
}> = ({ data = [], context = [], afterClick, style, iconService }) => {
|
|
57
67
|
if (!data.length) {
|
|
58
68
|
return null;
|
|
59
69
|
}
|
|
@@ -88,9 +98,9 @@ export const MenuActionList: React.FC<{
|
|
|
88
98
|
(dataSource: MenuNode[], key?: string) =>
|
|
89
99
|
dataSource.map((menuNode, index) => {
|
|
90
100
|
if (menuNode.id === SeparatorMenuItemNode.ID) {
|
|
91
|
-
return
|
|
101
|
+
return null;
|
|
92
102
|
}
|
|
93
|
-
|
|
103
|
+
const hasSeparator = dataSource[index + 1] && dataSource[index + 1].id === SeparatorMenuItemNode.ID;
|
|
94
104
|
if (menuNode.id === SubmenuItemNode.ID) {
|
|
95
105
|
// 子菜单项为空时不渲染
|
|
96
106
|
if (!Array.isArray(menuNode.children) || !menuNode.children.length) {
|
|
@@ -98,26 +108,32 @@ export const MenuActionList: React.FC<{
|
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
return (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
<>
|
|
112
|
+
<Menu.SubMenu
|
|
113
|
+
key={`${(menuNode as SubmenuItemNode).submenuId}-${index}`}
|
|
114
|
+
className={styles.submenuItem}
|
|
115
|
+
popupClassName='kt-menu'
|
|
116
|
+
title={<MenuAction hasSubmenu data={menuNode} iconService={iconService} />}
|
|
117
|
+
>
|
|
118
|
+
{recursiveRender(menuNode.children, menuNode.label)}
|
|
119
|
+
</Menu.SubMenu>
|
|
120
|
+
{hasSeparator ? <Menu.Divider key={`divider-${index}`} className={styles.menuItemDivider} /> : null}
|
|
121
|
+
</>
|
|
109
122
|
);
|
|
110
123
|
}
|
|
111
124
|
|
|
112
125
|
return (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
<>
|
|
127
|
+
<Menu.Item
|
|
128
|
+
id={`${menuNode.id}-${index}`}
|
|
129
|
+
key={`${menuNode.id}-${key}-${index}`}
|
|
130
|
+
className={styles.menuItem}
|
|
131
|
+
disabled={menuNode.disabled}
|
|
132
|
+
>
|
|
133
|
+
<MenuAction data={menuNode} disabled={menuNode.disabled} iconService={iconService} />
|
|
134
|
+
</Menu.Item>
|
|
135
|
+
{hasSeparator ? <Menu.Divider key={`divider-${index}`} className={styles.menuItemDivider} /> : null}
|
|
136
|
+
</>
|
|
121
137
|
);
|
|
122
138
|
}),
|
|
123
139
|
[],
|
|
@@ -453,7 +469,10 @@ export function InlineActionBar<T = undefined, U = undefined, K = undefined, M =
|
|
|
453
469
|
// 因为这里的 context 塞到 useMenus 之后会自动把参数加入到 MenuItem.execute 里面
|
|
454
470
|
const [navMenu, moreMenu] = useMenus(menus, separator, context, debounce);
|
|
455
471
|
|
|
456
|
-
const navMenus = useMemo(
|
|
472
|
+
const navMenus = useMemo(
|
|
473
|
+
() => (isFlattenMenu ? [...navMenu, ...moreMenu] : navMenu),
|
|
474
|
+
[navMenu, moreMenu, isFlattenMenu],
|
|
475
|
+
);
|
|
457
476
|
|
|
458
477
|
// inline 菜单不取第二组,对应内容由关联 context menu 去渲染
|
|
459
478
|
return (
|
package/src/index.ts
CHANGED
|
@@ -201,6 +201,18 @@ export class SeparatorMenuItemNode extends MenuNode {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
// 只展示 label 的 menu node
|
|
205
|
+
export class LabelMenuItemNode extends MenuNode {
|
|
206
|
+
static readonly ID = 'menu.item.node.label';
|
|
207
|
+
|
|
208
|
+
constructor(label: string) {
|
|
209
|
+
super({
|
|
210
|
+
id: LabelMenuItemNode.ID,
|
|
211
|
+
label,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
204
216
|
export interface IMenu extends IDisposable {
|
|
205
217
|
/**
|
|
206
218
|
* menu-id
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Injector, Autowired, INJECTOR_TOKEN } from '@opensumi/di';
|
|
2
|
+
import { Domain } from '@opensumi/ide-core-common';
|
|
3
|
+
import { IElectronRendererURLService, IElectronURLService } from '@opensumi/ide-core-common/lib/electron';
|
|
4
|
+
|
|
5
|
+
import { ClientAppContribution } from '../common/common.define';
|
|
6
|
+
import { electronEnv } from '../utils/electron';
|
|
7
|
+
|
|
8
|
+
import { IOpenerService } from '.';
|
|
9
|
+
|
|
10
|
+
@Domain(ClientAppContribution)
|
|
11
|
+
export class ElectronOpenerContributionClient implements ClientAppContribution {
|
|
12
|
+
@Autowired(INJECTOR_TOKEN)
|
|
13
|
+
private readonly injector: Injector;
|
|
14
|
+
|
|
15
|
+
@Autowired(IOpenerService)
|
|
16
|
+
private readonly openerService: IOpenerService;
|
|
17
|
+
|
|
18
|
+
onStart() {
|
|
19
|
+
const electronRendererURLService: IElectronRendererURLService = this.injector.get(IElectronURLService);
|
|
20
|
+
electronRendererURLService.on('open-url', (payload) => {
|
|
21
|
+
if (electronEnv.currentWindowId === payload.windowId) {
|
|
22
|
+
this.openerService.open(payload.url);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Injector, Autowired, INJECTOR_TOKEN } from '@opensumi/di';
|
|
2
2
|
import { Domain, ContributionProvider } from '@opensumi/ide-core-common';
|
|
3
|
-
import { IElectronRendererURLService, IElectronURLService } from '@opensumi/ide-core-common/lib/electron';
|
|
4
3
|
|
|
5
4
|
import { ClientAppContribution } from '../common/common.define';
|
|
6
5
|
import { AppConfig } from '../react-providers/config-provider';
|
|
7
|
-
import { electronEnv } from '../utils/electron';
|
|
8
6
|
|
|
9
7
|
import { CommandOpener } from './command-opener';
|
|
10
8
|
import { HttpOpener } from './http-opener';
|
|
@@ -44,14 +42,5 @@ export class OpenerContributionClient implements ClientAppContribution {
|
|
|
44
42
|
for (const contribution of contributions) {
|
|
45
43
|
contribution.registerOpener(this.openerService);
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
if (this.appConfig.isElectronRenderer) {
|
|
49
|
-
const electronRendererURLService: IElectronRendererURLService = this.injector.get(IElectronURLService);
|
|
50
|
-
electronRendererURLService.on('open-url', (payload) => {
|
|
51
|
-
if (electronEnv.currentWindowId === payload.windowId) {
|
|
52
|
-
this.openerService.open(payload.url);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
45
|
}
|
|
57
46
|
}
|
|
@@ -48,9 +48,14 @@ export function getPreferenceIconThemeId(): string {
|
|
|
48
48
|
export function getPreferenceLanguageId(defaultPreferences?: IPreferences): string {
|
|
49
49
|
// 默认从配置项中获取语言选项,其次从默认配置项中获取 `general.language`, 默认为 `en-US`
|
|
50
50
|
const langFromDefaultPreferences = defaultPreferences && defaultPreferences[GeneralSettingsId.Language];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const langExternalPreference = getExternalPreference<string>(GeneralSettingsId.Language);
|
|
52
|
+
|
|
53
|
+
// 用户自定义语言设置优先于默认设置
|
|
54
|
+
if (langExternalPreference.value && langExternalPreference.scope > PreferenceScope.Default) {
|
|
55
|
+
return langExternalPreference.value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return langFromDefaultPreferences || langExternalPreference.value || getLanguageId();
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
// 默认使用 localStorage
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import { ContributionProvider } from '@opensumi/ide-core-common/lib/contribution-provider';
|
|
3
|
+
import { Domain } from '@opensumi/ide-core-common/lib/di-helper/index';
|
|
4
|
+
|
|
5
|
+
import { ClientAppContribution } from '../common/common.define';
|
|
6
|
+
|
|
7
|
+
import { StaticResourceService, StaticResourceContribution } from './static.definition';
|
|
8
|
+
|
|
9
|
+
export * from './static.definition';
|
|
10
|
+
|
|
11
|
+
@Domain(ClientAppContribution)
|
|
12
|
+
export class StaticResourceClientAppContribution implements ClientAppContribution {
|
|
13
|
+
@Autowired()
|
|
14
|
+
private readonly staticResourceService: StaticResourceService;
|
|
15
|
+
|
|
16
|
+
@Autowired(StaticResourceContribution)
|
|
17
|
+
private readonly contributions: ContributionProvider<StaticResourceContribution>;
|
|
18
|
+
|
|
19
|
+
initialize() {
|
|
20
|
+
for (const contribution of this.contributions.getContributions()) {
|
|
21
|
+
contribution.registerStaticResolver(this.staticResourceService);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { IDisposable, URI } from '@opensumi/ide-core-common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @class StaticResourceService 静态资源转换服务
|
|
6
|
+
* @description
|
|
7
|
+
* 对于一些静态资源的展示,如图片,插件中的资源等等,在IDE中往往会以类似File协议的uri进行描述。
|
|
8
|
+
*
|
|
9
|
+
* 在WebIDE环境,我们无法将它直接挂载在对应的html标签或者css中。
|
|
10
|
+
* 因此在使用之前,需要将这些资源的URI转换为浏览器可以访问的资源。
|
|
11
|
+
*
|
|
12
|
+
* 在Electron中,由于File协议能直接访问,一般来说无需注册资源地址转换。
|
|
13
|
+
*/
|
|
14
|
+
@Injectable()
|
|
15
|
+
export abstract class StaticResourceService {
|
|
16
|
+
/**
|
|
17
|
+
* 注册一个静态资源转换方式的提供方
|
|
18
|
+
* @param provider
|
|
19
|
+
*/
|
|
20
|
+
public abstract registerStaticResourceProvider(provider: IStaticResourceProvider): IDisposable;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 将URI资源转换为静态资源
|
|
24
|
+
* 通常比如在WebIDE场景, 会将插件的file://路径,转换为某个静态服务的uri进行访问
|
|
25
|
+
* @param uri 待转换的uri
|
|
26
|
+
* @returns 转换后的uri
|
|
27
|
+
*/
|
|
28
|
+
public abstract resolveStaticResource(uri: URI): URI;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 被转换后的uri将会拥有哪些host,
|
|
32
|
+
* 用于webview的cspResource字段,
|
|
33
|
+
* webview需要能够知道什么样的资源是可以被访问的。
|
|
34
|
+
*
|
|
35
|
+
* 例: ['http://127.0.0.1:8000']
|
|
36
|
+
*/
|
|
37
|
+
public readonly resourceRoots: Set<string>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @interface 提供静态资源转换方式的提供方
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export interface IStaticResourceProvider {
|
|
45
|
+
/**
|
|
46
|
+
* 能够处理的scheme,单个scheme只能有一个StaticResourceProvider, 先来的会被后来的覆盖
|
|
47
|
+
*/
|
|
48
|
+
scheme: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 定义如何处理uri的转换
|
|
52
|
+
* @param uri 待转换的uri
|
|
53
|
+
*/
|
|
54
|
+
resolveStaticResource(uri: URI): URI;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* resolve后提供的外部资源的host路径, 会传入StaticResourceService的resourceRoots中
|
|
58
|
+
*
|
|
59
|
+
* 例: ['http://0.0.0.0:8000']
|
|
60
|
+
*/
|
|
61
|
+
roots?: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const StaticResourceContribution = Symbol('StaticResourceContribution');
|
|
65
|
+
|
|
66
|
+
export const StaticResourceContributionProvider = Symbol('StaticResourceContributionProvider');
|
|
67
|
+
|
|
68
|
+
export interface StaticResourceContribution {
|
|
69
|
+
registerStaticResolver(service: StaticResourceService): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { URI } from '@opensumi/ide-core-common';
|
|
3
|
+
|
|
4
|
+
import { StaticResourceService, IStaticResourceProvider } from './static.definition';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class StaticResourceServiceImpl implements StaticResourceService {
|
|
8
|
+
private providers = new Map<string, IStaticResourceProvider>();
|
|
9
|
+
|
|
10
|
+
public readonly resourceRoots: Set<string> = new Set();
|
|
11
|
+
|
|
12
|
+
public registerStaticResourceProvider(provider: IStaticResourceProvider) {
|
|
13
|
+
this.providers.set(provider.scheme, provider);
|
|
14
|
+
if (provider.roots) {
|
|
15
|
+
provider.roots.forEach((root) => {
|
|
16
|
+
this.resourceRoots.add(root);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
dispose: () => {
|
|
21
|
+
if (this.providers.get(provider.scheme) === provider) {
|
|
22
|
+
this.providers.delete(provider.scheme);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public resolveStaticResource(uri: URI): URI {
|
|
29
|
+
if (!this.providers.has(uri.scheme)) {
|
|
30
|
+
return uri;
|
|
31
|
+
}
|
|
32
|
+
const url = this.providers.get(uri.scheme)!.resolveStaticResource(uri);
|
|
33
|
+
// vscode-url path的 = 会被转码,先手动跳过转码
|
|
34
|
+
url.toString = url.toString.bind(url, true);
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/utils/env.ts
CHANGED
|
@@ -5,7 +5,7 @@ export function getElectronEnv(): any {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @deprecated useNativeTopMenu will
|
|
8
|
+
* @deprecated useNativeTopMenu will be removed in v2.26, please use appConfig#isElectronRenderer instead.
|
|
9
9
|
*/
|
|
10
10
|
export function useNativeTopMenu() {
|
|
11
11
|
if (isElectronRenderer()) {
|
|
@@ -19,7 +19,7 @@ export function useNativeTopMenu() {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* @deprecated useNativeContextMenu will
|
|
22
|
+
* @deprecated useNativeContextMenu will be removed in v2.26, please use appConfig#isElectronRenderer instead.
|
|
23
23
|
*/
|
|
24
24
|
export function useNativeContextMenu() {
|
|
25
25
|
if (isElectronRenderer()) {
|