Skip to content

Commit d2bd248

Browse files
authored
feat: upload expo-playground to hardware-example.onekey.so && fix buffer type error; OK-45072 (#596)
* feat: test expo playground jump * feat: test hash example * fix: expo-playground prodcuton * fix: expo-playground commit url * fix: commit url * fix: buffer * chore: 1.1.16-alpha.6 * fix: 1.1.16-alpha.7 & update isBuffer
1 parent fadb7a2 commit d2bd248

File tree

22 files changed

+254
-211
lines changed

22 files changed

+254
-211
lines changed

.github/templates/404.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
// 智能路由分发逻辑 - 保持原始URL不变,让SPA自己处理路由
1818
if (path.startsWith('/expo-playground/')) {
19-
// expo-playground 的子路由,保存原始路径信息
20-
if (path !== '/expo-playground/' && path !== '/expo-playground') {
19+
const base = '/expo-playground';
20+
const relativePath = path.slice(base.length);
21+
22+
if (relativePath && relativePath !== '/') {
2123
console.log('Handling expo-playground sub-route:', path);
22-
// 保存完整的原始URL到sessionStorage供应用恢复路由
23-
sessionStorage.setItem('spa_redirect_url', path + fullUrl);
24-
// 直接重定向到 index.html,保持 URL 不变
25-
window.location.replace('/expo-playground/index.html');
24+
const normalized = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;
25+
const hashPath = normalized.startsWith('/') ? `#${normalized}` : `#/${normalized}`;
26+
window.location.replace(`${base}/${hashPath}${search}${hash}`);
2627
return;
2728
}
2829
return;

.github/workflows/build-example-web.yml

Lines changed: 90 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3,160 +3,147 @@ name: Build and Deploy Examples
33
on: workflow_dispatch
44

55
env:
6-
COMMIT_SHORT_SHA: ${{ github.sha }}
6+
COMMIT_FULL_SHA: ${{ github.sha }}
77

88
jobs:
9-
build_expo:
9+
deploy_preview:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313

1414
- name: Get short commit SHA
1515
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
1616

1717
- name: Setup Node.js
18-
uses: actions/setup-node@v3
18+
uses: actions/setup-node@v4
1919
with:
2020
node-version: '22'
2121
registry-url: 'https://registry.npmjs.org'
22+
2223
- name: Install Dependencies
2324
run: |
2425
yarn
2526
yarn bootstrap
27+
2628
- name: Build All Packages
2729
run: yarn build
30+
2831
- name: Build Expo Example
2932
run: EXPO_PUBLIC_COMMIT_SHA=${{ env.COMMIT_SHORT_SHA }} yarn expo export:web
3033
working-directory: packages/connect-examples/expo-example
3134

32-
- name: Add commit info to build output
35+
- name: Add commit info to Expo Example
3336
run: |
34-
# 先备份原始构建产物到临时目录
3537
mkdir -p temp-build
3638
cp -r web-build/* temp-build/ 2>/dev/null || true
37-
# 创建带有 commit id 的子目录
3839
mkdir -p web-build/commits/${{ env.COMMIT_SHORT_SHA }}
39-
# 复制备份的构建产物到带有 commit id 的目录
4040
cp -r temp-build/* web-build/commits/${{ env.COMMIT_SHORT_SHA }}/
41-
# 创建一个 commit 信息文件
4241
echo '{"commit": "${{ env.COMMIT_SHORT_SHA }}", "fullCommit": "${{ github.sha }}", "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' > web-build/commits/${{ env.COMMIT_SHORT_SHA }}/commit-info.json
43-
# 为 commit 版本也创建 404.html
4442
cp web-build/commits/${{ env.COMMIT_SHORT_SHA }}/index.html web-build/commits/${{ env.COMMIT_SHORT_SHA }}/404.html
45-
# 清理临时目录
4643
rm -rf temp-build
4744
working-directory: packages/connect-examples/expo-example
4845

49-
- name: Upload Artifact
50-
uses: actions/upload-artifact@v4
46+
- name: Build Expo Playground (testing preview)
47+
working-directory: packages/connect-examples/expo-playground
48+
run: yarn build
49+
50+
- name: Add SPA fallback pages
51+
run: |
52+
cp packages/connect-examples/expo-playground/dist/index.html packages/connect-examples/expo-playground/dist/404.html
53+
cp packages/connect-examples/expo-example/web-build/index.html packages/connect-examples/expo-example/web-build/404.html
54+
55+
- name: Prepare root static assets
56+
run: |
57+
rm -rf gh-pages-root
58+
mkdir -p gh-pages-root
59+
cp .github/templates/404.html gh-pages-root/404.html
60+
cp .github/templates/404.html gh-pages-root/index.html
61+
if [ -f "packages/connect-examples/expo-example/web-build/manifest.json" ]; then
62+
cp packages/connect-examples/expo-example/web-build/manifest.json gh-pages-root/manifest.json
63+
echo "✅ Copied manifest.json from expo-example"
64+
else
65+
cp .github/templates/manifest.json gh-pages-root/manifest.json
66+
echo "⚠️ expo-example manifest not found, using template"
67+
fi
68+
find packages/connect-examples/expo-example/web-build -maxdepth 1 -type f -name "favicon*" -exec cp {} gh-pages-root/ \;
69+
70+
- name: Deploy root assets
71+
uses: peaceiris/actions-gh-pages@v4
5172
with:
52-
name: expo-build
53-
path: packages/connect-examples/expo-example/web-build
73+
github_token: ${{ secrets.GITHUB_TOKEN }}
74+
publish_dir: ./gh-pages-root
75+
cname: hardware-example.onekeytest.com
76+
force_orphan: true
77+
78+
- name: Deploy Expo Example (GitHub Pages)
79+
uses: peaceiris/actions-gh-pages@v4
80+
with:
81+
github_token: ${{ secrets.GITHUB_TOKEN }}
82+
publish_dir: packages/connect-examples/expo-example/web-build
83+
destination_dir: expo-example
84+
keep_files: true
5485

55-
build_new_example:
86+
- name: Deploy Expo Playground (GitHub Pages)
87+
uses: peaceiris/actions-gh-pages@v4
88+
with:
89+
github_token: ${{ secrets.GITHUB_TOKEN }}
90+
publish_dir: packages/connect-examples/expo-playground/dist
91+
destination_dir: expo-playground
92+
keep_files: true
93+
94+
build_playground_production:
5695
runs-on: ubuntu-latest
96+
needs: deploy_preview
5797
steps:
58-
- uses: actions/checkout@v3
98+
- uses: actions/checkout@v4
5999

60100
- name: Get short commit SHA
61101
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
62102

63103
- name: Setup Node.js
64-
uses: actions/setup-node@v3
104+
uses: actions/setup-node@v4
65105
with:
66106
node-version: '22'
67107
registry-url: 'https://registry.npmjs.org'
108+
68109
- name: Install Dependencies
69110
run: |
70111
yarn
71112
yarn bootstrap
113+
72114
- name: Build All Packages
73115
run: yarn build
74-
- name: Build New Example
75-
run: COMMIT_SHA=${{ env.COMMIT_SHORT_SHA }} yarn build
76-
working-directory: packages/connect-examples/expo-playground
77-
- name: Upload Artifact
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: expo-playground-build
81-
path: packages/connect-examples/expo-playground/dist
82-
83-
deploy:
84-
runs-on: ubuntu-latest
85-
needs: [build_expo, build_new_example]
86-
steps:
87-
- name: Checkout
88-
uses: actions/checkout@v3
89-
90-
- name: Get short commit SHA
91-
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
92-
93-
- name: Setup Deploy Directory
94-
run: mkdir -p deploy
95-
- name: Download Expo Artifact
96-
uses: actions/download-artifact@v4
97-
with:
98-
name: expo-build
99-
path: deploy/temp-expo
100-
- name: Download New Example Artifact
101-
uses: actions/download-artifact@v4
102-
with:
103-
name: expo-playground-build
104-
path: deploy/expo-playground
105-
- name: Setup Expo as Root and create routing
106-
run: |
107-
# Create expo-example subdirectory and copy all build files
108-
mkdir -p deploy/expo-example
109-
cp -r deploy/temp-expo/* deploy/expo-example/
110-
111-
# Debug: List files in expo-example directory
112-
echo "=== Files in deploy/expo-example ==="
113-
find deploy/expo-example -type f -name "*.json" -o -name "favicon*" -o -name "*.ico" | head -10
114-
115-
# Copy all favicon-related files to root path
116-
# Handle various favicon formats that Expo might generate
117-
favicon_count=0
118-
find deploy/expo-example -name "favicon*" -type f | while read file; do
119-
filename=$(basename "$file")
120-
cp "$file" "deploy/$filename"
121-
echo "✅ Copied favicon: $filename"
122-
favicon_count=$((favicon_count + 1))
123-
done
124-
125-
if [ $favicon_count -eq 0 ]; then
126-
echo "⚠️ No favicon files found in build output"
127-
fi
128116

129-
# Copy manifest.json to root path for PWA support
130-
if [ -f "deploy/expo-example/manifest.json" ]; then
131-
cp deploy/expo-example/manifest.json deploy/manifest.json
132-
echo "✅ Copied manifest.json to root"
133-
echo "=== Generated manifest.json content ==="
134-
cat deploy/manifest.json | head -10
135-
else
136-
# Use fallback manifest.json if Expo didn't generate one
137-
cp .github/templates/manifest.json deploy/manifest.json
138-
echo "⚠️ Used fallback manifest.json (Expo didn't generate one)"
139-
fi
140-
141-
# Clean up temp directory
142-
rm -rf deploy/temp-expo
117+
- name: Build Expo Playground (production)
118+
working-directory: packages/connect-examples/expo-playground
119+
env:
120+
COMMIT_SHA: ${{ env.COMMIT_FULL_SHA }}
121+
run: yarn build
143122

144-
- name: Add SPA fallback for client-side routing
123+
- name: Package production bundle with commit id
124+
working-directory: packages/connect-examples/expo-playground
125+
env:
126+
COMMIT_FULL_SHA: ${{ env.COMMIT_FULL_SHA }}
127+
COMMIT_SHORT_SHA: ${{ env.COMMIT_SHORT_SHA }}
145128
run: |
146-
# 为各子应用创建简单的 SPA 回退 404.html
147-
cp deploy/expo-playground/index.html deploy/expo-playground/404.html
148-
cp deploy/expo-example/index.html deploy/expo-example/404.html
149-
150-
# 复制统一的路由分发器模板到根目录
151-
cp .github/templates/404.html deploy/404.html
152-
153-
# 验证部署结构
154-
echo "=== Deployment Structure ==="
155-
find deploy -name "*.html" -o -name "manifest.json" -o -name "favicon*" | sort
156-
- name: Deploy to Github Pages
157-
uses: peaceiris/actions-gh-pages@v4
129+
RELEASE_ROOT="release"
130+
rm -rf "${RELEASE_ROOT}"
131+
mkdir -p "${RELEASE_ROOT}"
132+
cp dist/index.html "${RELEASE_ROOT}/index.html"
133+
cp dist/404.html "${RELEASE_ROOT}/404.html"
134+
mkdir -p "${RELEASE_ROOT}/${COMMIT_FULL_SHA}"
135+
cp -R dist/${COMMIT_FULL_SHA}/. "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/"
136+
cat <<EOF > "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/build-info.json"
137+
{
138+
"commit": "${COMMIT_FULL_SHA}",
139+
"shortCommit": "${COMMIT_SHORT_SHA}",
140+
"buildEnv": "production",
141+
"buildTime": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
142+
}
143+
EOF
144+
145+
- name: Upload Production Artifact
146+
uses: actions/upload-artifact@v4
158147
with:
159-
github_token: ${{ secrets.GITHUB_TOKEN }}
160-
publish_dir: ./deploy
161-
cname: hardware-example.onekeytest.com
162-
force_orphan: true
148+
name: ${{ env.COMMIT_FULL_SHA }}
149+
path: packages/connect-examples/expo-playground/release

packages/connect-examples/electron-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "hardware-example",
33
"productName": "HardwareExample",
44
"executableName": "onekey-hardware-example",
5-
"version": "1.1.16-alpha.5",
5+
"version": "1.1.16-alpha.7",
66
"author": "OneKey",
77
"description": "End-to-end encrypted workspaces for teams",
88
"main": "dist/index.js",
@@ -22,7 +22,7 @@
2222
"ts:check": "yarn tsc --noEmit"
2323
},
2424
"dependencies": {
25-
"@onekeyfe/hd-transport-electron": "1.1.16-alpha.5",
25+
"@onekeyfe/hd-transport-electron": "1.1.16-alpha.7",
2626
"@stoprocent/noble": "2.3.4",
2727
"debug": "4.3.4",
2828
"electron-is-dev": "^3.0.1",

packages/connect-examples/expo-example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-example",
3-
"version": "1.1.16-alpha.5",
3+
"version": "1.1.16-alpha.7",
44
"scripts": {
55
"start": "cross-env CONNECT_SRC=https://localhost:8087/ yarn expo start --dev-client",
66
"android": "yarn expo run:android",
@@ -19,10 +19,10 @@
1919
"@noble/ed25519": "^2.1.0",
2020
"@noble/hashes": "^1.3.3",
2121
"@noble/secp256k1": "^1.7.1",
22-
"@onekeyfe/hd-ble-sdk": "1.1.16-alpha.5",
23-
"@onekeyfe/hd-common-connect-sdk": "1.1.16-alpha.5",
24-
"@onekeyfe/hd-core": "1.1.16-alpha.5",
25-
"@onekeyfe/hd-web-sdk": "1.1.16-alpha.5",
22+
"@onekeyfe/hd-ble-sdk": "1.1.16-alpha.7",
23+
"@onekeyfe/hd-common-connect-sdk": "1.1.16-alpha.7",
24+
"@onekeyfe/hd-core": "1.1.16-alpha.7",
25+
"@onekeyfe/hd-web-sdk": "1.1.16-alpha.7",
2626
"@onekeyfe/react-native-ble-utils": "^0.1.3",
2727
"@polkadot/util-crypto": "13.1.1",
2828
"@react-native-async-storage/async-storage": "1.21.0",

packages/connect-examples/expo-playground/app/data/searchActions.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ import { deviceMethodsRegistry, signerMethodsRegistry } from '../hooks/useMethod
22
import { usePersistenceStore } from '../store/persistenceStore';
33
import type { Action } from 'kbar';
44

5-
// 获取基础路径 - 与项目配置保持一致
6-
const getBasename = () => {
7-
if (typeof window === 'undefined') return '';
8-
// 统一使用环境变量,与 entry.client.tsx 和 webpack.config.js 保持一致
9-
return process.env.NODE_ENV === 'production' ? '/expo-playground' : '';
5+
// 规范化路径并生成 Hash 路由路径
6+
const buildHashPath = (path: string) => {
7+
if (!path) {
8+
return '#/';
9+
}
10+
const normalized = path.startsWith('/') ? path : `/${path}`;
11+
return normalized === '/' ? '#/' : `#${normalized}`;
1012
};
1113

12-
// 导航函数 - 使用 React Router 的编程式导航
14+
// 导航函数 - 切换 Hash 路由以适配 createHashRouter
1315
const navigateTo = (path: string) => {
14-
// 添加 basename 前缀
15-
const fullPath = getBasename() + path;
16-
// 使用 window.history.pushState 进行 SPA 导航
17-
window.history.pushState(null, '', fullPath);
18-
// 触发 popstate 事件让 React Router 响应
19-
window.dispatchEvent(new PopStateEvent('popstate'));
16+
if (typeof window === 'undefined') return;
17+
const targetHash = buildHashPath(path);
18+
if (window.location.hash === targetHash) {
19+
// 如果已在目标哈希,则手动触发事件以确保路由响应
20+
const hashEvent =
21+
typeof HashChangeEvent === 'function'
22+
? new HashChangeEvent('hashchange')
23+
: new Event('hashchange');
24+
window.dispatchEvent(hashEvent);
25+
return;
26+
}
27+
window.location.hash = targetHash;
2028
};
2129

2230
// 主题切换函数

0 commit comments

Comments
 (0)