-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPA-Installer-JSBox.js
More file actions
144 lines (135 loc) · 3.44 KB
/
IPA-Installer-JSBox.js
File metadata and controls
144 lines (135 loc) · 3.44 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* IPA-installer JSBox script. This script is not available stand alone, checkout the demo from TG channel @NobyDa
*
* Modified from https://github.com/axelburks/JSBox/blob/master/IPA%20Installer.js by @NobyDa
*/
var port_number = 8070
var plist_url = `itms-services://?action=download-manifest&url=https://nobyda.app/install%3Fclient%3Djsbox%26url%3Dhttp%253A%252F%252F127.0.0.1%253A${port_number}%252Fdownload%253Fpath%253D%25252Fapp.ipa`
$app.strings = {
"en": {
"starterror": "Not support running in this way",
"ftypeerror": " is not ipa file",
"installtitle": "Installing...",
"installmsg": "\n\nYou can check on Homescreen.\nPlease tap \"Done\" button after finished",
"inerrtitle": "IPA file import error",
"inerrmsg": "Please rerun the script"
},
"zh-Hans": {
"starterror": "不支持此方式运行!",
"ftypeerror": " 非 ipa 文件!",
"installtitle": "正在安装…",
"installmsg": "\n\n可前往桌面查看安装进度\n完成后请点击\"Done\"按钮",
"inerrtitle": "IPA文件导入失败",
"inerrmsg": "请重新运行此脚本"
}
}
// 从应用内启动
if ($app.env == $env.app) {
$drive.open({
handler: function(data) {
fileCheck(data)
}
})
}
// 从 Action Entension 启动
else if ($app.env == $env.action) {
fileCheck($context.data)
}
else {
$ui.error($l10n("starterror"))
delayClose(2)
}
function startServer(port) {
$http.startServer({
port: port,
path: "",
handler: function(result) {
console.info(result.url)
}
})
}
function fileCheck(data) {
if (data && data.fileName) {
var fileName = data.fileName;
if (fileName.indexOf(".ipa") == -1) {
$ui.error(fileName + $l10n("ftypeerror"))
delayClose(2)
} else {
install(fileName, data);
}
}
}
function install(fileName, file) {
var result = $file.write({
data: file,
path: "app.ipa"
})
if (result) {
startServer(port_number)
$location.startUpdates({
handler: function(resp) {
console.info(resp.lat + " " + resp.lng + " " + resp.alt)
}
})
var preResult = $app.openURL(plist_url);
if (preResult) {
$ui.alert({
title: $l10n("installtitle"),
message: "\n" + fileName + $l10n("installmsg"),
actions: [{
title: "Cancel",
style: "Cancel",
handler: function() {
$http.stopServer()
$file.delete("app.ipa")
delayClose(0.2)
}
},
{
title: "Done",
handler: function() {
$http.stopServer()
$file.delete("app.ipa")
delayClose(0.2)
}
}]
})
} else {
$ui.alert({
title: "Open itms-services scheme failed",
message: "Please rerun the script or restart device",
actions: [
{
title: "OK",
handler: function() {
delayClose(0.2)
}
}]
})
}
} else {
$ui.alert({
title: $l10n("inerrtitle"),
message: $l10n("inerrmsg"),
actions: [{
title: "OK",
style: "Cancel",
handler: function() {
delayClose(0.2)
}
}]
})
}
}
function delayClose(time) {
$location.stopUpdates()
$thread.main({
delay: time,
handler: function() {
if ($app.env == $env.action || $app.env == $env.safari) {
$context.close()
}
$app.close()
}
})
}