Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
330901dd
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,发现更多精彩内容 >>
提交
330901dd
编写于
3月 01, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
run shared process in a browser window
上级
b518405b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
193 addition
and
42 deletion
+193
-42
src/vs/code/electron-browser/sharedProcess.html
src/vs/code/electron-browser/sharedProcess.html
+32
-0
src/vs/code/electron-browser/sharedProcess.js
src/vs/code/electron-browser/sharedProcess.js
+107
-0
src/vs/code/electron-browser/sharedProcessMain.ts
src/vs/code/electron-browser/sharedProcessMain.ts
+9
-26
src/vs/code/electron-main/main.ts
src/vs/code/electron-main/main.ts
+3
-16
src/vs/code/electron-main/sharedProcess.ts
src/vs/code/electron-main/sharedProcess.ts
+42
-0
未找到文件。
src/vs/code/electron-browser/sharedProcess.html
0 → 100644
浏览文件 @
330901dd
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
</head>
<body
class=
"monaco-shell vs-dark"
aria-label=
""
>
<script>
(
function
()
{
try
{
window
.
location
.
search
.
substring
(
1
).
split
(
'
&
'
).
forEach
(
p
=>
{
var
kv
=
p
.
split
(
'
=
'
);
if
(
kv
[
0
]
===
'
config
'
&&
kv
[
1
])
{
let
config
=
JSON
.
parse
(
decodeURIComponent
(
kv
[
1
]));
window
.
document
.
body
.
className
=
'
monaco-shell
'
+
config
.
baseTheme
;
}
});
}
catch
(
error
)
{
console
.
error
(
error
);
}
})();
</script>
Shared Process
</body>
<!-- Startup via index.js -->
<script
src=
"sharedProcess.js"
></script>
</html>
\ No newline at end of file
src/vs/code/electron-browser/sharedProcess.js
0 → 100644
浏览文件 @
330901dd
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Warning: Do not use the `let` declarator in this file, it breaks our minification
'
use strict
'
;
/*global window,document,define*/
const
path
=
require
(
'
path
'
);
const
electron
=
require
(
'
electron
'
);
const
remote
=
electron
.
remote
;
const
ipc
=
electron
.
ipcRenderer
;
function
assign
(
destination
,
source
)
{
return
Object
.
keys
(
source
)
.
reduce
(
function
(
r
,
key
)
{
r
[
key
]
=
source
[
key
];
return
r
;
},
destination
);
}
function
parseURLQueryArgs
()
{
const
search
=
window
.
location
.
search
||
''
;
return
search
.
split
(
/
[
?&
]
/
)
.
filter
(
function
(
param
)
{
return
!!
param
;
})
.
map
(
function
(
param
)
{
return
param
.
split
(
'
=
'
);
})
.
filter
(
function
(
param
)
{
return
param
.
length
===
2
;
})
.
reduce
(
function
(
r
,
param
)
{
r
[
param
[
0
]]
=
decodeURIComponent
(
param
[
1
]);
return
r
;
},
{});
}
function
createScript
(
src
,
onload
)
{
const
script
=
document
.
createElement
(
'
script
'
);
script
.
src
=
src
;
script
.
addEventListener
(
'
load
'
,
onload
);
const
head
=
document
.
getElementsByTagName
(
'
head
'
)[
0
];
head
.
insertBefore
(
script
,
head
.
lastChild
);
}
function
uriFromPath
(
_path
)
{
var
pathName
=
path
.
resolve
(
_path
).
replace
(
/
\\
/g
,
'
/
'
);
if
(
pathName
.
length
>
0
&&
pathName
.
charAt
(
0
)
!==
'
/
'
)
{
pathName
=
'
/
'
+
pathName
;
}
return
encodeURI
(
'
file://
'
+
pathName
);
}
function
main
()
{
const
args
=
parseURLQueryArgs
();
const
configuration
=
JSON
.
parse
(
args
[
'
config
'
]
||
'
{}
'
)
||
{};
// Correctly inherit the parent's environment
assign
(
process
.
env
,
configuration
.
userEnv
);
// Get the nls configuration into the process.env as early as possible.
var
nlsConfig
=
{
availableLanguages
:
{}
};
const
config
=
process
.
env
[
'
VSCODE_NLS_CONFIG
'
];
if
(
config
)
{
process
.
env
[
'
VSCODE_NLS_CONFIG
'
]
=
config
;
try
{
nlsConfig
=
JSON
.
parse
(
config
);
}
catch
(
e
)
{
/*noop*/
}
}
var
locale
=
nlsConfig
.
availableLanguages
[
'
*
'
]
||
'
en
'
;
if
(
locale
===
'
zh-tw
'
)
{
locale
=
'
zh-Hant
'
;
}
else
if
(
locale
===
'
zh-cn
'
)
{
locale
=
'
zh-Hans
'
;
}
window
.
document
.
documentElement
.
setAttribute
(
'
lang
'
,
locale
);
// Load the loader and start loading the workbench
const
rootUrl
=
uriFromPath
(
configuration
.
appRoot
)
+
'
/out
'
;
// In the bundled version the nls plugin is packaged with the loader so the NLS Plugins
// loads as soon as the loader loads. To be able to have pseudo translation
createScript
(
rootUrl
+
'
/vs/loader.js
'
,
function
()
{
define
(
'
fs
'
,
[
'
original-fs
'
],
function
(
originalFS
)
{
return
originalFS
;
});
// replace the patched electron fs with the original node fs for all AMD code
window
.
MonacoEnvironment
=
{};
const
nodeCachedDataErrors
=
window
.
MonacoEnvironment
.
nodeCachedDataErrors
=
[];
require
.
config
({
baseUrl
:
rootUrl
,
'
vs/nls
'
:
nlsConfig
,
nodeCachedDataDir
:
configuration
.
nodeCachedDataDir
,
onNodeCachedDataError
:
function
(
err
)
{
nodeCachedDataErrors
.
push
(
err
)
},
nodeModules
:
[
/*BUILD->INSERT_NODE_MODULES*/
]
});
if
(
nlsConfig
.
pseudo
)
{
require
([
'
vs/nls
'
],
function
(
nlsPlugin
)
{
nlsPlugin
.
setPseudoTranslation
(
nlsConfig
.
pseudo
);
});
}
require
([
'
vs/code/electron-browser/sharedProcessMain
'
],
function
()
{
});
});
}
main
();
src/vs/code/
node
/sharedProcessMain.ts
→
src/vs/code/
electron-browser
/sharedProcessMain.ts
浏览文件 @
330901dd
...
...
@@ -28,32 +28,16 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProper
import
{
TelemetryAppenderChannel
}
from
'
vs/platform/telemetry/common/telemetryIpc
'
;
import
{
TelemetryService
,
ITelemetryServiceConfig
}
from
'
vs/platform/telemetry/common/telemetryService
'
;
import
{
AppInsightsAppender
}
from
'
vs/platform/telemetry/node/appInsightsAppender
'
;
import
{
ISharedProcessInitData
}
from
'
./sharedProcess
'
;
//
import { ISharedProcessInitData } from './sharedProcess';
import
{
IChoiceService
}
from
'
vs/platform/message/common/message
'
;
import
{
ChoiceChannelClient
}
from
'
vs/platform/message/common/messageIpc
'
;
import
{
IWindowsService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
WindowsChannelClient
}
from
'
vs/platform/windows/common/windowsIpc
'
;
import
{
ActiveWindowManager
}
from
'
vs/code/common/windows
'
;
import
{
ipcRenderer
}
from
'
electron
'
;
function
quit
(
err
?:
Error
)
{
if
(
err
)
{
console
.
error
(
err
.
stack
||
err
);
}
process
.
exit
(
err
?
1
:
0
);
}
/**
* Plan B is to kill oneself if one's parent dies. Much drama.
*/
function
setupPlanB
(
parentPid
:
number
):
void
{
setInterval
(
function
()
{
try
{
process
.
kill
(
parentPid
,
0
);
// throws an exception if the main process doesn't exist anymore.
}
catch
(
e
)
{
process
.
exit
();
}
},
5000
);
interface
ISharedProcessInitData
{
args
:
any
;
}
const
eventPrefix
=
'
monacoworkbench
'
;
...
...
@@ -161,14 +145,13 @@ function setupIPC(hook: string): TPromise<Server> {
function
handshake
():
TPromise
<
ISharedProcessInitData
>
{
return
new
TPromise
<
ISharedProcessInitData
>
((
c
,
e
)
=>
{
process
.
once
(
'
message
'
,
c
);
process
.
once
(
'
error
'
,
e
);
process
.
send
(
'
hello
'
);
ipcRenderer
.
once
(
'
handshake
'
,
(
_
,
r
)
=>
c
(
r
));
ipcRenderer
.
send
(
'
handshake
'
);
});
}
setupIPC
(
process
.
env
[
'
VSCODE_SHARED_IPC_HOOK
'
])
.
then
(
server
=>
handshake
()
.
then
(
data
=>
main
(
server
,
data
))
.
then
(()
=>
setupPlanB
(
process
.
env
[
'
VSCODE_PID
'
]))
.
done
(
null
,
quit
));
\ No newline at end of file
.
then
(
data
=>
main
(
server
,
data
)));
// .then(() => setupPlanB(process.env['VSCODE_PID']))
// .done(null, quit));
src/vs/code/electron-main/main.ts
浏览文件 @
330901dd
...
...
@@ -27,9 +27,8 @@ import { Server, serve, connect } from 'vs/base/parts/ipc/node/ipc.net';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
AskpassChannel
}
from
'
vs/workbench/parts/git/common/gitIpc
'
;
import
{
GitAskpassService
}
from
'
vs/workbench/parts/git/electron-main/askpassService
'
;
import
{
spawnSharedProcess
}
from
'
vs/code/
node
/sharedProcess
'
;
import
{
spawnSharedProcess
}
from
'
vs/code/
electron-main
/sharedProcess
'
;
import
{
Mutex
}
from
'
windows-mutex
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
LaunchService
,
ILaunchChannel
,
LaunchChannel
,
LaunchChannelClient
,
ILaunchService
}
from
'
./launch
'
;
import
{
ServicesAccessor
,
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
...
...
@@ -144,17 +143,9 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
// Spawn shared process
const
initData
=
{
args
:
environmentService
.
args
};
const
options
=
{
allowOutput
:
!
environmentService
.
isBuilt
||
environmentService
.
verbose
,
debugPort
:
environmentService
.
isBuilt
?
null
:
5871
};
let
sharedProcessDisposable
:
IDisposable
;
const
sharedProcess
=
spawnSharedProcess
(
initData
,
options
).
then
(
disposable
=>
{
sharedProcessDisposable
=
disposable
;
return
connect
(
environmentService
.
sharedIPCHandle
,
'
main
'
);
});
const
sharedProcess
=
spawnSharedProcess
(
initData
)
.
then
(
disposable
=>
connect
(
environmentService
.
sharedIPCHandle
,
'
main
'
));
// Create a new service collection, because the telemetry service
// requires a connection to shared process, which was only established
...
...
@@ -220,10 +211,6 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
mainIpcServer
=
null
;
}
if
(
sharedProcessDisposable
)
{
sharedProcessDisposable
.
dispose
();
}
if
(
windowsMutex
)
{
windowsMutex
.
release
();
}
...
...
src/vs/code/
node
/sharedProcess.ts
→
src/vs/code/
electron-main
/sharedProcess.ts
浏览文件 @
330901dd
...
...
@@ -3,75 +3,40 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
cp
from
'
child_process
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
ParsedArgs
}
from
'
vs/platform/environment/common/environment
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
BrowserWindow
,
ipcMain
}
from
'
electron
'
;
export
interface
ISharedProcessInitData
{
args
:
ParsedArgs
;
}
export
interface
ISharedProcessOptions
{
allowOutput
?:
boolean
;
debugPort
?:
number
;
}
const
boostrapPath
=
URI
.
parse
(
require
.
toUrl
(
'
bootstrap
'
)).
fsPath
;
function
_spawnSharedProcess
(
initData
:
ISharedProcessInitData
,
options
:
ISharedProcessOptions
):
cp
.
ChildProcess
{
const
execArgv
:
string
[]
=
[];
const
env
=
assign
({},
process
.
env
,
{
AMD_ENTRYPOINT
:
'
vs/code/node/sharedProcessMain
'
,
ELECTRON_NO_ASAR
:
'
1
'
export
function
spawnSharedProcess
(
initData
:
ISharedProcessInitData
):
TPromise
<
void
>
{
const
window
=
new
BrowserWindow
();
const
config
=
assign
({
userEnv
:
{},
appRoot
:
''
,
nodeCachedDataDir
:
''
});
if
(
options
.
allowOutput
)
{
env
[
'
VSCODE_ALLOW_IO
'
]
=
'
true
'
;
}
if
(
options
.
debugPort
)
{
execArgv
.
push
(
`--debug=
${
options
.
debugPort
}
`
);
}
const
result
=
cp
.
fork
(
boostrapPath
,
[
'
--type=SharedProcess
'
],
{
env
,
execArgv
});
return
result
;
}
const
url
=
`
${
require
.
toUrl
(
'
vs/code/electron-browser/sharedProcess.html
'
)}
?config=
${
encodeURIComponent
(
JSON
.
stringify
(
config
))}
`
;
window
.
loadURL
(
url
);
// window.hide();
window
.
webContents
.
openDevTools
();
export
function
spawnSharedProcess
(
initData
:
ISharedProcessInitData
,
options
:
ISharedProcessOptions
=
{}):
TPromise
<
IDisposable
>
{
let
spawnCount
=
0
;
let
child
:
cp
.
ChildProcess
;
let
promise
:
TPromise
<
IDisposable
>
;
const
spawn
=
()
=>
{
if
(
++
spawnCount
>
10
)
{
return
;
// Prevent the window from dying
window
.
on
(
'
close
'
,
e
=>
{
if
(
window
.
isVisible
())
{
e
.
preventDefault
();
window
.
hide
();
}
});
child
=
_spawnSharedProcess
(
initData
,
options
);
promise
=
new
TPromise
<
IDisposable
>
((
c
,
e
)
=>
{
// handshake
child
.
once
(
'
message
'
,
()
=>
{
child
.
send
(
initData
);
c
({
dispose
:
()
=>
{
if
(
child
)
{
child
.
removeListener
(
'
exit
'
,
spawn
);
child
.
kill
();
child
=
null
;
}
}
});
});
return
new
TPromise
<
void
>
((
c
,
e
)
=>
{
ipcMain
.
once
(
'
handshake
'
,
({
sender
})
=>
{
sender
.
send
(
'
handshake
'
,
initData
);
c
(
null
);
});
child
.
on
(
'
exit
'
,
spawn
);
};
spawn
();
return
promise
;
});
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录