Skip to content

Commit a0d72d3

Browse files
committed
feat: skyline正式支持
1 parent 6982467 commit a0d72d3

5 files changed

Lines changed: 120 additions & 44 deletions

File tree

res/scripts/core_index.js

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,112 @@
1-
"use strict";
21
{
32
const createElement = document.createElement
43
document.createElement = function (tagName) {
54
const instance = createElement.call(document, tagName)
65
if (tagName === 'iframe') {
76
instance.setAttribute('nwdisable', 'true')
7+
} else if (tagName === 'webview') {
8+
Object.defineProperty(instance, 'instance', {
9+
set(value) {
10+
console.warn('webview instance set', value)
11+
this._instance = value
12+
if (value) {
13+
Object.defineProperty(value, '_type', {
14+
set(type) {
15+
console.warn('webview type set', type)
16+
this.__type = type
17+
if (type === 'skyline_appservice') {
18+
const client = require('skyline-addon/build/skyline.node')
19+
const setErrorMsg = (msg) => {
20+
console.error('skyline error', msg)
21+
const store = require('core.wxvpkg/b7691e109ad844af265d9385e5205802.js')
22+
if (msg?.includes('Not connected')) {
23+
msg = 'Skyline链接丢失,请检查服务状态'
24+
} else if (msg?.includes('Socket connection failed') || msg?.includes('Connection refused')) {
25+
msg = 'Skyline连接失败,请检查服务状态'
26+
}
27+
store.dispatch({
28+
type: 'SIMULATOR_LAUNCH_ERROR',
29+
data: msg || 'Skyline出现异常,无法启动AppService,请检查Skyline是否正常运行',
30+
})
31+
}
32+
try {
33+
client.Controller.connect()
34+
} catch (e) {
35+
console.error('connect skyline error', e)
36+
setErrorMsg(e?.message)
37+
throw e
38+
}
39+
const controller = new client.Controller(setErrorMsg)
40+
const webview = controller.webview
41+
Object.defineProperties(this, {
42+
src: {
43+
set(src) {
44+
console.warn('skyline_appservice webview set src', src)
45+
webview.src = src
46+
this.__webview__.src = 'about:blank'
47+
},
48+
get() {
49+
console.warn('skyline_appservice webview get src', webview.src)
50+
return webview.src
51+
},
52+
configurable: true,
53+
},
54+
})
55+
webview.showDevTools = async function (show, container) {
56+
try{
57+
// 1. 获取列表
58+
const resp = await fetch('http://127.0.0.1:9222/json/list')
59+
const list = await resp.json()
60+
// 2. 筛选 webview - appservice/mainframe
61+
const target = list.find(item => item.type === 'webview')
62+
// 3. 取到 webSocketDebuggerUrl
63+
const webSocketDebuggerUrl = target.webSocketDebuggerUrl.replace('ws://', '')
64+
// devtools://devtools/bundled/devtools_app.html?ws=127.0.0.1:9222/devtools/page/7601AF914FBACB429A289A8AC7AA82EB
65+
container.src = `devtools://devtools/bundled/devtools_app.html?ws=${webSocketDebuggerUrl}`
66+
// this.__webview__.showDevTools(show, container)
67+
}
68+
catch(e){
69+
console.error('showDevTools error', e)
70+
require('core.wxvpkg/b7691e109ad844af265d9385e5205802.js').dispatch({
71+
type: 'SIMULATOR_LAUNCH_ERROR',
72+
data: 'Skyline出现异常,无法启动AppService,请检查Skyline是否正常运行',
73+
})
74+
}
75+
}
76+
this.getOriginElement = function () {
77+
return webview
78+
}
79+
this.setAttribute = function (name, value) {
80+
return webview.setAttribute(name, value)
81+
}
82+
{
83+
const mount = this.mount
84+
this.mount = function (e) {
85+
mount.apply(this, e)
86+
controller.mount()
87+
}
88+
}
89+
{
90+
const unmount = this.unmount
91+
this.unmount = function (e) {
92+
unmount.apply(this, e)
93+
controller.unmount()
94+
}
95+
}
96+
}
97+
},
98+
get() {
99+
return this.__type
100+
},
101+
configurable: true,
102+
})
103+
}
104+
},
105+
get() {
106+
return this._instance
107+
},
108+
configurable: true,
109+
})
8110
}
9111
return instance
10112
}

res/scripts/document_start.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,4 @@
8989
}
9090
}
9191
})();
92-
if (!window.skylineRequireReplace) {
93-
window.skylineRequireReplace = true;
94-
const originalRequire = window.require;
95-
if (originalRequire) {
96-
window.require = function (m) {
97-
if (m.includes("skyline.node")) {
98-
// 给native用的
99-
globalThis.__sharedMemory = originalRequire(
100-
"sharedMemory/sharedMemory.node"
101-
);
102-
}
103-
return originalRequire(m);
104-
};
105-
window.require.cache = originalRequire.cache;
106-
window.require.extensions = originalRequire.extensions;
107-
window.require.resolve = originalRequire.resolve;
108-
}
109-
}
11092
})();

res/scripts/skyline.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
(() => {
22
// 处理红蓝颜色通道反转的问题
3-
const originalTextImage2D = WebGLRenderingContext.prototype.texImage2D;
4-
WebGLRenderingContext.prototype.texImage2D = function (...args) {
5-
const buffer = args[8];
6-
for (let i=0; i<buffer.byteLength; i+=4) {
7-
// BGRA -> RGBA
8-
const b = buffer[i];
9-
buffer[i] = buffer[i + 2];
10-
buffer[i + 2] = b;
11-
}
12-
return originalTextImage2D.apply(this, args);
13-
};
3+
window.__global.platform = 'win32'
144
})();

tools/replace-skyline.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ cache_dir="$root_dir/cache"
77
nwjs_dir="$root_dir/nwjs"
88
package_dir="$root_dir/package.nw"
99

10-
shared_memory_version="v1.0.3"
11-
skyline_version="v1.0.4"
10+
shared_memory_version="v1.0.4"
11+
skyline_version="v2.01.2510280-1"
1212

1313
cd "$package_dir/node_modules"
1414
mkdir -p "$cache_dir/skyline"

tools/run-skyline-server.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
2-
docker run -it \
3-
--restart=always \
4-
--hostname="$(hostname)" \
5-
--env="DISPLAY" \
6-
--platform="linux/amd64" \
7-
--volume="${XAUTHORITY:-${HOME}/.Xauthority}:/root/.Xauthority:ro" \
8-
--volume="/tmp/.X11-unix:/tmp/.X11-unix:ro" \
9-
--volume="/dev/shm:/dev/shm" \
10-
--volume="./.wine:/root/.wine" \
11-
-p 3001:3001 \
12-
--name skyline_server \
13-
ghcr.io/msojocs/skyline-client-server:master
2+
set -ex
3+
4+
root_dir=$(cd "$(dirname "$0")/.." && pwd -P)
5+
6+
docker run -d \
7+
--network host \
8+
-e HOST_UID=$(id -u) \
9+
-e HOST_GID=$(id -g) \
10+
-e XVFB_RES=800x600x24 \
11+
-v $HOME/.config/wechat-devtools/WeappPlugin:/workspace/WeappPlugin \
12+
-v $root_dir/package.nw/js/ideplugin:/workspace/inspector \
13+
-v "/dev/shm:/dev/shm" \
14+
--name wechat_devtools_server \
15+
devtools-server:2.01.2510280-1

0 commit comments

Comments
 (0)