@opensumi/ide-core-common 2.21.13 → 2.22.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/command.d.ts +15 -5
- package/lib/command.d.ts.map +1 -1
- package/lib/command.js +11 -1
- package/lib/command.js.map +1 -1
- package/lib/const/application.d.ts +6 -1
- package/lib/const/application.d.ts.map +1 -1
- package/lib/const/application.js +8 -3
- package/lib/const/application.js.map +1 -1
- package/lib/declare.d.ts +2 -2
- package/lib/declare.d.ts.map +1 -1
- package/lib/editor.d.ts +4 -0
- package/lib/editor.d.ts.map +1 -1
- package/lib/electron.d.ts +1 -1
- package/lib/electron.d.ts.map +1 -1
- package/lib/event-bus/event-bus-types.d.ts +1 -1
- package/lib/event-bus/event-bus-types.d.ts.map +1 -1
- package/lib/event-bus/event-bus.js.map +1 -1
- package/lib/event-bus/event-decorator.js.map +1 -1
- package/lib/extension.schema.d.ts +1 -1
- package/lib/extension.schema.d.ts.map +1 -1
- package/lib/hash-calculate/WASMInterface.d.ts +2 -2
- package/lib/hash-calculate/WASMInterface.d.ts.map +1 -1
- package/lib/hash-calculate/hash-calculate.js.map +1 -1
- package/lib/hash-calculate/util.d.ts +2 -2
- package/lib/hash-calculate/util.d.ts.map +1 -1
- package/lib/json-schema.d.ts +9 -0
- package/lib/json-schema.d.ts.map +1 -1
- package/lib/keyboard/keymap.d.ts +1 -1
- package/lib/keyboard/keymap.d.ts.map +1 -1
- package/lib/localize.d.ts +1 -1
- package/lib/localize.d.ts.map +1 -1
- package/lib/log.d.ts +2 -2
- package/lib/log.d.ts.map +1 -1
- package/lib/mime.d.ts +6 -6
- package/lib/module.js.map +1 -1
- package/lib/preferences/preference-schema.d.ts +13 -3
- package/lib/preferences/preference-schema.d.ts.map +1 -1
- package/lib/preferences/preference-schema.js +11 -1
- package/lib/preferences/preference-schema.js.map +1 -1
- package/lib/preferences/preference-scope.d.ts +8 -1
- package/lib/preferences/preference-scope.d.ts.map +1 -1
- package/lib/preferences/preference-scope.js +11 -2
- package/lib/preferences/preference-scope.js.map +1 -1
- package/lib/problem-matcher.d.ts +1 -1
- package/lib/problem-matcher.d.ts.map +1 -1
- package/lib/problem-matcher.js.map +1 -1
- package/lib/problem-pattern.d.ts +4 -2
- package/lib/problem-pattern.d.ts.map +1 -1
- package/lib/problem-pattern.js +24 -1
- package/lib/problem-pattern.js.map +1 -1
- package/lib/reference.d.ts +2 -1
- package/lib/reference.d.ts.map +1 -1
- package/lib/reference.js +11 -6
- package/lib/reference.js.map +1 -1
- package/lib/reporter.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js.map +1 -1
- package/lib/task-definition.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/common.d.ts.map +1 -1
- package/lib/types/editor.d.ts +2 -2
- package/lib/types/editor.d.ts.map +1 -1
- package/lib/types/file-watch.d.ts +1 -1
- package/lib/types/file-watch.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.js +4 -10
- package/lib/types/markers/markers-manager.js.map +1 -1
- package/lib/types/markers/markers.d.ts +2 -0
- package/lib/types/markers/markers.d.ts.map +1 -1
- package/lib/types/markers/markers.js.map +1 -1
- package/package.json +7 -6
- package/src/LifeCyclePhase.ts +6 -0
- package/src/application-error.ts +77 -0
- package/src/application-props.ts +28 -0
- package/src/application.lifecycle.ts +15 -0
- package/src/browser-fs/ensure-dir.ts +46 -0
- package/src/browser-fs/util.ts +52 -0
- package/src/clipboard.ts +31 -0
- package/src/command.ts +726 -0
- package/src/commands/terminal.ts +0 -0
- package/src/comparers.ts +152 -0
- package/src/connection.ts +7 -0
- package/src/const/application.ts +11 -0
- package/src/const/index.ts +1 -0
- package/src/contribution-provider.ts +47 -0
- package/src/credential.ts +21 -0
- package/src/crypto.ts +8 -0
- package/src/declare.ts +3 -0
- package/src/di-helper/domain-helper.ts +48 -0
- package/src/di-helper/index.ts +1 -0
- package/src/editor.ts +6 -0
- package/src/electron.ts +168 -0
- package/src/env.ts +1 -0
- package/src/event-bus/basic-event.ts +3 -0
- package/src/event-bus/event-bus-types.ts +68 -0
- package/src/event-bus/event-bus.ts +57 -0
- package/src/event-bus/event-decorator.ts +32 -0
- package/src/event-bus/index.ts +4 -0
- package/src/extension.schema.ts +16 -0
- package/src/hash-calculate/WASMInterface.ts +266 -0
- package/src/hash-calculate/hash-calculate.ts +53 -0
- package/src/hash-calculate/lockedCreate.ts +17 -0
- package/src/hash-calculate/md5.wasm.json +1 -0
- package/src/hash-calculate/mutex.ts +30 -0
- package/src/hash-calculate/util.ts +190 -0
- package/src/id-generator.ts +15 -0
- package/src/index.ts +39 -0
- package/src/json-schema.ts +80 -0
- package/src/keyboard/index.ts +2 -0
- package/src/keyboard/keyboard-layout-provider.ts +46 -0
- package/src/keyboard/keymap.ts +224 -0
- package/src/line-text.ts +93 -0
- package/src/localize.ts +203 -0
- package/src/log.ts +338 -0
- package/src/markdown.ts +8 -0
- package/src/menu.ts +31 -0
- package/src/mime.ts +8 -0
- package/src/mocks/electron/browserMock.ts +10 -0
- package/src/mocks/electron/ipcRenderer.ts +30 -0
- package/src/module.ts +31 -0
- package/src/network.ts +47 -0
- package/src/node/cli.ts +5 -0
- package/src/node/port.ts +134 -0
- package/src/preferences/index.ts +2 -0
- package/src/preferences/preference-schema.ts +122 -0
- package/src/preferences/preference-scope.ts +65 -0
- package/src/problem-matcher.ts +389 -0
- package/src/problem-pattern.ts +574 -0
- package/src/range.ts +24 -0
- package/src/reference.ts +141 -0
- package/src/reporter.ts +64 -0
- package/src/settings/general.ts +5 -0
- package/src/settings/index.ts +3 -0
- package/src/settings/search.ts +7 -0
- package/src/settings/terminal.ts +9 -0
- package/src/storage.ts +99 -0
- package/src/task-definition.ts +172 -0
- package/src/theme.ts +7 -0
- package/src/types/accessibility.ts +4 -0
- package/src/types/application.ts +14 -0
- package/src/types/authentication.ts +120 -0
- package/src/types/common.ts +14 -0
- package/src/types/dnd.ts +8 -0
- package/src/types/editor.ts +246 -0
- package/src/types/extension.ts +96 -0
- package/src/types/file-watch.ts +100 -0
- package/src/types/file.ts +262 -0
- package/src/types/index.ts +15 -0
- package/src/types/markdown.ts +10 -0
- package/src/types/markers/index.ts +2 -0
- package/src/types/markers/markers-manager.ts +392 -0
- package/src/types/markers/markers.ts +125 -0
- package/src/types/message.ts +6 -0
- package/src/types/reporter.ts +96 -0
- package/src/types/statusbar.ts +6 -0
- package/src/types/string.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/ipc.ts +28 -0
package/src/log.ts
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Event } from '@opensumi/ide-utils';
|
|
3
|
+
|
|
4
|
+
export enum LogLevel {
|
|
5
|
+
Verbose,
|
|
6
|
+
Debug,
|
|
7
|
+
Info,
|
|
8
|
+
Warning,
|
|
9
|
+
Error,
|
|
10
|
+
Critical,
|
|
11
|
+
Off,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum SupportLogNamespace {
|
|
15
|
+
// 主进程
|
|
16
|
+
Main = 'main',
|
|
17
|
+
// 渲染进程
|
|
18
|
+
Render = 'render',
|
|
19
|
+
// Node进程
|
|
20
|
+
Node = 'node',
|
|
21
|
+
// 浏览器进程
|
|
22
|
+
Browser = 'browser',
|
|
23
|
+
// 插件进程
|
|
24
|
+
ExtensionHost = 'extHost',
|
|
25
|
+
// 应用层
|
|
26
|
+
App = 'app',
|
|
27
|
+
// 其他未分类
|
|
28
|
+
OTHER = 'other',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ICoreLogger {
|
|
32
|
+
verbose(...args: any[]): void;
|
|
33
|
+
debug(...args: any[]): void;
|
|
34
|
+
log(...args: any[]): void;
|
|
35
|
+
warn(...args: any[]): void;
|
|
36
|
+
error(...args: any[]): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface BaseLogServiceOptions {
|
|
40
|
+
/**
|
|
41
|
+
* 对应存储日志的文件名
|
|
42
|
+
*/
|
|
43
|
+
namespace?: string;
|
|
44
|
+
/**
|
|
45
|
+
* 设置落盘级别,默认 LogLevel.Info
|
|
46
|
+
*/
|
|
47
|
+
logLevel?: LogLevel;
|
|
48
|
+
/**
|
|
49
|
+
* 进程的PID,会作为日志内容的前缀
|
|
50
|
+
*/
|
|
51
|
+
pid?: number;
|
|
52
|
+
/**
|
|
53
|
+
* 落盘日志的存储文件夹
|
|
54
|
+
* 例如: ~/.sumi/logs/20180909/
|
|
55
|
+
*/
|
|
56
|
+
logDir?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ILogServiceOptions extends BaseLogServiceOptions {
|
|
60
|
+
logServiceManager: ILogServiceManager;
|
|
61
|
+
namespace: string;
|
|
62
|
+
logLevel?: LogLevel;
|
|
63
|
+
pid?: number;
|
|
64
|
+
isShowConsoleLog?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Archive {
|
|
68
|
+
/**
|
|
69
|
+
* 将压缩的zip文件,写入流;通过该方法可以将zip文件写入本地或上传服务器
|
|
70
|
+
* @param writeStream fs.WriteStream
|
|
71
|
+
*/
|
|
72
|
+
pipe(writeStream: any);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const ILogServiceManager = Symbol('ILogServiceManager');
|
|
76
|
+
export interface ILogServiceManager {
|
|
77
|
+
onDidChangeLogLevel: Event<LogLevel>;
|
|
78
|
+
|
|
79
|
+
getLogger(namespace: SupportLogNamespace, loggerOptions?: BaseLogServiceOptions): ILogService;
|
|
80
|
+
getGlobalLogLevel(): LogLevel;
|
|
81
|
+
removeLogger(namespace: SupportLogNamespace);
|
|
82
|
+
setGlobalLogLevel(level: LogLevel);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 返回当前日志存放的目录
|
|
86
|
+
*/
|
|
87
|
+
getLogFolder(): string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 返回保存日志的根目录,为 getLogFolder() 的父目录
|
|
91
|
+
*/
|
|
92
|
+
getRootLogFolder(): string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 清理 getRootLogFolder() 中最近5天前的日志,仅保留最近5天日志
|
|
96
|
+
*/
|
|
97
|
+
cleanOldLogs(): Promise<void>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 清理 getRootLogFolder() 中的所有日志
|
|
101
|
+
*/
|
|
102
|
+
cleanAllLogs(): Promise<void>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 清理 day 之前的日志目录
|
|
106
|
+
* @param day --格式为: 20190807
|
|
107
|
+
*/
|
|
108
|
+
cleanExpiredLogs(day: number): Promise<void>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param day --格式为: 20190807
|
|
112
|
+
*/
|
|
113
|
+
getLogZipArchiveByDay(day: number): Promise<Archive>;
|
|
114
|
+
|
|
115
|
+
getLogZipArchiveByFolder(foldPath: string): Promise<Archive>;
|
|
116
|
+
|
|
117
|
+
dispose();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface IBaseLogService extends ICoreLogger {
|
|
121
|
+
/**
|
|
122
|
+
* 获取当前的log level
|
|
123
|
+
*/
|
|
124
|
+
getLevel(): LogLevel;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 设置 log level
|
|
128
|
+
*/
|
|
129
|
+
setLevel(level: LogLevel): void;
|
|
130
|
+
critical(...args: any[]): void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 直接发送log 消息,在此函数内部分发到上面的 log、error方法
|
|
134
|
+
* @param level
|
|
135
|
+
* @param message
|
|
136
|
+
*/
|
|
137
|
+
sendLog(level: LogLevel, message: string): void;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 释放spdlog对象
|
|
141
|
+
*/
|
|
142
|
+
drop(): Promise<void>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 立即写入数据
|
|
146
|
+
*/
|
|
147
|
+
flush(): Promise<void>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 销毁当前实例
|
|
151
|
+
*/
|
|
152
|
+
dispose(): void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface ILogService extends IBaseLogService {
|
|
156
|
+
/**
|
|
157
|
+
* 设置 logger 信息,用于初始化后,更新 logger 设置
|
|
158
|
+
*/
|
|
159
|
+
setOptions(options: BaseLogServiceOptions);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const LogServiceForClientPath = 'LogServiceForClientPath';
|
|
163
|
+
|
|
164
|
+
export interface ILogServiceClient extends ICoreLogger {
|
|
165
|
+
getLevel(): Promise<LogLevel>;
|
|
166
|
+
setLevel(level: LogLevel): Promise<void>;
|
|
167
|
+
critical(...args: any[]): void;
|
|
168
|
+
dispose(): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type IExtensionLogger = ICoreLogger;
|
|
172
|
+
|
|
173
|
+
export const ILoggerManagerClient = Symbol('ILoggerManagerClient');
|
|
174
|
+
export interface ILoggerManagerClient {
|
|
175
|
+
onDidChangeLogLevel: Event<LogLevel>;
|
|
176
|
+
getLogger(namespace: SupportLogNamespace, pid?: number): ILogServiceClient;
|
|
177
|
+
|
|
178
|
+
setGlobalLogLevel(level: LogLevel): Promise<void>;
|
|
179
|
+
getGlobalLogLevel(): Promise<LogLevel>;
|
|
180
|
+
|
|
181
|
+
onDidLogLevelChanged(level: LogLevel);
|
|
182
|
+
dispose(): Promise<void>;
|
|
183
|
+
getLogFolder(): Promise<string>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* DebugLog
|
|
188
|
+
*/
|
|
189
|
+
export interface IDebugLog extends ICoreLogger {
|
|
190
|
+
info(...args: any[]): void;
|
|
191
|
+
|
|
192
|
+
destroy(): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 只输出在控制台,不会落盘
|
|
197
|
+
* const debugLog = new DebugLog('FileService');
|
|
198
|
+
*
|
|
199
|
+
* @export
|
|
200
|
+
* @class DebugLog
|
|
201
|
+
* @implements {IDebugLog}
|
|
202
|
+
*/
|
|
203
|
+
const isNode = typeof process !== 'undefined' && process.release;
|
|
204
|
+
const isChrome = !isNode && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
|
205
|
+
export class DebugLog implements IDebugLog {
|
|
206
|
+
private namespace: string;
|
|
207
|
+
private isEnable = false;
|
|
208
|
+
|
|
209
|
+
constructor(namespace?: string) {
|
|
210
|
+
if (typeof process !== 'undefined' && process.env && process.env.KTLOG_SHOW_DEBUG) {
|
|
211
|
+
this.isEnable = true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.namespace = namespace || '';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private getPre(level: string, color: string) {
|
|
218
|
+
const text = this.namespace ? `[${this.namespace}:${level}]` : `[${level}]`;
|
|
219
|
+
return this.getColor(color, text);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private getColor(color: string, message: string) {
|
|
223
|
+
if (!isNode && !isChrome) {
|
|
224
|
+
return message;
|
|
225
|
+
}
|
|
226
|
+
const colors = {
|
|
227
|
+
reset: '\x1b[0m',
|
|
228
|
+
|
|
229
|
+
// text color
|
|
230
|
+
|
|
231
|
+
black: '\x1b[30m',
|
|
232
|
+
red: '\x1b[31m',
|
|
233
|
+
green: '\x1b[32m',
|
|
234
|
+
yellow: '\x1b3[33m',
|
|
235
|
+
blue: '\x1b[34m',
|
|
236
|
+
magenta: '\x1b[35m',
|
|
237
|
+
cyan: '\x1b[36m',
|
|
238
|
+
white: '\x1b[37m',
|
|
239
|
+
|
|
240
|
+
// background color
|
|
241
|
+
|
|
242
|
+
blackBg: '\x1b[40m',
|
|
243
|
+
redBg: '\x1b[41m',
|
|
244
|
+
greenBg: '\x1b[42m',
|
|
245
|
+
yellowBg: '\x1b[43m',
|
|
246
|
+
blueBg: '\x1b[44m',
|
|
247
|
+
magentaBg: '\x1b[45m',
|
|
248
|
+
cyanBg: '\x1b[46m',
|
|
249
|
+
whiteBg: '\x1b[47m',
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
return (colors[color] || '') + message + colors.reset;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
verbose = (...args: any[]) => {
|
|
256
|
+
if (!this.isEnable) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
return console.debug(this.getPre('verbose', 'green'), ...args);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
debug = (...args: any[]) => {
|
|
263
|
+
if (!this.isEnable) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
return console.debug(this.getPre('debug', 'blue'), ...args);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
log = (...args: any[]) => {
|
|
270
|
+
if (!this.isEnable) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
return console.log(this.getPre('log', 'green'), ...args);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
error = (...args: any[]) =>
|
|
277
|
+
// 错误一直显示
|
|
278
|
+
console.error(this.getPre('error', 'red'), ...args);
|
|
279
|
+
|
|
280
|
+
warn = (...args: any[]) => {
|
|
281
|
+
if (!this.isEnable) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
return console.warn(this.getPre('warn', 'yellow'), ...args);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
info = (...args: any[]) => {
|
|
288
|
+
if (!this.isEnable) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
return console.info(this.getPre('log', 'green'), ...args);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
destroy() {}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 兼容旧logger 提供的类型,同 ILogServiceClient
|
|
299
|
+
*/
|
|
300
|
+
export const ILogger = Symbol('ILogger');
|
|
301
|
+
export type ILogger = ILogServiceClient;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 只输出在控制台,不会落盘
|
|
305
|
+
*/
|
|
306
|
+
export function getDebugLogger(namespace?: string): IDebugLog {
|
|
307
|
+
function showWarn() {
|
|
308
|
+
// Do nothing
|
|
309
|
+
}
|
|
310
|
+
const debugLog = new DebugLog(namespace);
|
|
311
|
+
return {
|
|
312
|
+
get verbose() {
|
|
313
|
+
showWarn();
|
|
314
|
+
return debugLog.verbose;
|
|
315
|
+
},
|
|
316
|
+
get log() {
|
|
317
|
+
showWarn();
|
|
318
|
+
return debugLog.log;
|
|
319
|
+
},
|
|
320
|
+
get debug() {
|
|
321
|
+
showWarn();
|
|
322
|
+
return debugLog.debug;
|
|
323
|
+
},
|
|
324
|
+
get error() {
|
|
325
|
+
showWarn();
|
|
326
|
+
return debugLog.error;
|
|
327
|
+
},
|
|
328
|
+
get info() {
|
|
329
|
+
showWarn();
|
|
330
|
+
return debugLog.info;
|
|
331
|
+
},
|
|
332
|
+
get warn() {
|
|
333
|
+
showWarn();
|
|
334
|
+
return debugLog.warn;
|
|
335
|
+
},
|
|
336
|
+
destroy() {},
|
|
337
|
+
};
|
|
338
|
+
}
|
package/src/markdown.ts
ADDED
package/src/menu.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IDisposable } from '@opensumi/ide-utils';
|
|
2
|
+
|
|
3
|
+
import { IElectronMainApi } from './electron';
|
|
4
|
+
|
|
5
|
+
export interface INativeMenuTemplate {
|
|
6
|
+
id?: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
type?: 'separator' | 'checkbox';
|
|
9
|
+
submenu?: INativeMenuTemplate[];
|
|
10
|
+
accelerator?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
action?: boolean;
|
|
14
|
+
role?: string;
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IElectronMainMenuService extends IElectronMainApi<'menuClick' | 'menuClose'> {
|
|
19
|
+
showContextMenu(template: INativeMenuTemplate, webContentsId: number): Promise<void>;
|
|
20
|
+
setApplicationMenu(template: INativeMenuTemplate, windowId: number): Promise<void>;
|
|
21
|
+
on(event: 'menuClick', listener: (targetId: string, menuId: string) => void): IDisposable;
|
|
22
|
+
on(event: 'menuClose', listener: (targetId: string, contextMenuId: string) => void): IDisposable;
|
|
23
|
+
runNativeRoleAction(actionName: string): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const IElectronMainMenuService = 'IElectronMainMenuService';
|
|
27
|
+
|
|
28
|
+
export interface ISumiMenuExtendInfo {
|
|
29
|
+
command: string;
|
|
30
|
+
extraDesc?: string;
|
|
31
|
+
}
|
package/src/mime.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MockedElectronIpcRenderer } from './ipcRenderer';
|
|
2
|
+
|
|
3
|
+
export function mockElectronRenderer() {
|
|
4
|
+
const mockedElectronIpcRenderer = new MockedElectronIpcRenderer();
|
|
5
|
+
jest.mock('electron', () => ({
|
|
6
|
+
ipcRenderer: mockedElectronIpcRenderer,
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
(global as any).ipcRenderer = mockedElectronIpcRenderer;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
export class MockedElectronIpcRenderer extends EventEmitter implements Electron.IpcRenderer {
|
|
4
|
+
invoke(channel: string, ...args: any[]): Promise<any> {
|
|
5
|
+
throw new Error('Method not implemented.');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
eventNames() {
|
|
9
|
+
return super.eventNames().map((s) => s.toString());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public targetHost: EventEmitter = new EventEmitter();
|
|
13
|
+
|
|
14
|
+
send(channel: string, ...args: any[]): void {
|
|
15
|
+
this.targetHost.emit('send', { channel }, args);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
sendSync(channel: string, ...args: any[]) {
|
|
19
|
+
this.targetHost.emit('sendSync', { channel }, args);
|
|
20
|
+
}
|
|
21
|
+
sendTo(webContentsId: number, channel: string, ...args: any[]): void {
|
|
22
|
+
this.targetHost.emit('sendTo', { webContentsId, channel }, args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
sendToHost(channel: string, ...args: any[]): void {
|
|
26
|
+
this.targetHost.emit('sendToHost', channel, ...args);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
postMessage(channel: string, message: any, transfer?: MessagePort[]): void {}
|
|
30
|
+
}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目中会使用到的模块接口定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Autowired, INJECTOR_TOKEN, Injector, Provider, ConstructorOf, Token, Domain } from '@opensumi/di';
|
|
6
|
+
|
|
7
|
+
interface FrontService {
|
|
8
|
+
token: Token;
|
|
9
|
+
servicePath: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BackService {
|
|
13
|
+
token?: Token;
|
|
14
|
+
clientToken?: Token;
|
|
15
|
+
servicePath: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class BasicModule {
|
|
19
|
+
@Autowired(INJECTOR_TOKEN)
|
|
20
|
+
protected injector: Injector;
|
|
21
|
+
providers?: Provider[];
|
|
22
|
+
backServices?: BackService[];
|
|
23
|
+
frontServices?: FrontService[];
|
|
24
|
+
contributionProvider: Domain | Domain[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ModuleDependencies<T extends BasicModule>(dependencies: ConstructorOf<BasicModule>[]) {
|
|
28
|
+
return (target) => {
|
|
29
|
+
Reflect.defineMetadata('dependencies', dependencies, target);
|
|
30
|
+
};
|
|
31
|
+
}
|
package/src/network.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export namespace Schemes {
|
|
2
|
+
/**
|
|
3
|
+
* A schema that is used for models that exist in memory
|
|
4
|
+
* only and that have no correspondence on a server or such.
|
|
5
|
+
*/
|
|
6
|
+
export const inMemory = 'inmemory';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A schema that is used for setting files
|
|
10
|
+
*/
|
|
11
|
+
export const vscode = 'vscode';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A schema that is used for internal private files
|
|
15
|
+
*/
|
|
16
|
+
export const internal = 'private';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A walk-through document.
|
|
20
|
+
*/
|
|
21
|
+
export const walkThrough = 'walkThrough';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An embedded code snippet.
|
|
25
|
+
*/
|
|
26
|
+
export const walkThroughSnippet = 'walkThroughSnippet';
|
|
27
|
+
|
|
28
|
+
export const http = 'http';
|
|
29
|
+
|
|
30
|
+
export const https = 'https';
|
|
31
|
+
|
|
32
|
+
export const file = 'file';
|
|
33
|
+
|
|
34
|
+
export const mailto = 'mailto';
|
|
35
|
+
|
|
36
|
+
export const untitled = 'untitled';
|
|
37
|
+
|
|
38
|
+
export const data = 'data';
|
|
39
|
+
|
|
40
|
+
export const command = 'command';
|
|
41
|
+
|
|
42
|
+
export const vscodeRemote = 'vscode-remote';
|
|
43
|
+
|
|
44
|
+
export const userData = 'vscode-userdata';
|
|
45
|
+
|
|
46
|
+
export const userStorage = 'user_storage';
|
|
47
|
+
}
|
package/src/node/cli.ts
ADDED
package/src/node/port.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* ---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
// Some code copied and modified from https://github.com/microsoft/vscode/blob/1.44.0/src/vs/base/node/ports.ts
|
|
6
|
+
|
|
7
|
+
import net from 'net';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @returns Returns a random port between 1025 and 65535.
|
|
11
|
+
*/
|
|
12
|
+
export function randomPort(): number {
|
|
13
|
+
const min = 1025;
|
|
14
|
+
const max = 65535;
|
|
15
|
+
return min + Math.floor((max - min) * Math.random());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const defaultHost = process.env.HOST || '127.0.0.1';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Given a start point and a max number of retries, will find a port that
|
|
22
|
+
* is openable. Will return 0 in case no free port can be found.
|
|
23
|
+
*/
|
|
24
|
+
export function findFreePort(startPort: number, giveUpAfter: number, timeout: number): Promise<number> {
|
|
25
|
+
let done = false;
|
|
26
|
+
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const timeoutHandle = setTimeout(() => {
|
|
29
|
+
if (!done) {
|
|
30
|
+
done = true;
|
|
31
|
+
return resolve(0);
|
|
32
|
+
}
|
|
33
|
+
}, timeout);
|
|
34
|
+
|
|
35
|
+
doFindFreePort(startPort, giveUpAfter, (port) => {
|
|
36
|
+
if (!done) {
|
|
37
|
+
done = true;
|
|
38
|
+
clearTimeout(timeoutHandle);
|
|
39
|
+
return resolve(port);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function doFindFreePort(startPort: number, giveUpAfter: number, clb: (port: number) => void): void {
|
|
46
|
+
if (giveUpAfter === 0) {
|
|
47
|
+
return clb(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const client = new net.Socket();
|
|
51
|
+
|
|
52
|
+
// If we can connect to the port it means the port is already taken so we continue searching
|
|
53
|
+
client.once('connect', () => {
|
|
54
|
+
dispose(client);
|
|
55
|
+
|
|
56
|
+
return doFindFreePort(startPort + 1, giveUpAfter - 1, clb);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
client.once('data', () => {
|
|
60
|
+
// this listener is required since node.js 8.x
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
client.once('error', (err: Error & { code?: string }) => {
|
|
64
|
+
dispose(client);
|
|
65
|
+
|
|
66
|
+
// If we receive any non ECONNREFUSED error, it means the port is used but we cannot connect
|
|
67
|
+
if (err.code !== 'ECONNREFUSED') {
|
|
68
|
+
return doFindFreePort(startPort + 1, giveUpAfter - 1, clb);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Otherwise it means the port is free to use!
|
|
72
|
+
return clb(startPort);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
client.connect(startPort, defaultHost);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Uses listen instead of connect. Is faster, but if there is another listener on 127.0.0.1 then this will take 127.0.0.1 from that listener.
|
|
80
|
+
*/
|
|
81
|
+
export function findFreePortFaster(startPort: number, giveUpAfter: number, timeout: number): Promise<number> {
|
|
82
|
+
let resolved = false;
|
|
83
|
+
let timeoutHandle: NodeJS.Timeout | undefined;
|
|
84
|
+
let countTried = 1;
|
|
85
|
+
const server = net.createServer({ pauseOnConnect: true });
|
|
86
|
+
function doResolve(port: number, resolve: (port: number) => void) {
|
|
87
|
+
if (!resolved) {
|
|
88
|
+
resolved = true;
|
|
89
|
+
server.removeAllListeners();
|
|
90
|
+
server.close();
|
|
91
|
+
if (timeoutHandle) {
|
|
92
|
+
clearTimeout(timeoutHandle);
|
|
93
|
+
}
|
|
94
|
+
resolve(port);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return new Promise<number>((resolve) => {
|
|
98
|
+
// 使用 global.setTimeout 消除歧义,减少测试问题
|
|
99
|
+
// ref: https://github.com/Microsoft/TypeScript/issues/30128#issuecomment-467968688
|
|
100
|
+
timeoutHandle = global.setTimeout(() => {
|
|
101
|
+
doResolve(0, resolve);
|
|
102
|
+
}, timeout);
|
|
103
|
+
|
|
104
|
+
server.on('listening', () => {
|
|
105
|
+
doResolve(startPort, resolve);
|
|
106
|
+
});
|
|
107
|
+
server.on('error', (err) => {
|
|
108
|
+
if (err && ((err as any).code === 'EADDRINUSE' || (err as any).code === 'EACCES') && countTried < giveUpAfter) {
|
|
109
|
+
startPort++;
|
|
110
|
+
countTried++;
|
|
111
|
+
server.listen(startPort, defaultHost);
|
|
112
|
+
} else {
|
|
113
|
+
doResolve(0, resolve);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
server.on('close', () => {
|
|
117
|
+
doResolve(0, resolve);
|
|
118
|
+
});
|
|
119
|
+
server.listen(startPort, defaultHost);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function dispose(socket: net.Socket): void {
|
|
124
|
+
try {
|
|
125
|
+
socket.removeAllListeners('connect');
|
|
126
|
+
socket.removeAllListeners('error');
|
|
127
|
+
socket.end();
|
|
128
|
+
socket.destroy();
|
|
129
|
+
socket.unref();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
// eslint-disable-next-line no-console
|
|
132
|
+
console.error(error); // otherwise this error would get lost in the callback chain
|
|
133
|
+
}
|
|
134
|
+
}
|