-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
107 lines (97 loc) · 2.65 KB
/
Copy pathtest.html
File metadata and controls
107 lines (97 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>开发者模式 - Turn any website into a native app. No rewrite. Zero Rust. Just config</title>
<style>
body {
padding: 10px 20px;
}
button {
margin: 0 20px;
}
div {
margin-top: 20px;
}
img {
width: 500px;
margin-left: 20px;
}
a {
display: block;
margin-top: 10px;
}
.text-center {
text-align: center;
}
.red-text {
color: #e30606;
}
</style>
</head>
<body>
<h3>
CapShell - Turn any website into a native app. No rewrite. Zero Rust. Just config.
</h3>
<h3 class="text-center">
请在 <span class="red-text">config.json</span> 中配置应用URL。
<a href="https://github.com/TommysLee/CapShell/blob/main/src-tauri/default_config.json" target="_blank" rel="noopener">点击查看示例</a>
</h3>
<hr>
<h3>
开发者模式
</h3>
<button onclick="startGpsTracking()">启用GPS定位,请查看控制台</button>
<button onclick="stopGpsTracking()">关闭GPS定位</button>
<button onclick="openCamera()">打开相机</button>
<button onclick="closeCamera()">关闭相机</button>
<div>
<img id="img" style="width: 500px"/>
</div>
<ul id="gps-list">
</ul>
<script src="assets/js/sdk.js"></script>
<script>
const imgEl = document.getElementById("img");
const gpsEl = document.getElementById("gps-list");
// 开启GPS实时定位
function startGpsTracking() {
Shell.startGpsTracking(position => {
const gps_data = JSON.stringify(position);
console.log("子页面:实时GPS", position, '\n', gps_data);
appendEl(gps_data);
}, err => {
console.log("子页面:GPS错误:", err);
})
appendEl('GPS 实时定位已开启');
}
// 关闭GPS实时定位
function stopGpsTracking() {
Shell.stopGpsTracking();
appendEl('GPS 实时定位 已关闭');
}
// 打开相机
function openCamera() {
Shell.openCamera((result) => {
console.log("子页面", result.type, " Callback: ", result);
if (result.type === 'CAMERA_RESULT') {
result.image && (imgEl.src = result.image);
}
})
}
// 关闭相机
function closeCamera() {
Shell.closeCamera((result) => {
console.log("子页面 closeCamera Callback: ", result);
})
}
// 工具函数
function appendEl(content) {
const el = document.createElement('li');
el.innerHTML = content;
gpsEl.appendChild(el);
}
</script>
</body>
</html>