Skip to content

Commit a4e5b4e

Browse files
committed
fix launch path not accessible crash
1 parent 6ac55b8 commit a4e5b4e

File tree

7 files changed

+809
-653
lines changed

7 files changed

+809
-653
lines changed

Build/v2ray-core/geoip.dat

697 KB
Binary file not shown.

Build/v2ray-core/geosite.dat

Lines changed: 757 additions & 625 deletions
Large diffs are not rendered by default.

V2rayU.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@
836836
CODE_SIGN_STYLE = Automatic;
837837
COMBINE_HIDPI_IMAGES = YES;
838838
COPY_PHASE_STRIP = NO;
839-
CURRENT_PROJECT_VERSION = 4.0.1;
839+
CURRENT_PROJECT_VERSION = 4.0.3;
840840
DEFINES_MODULE = YES;
841841
DEVELOPMENT_TEAM = RJYEH6TCJD;
842842
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
@@ -847,7 +847,7 @@
847847
"@executable_path/../Frameworks",
848848
);
849849
MACOSX_DEPLOYMENT_TARGET = 10.14;
850-
MARKETING_VERSION = 4.0.preview;
850+
MARKETING_VERSION = 4.0.0;
851851
ONLY_ACTIVE_ARCH = YES;
852852
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
853853
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -869,7 +869,7 @@
869869
CODE_SIGN_STYLE = Automatic;
870870
COMBINE_HIDPI_IMAGES = YES;
871871
COPY_PHASE_STRIP = NO;
872-
CURRENT_PROJECT_VERSION = 4.0.1;
872+
CURRENT_PROJECT_VERSION = 4.0.3;
873873
DEFINES_MODULE = YES;
874874
DEVELOPMENT_TEAM = RJYEH6TCJD;
875875
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
@@ -880,7 +880,7 @@
880880
"@executable_path/../Frameworks",
881881
);
882882
MACOSX_DEPLOYMENT_TARGET = 10.14;
883-
MARKETING_VERSION = 4.0.preview;
883+
MARKETING_VERSION = 4.0.0;
884884
ONLY_ACTIVE_ARCH = NO;
885885
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
886886
PRODUCT_NAME = "$(TARGET_NAME)";

V2rayU/MainMenu.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ class MenuController: NSObject, NSMenuDelegate {
103103

104104
func setStatusMenuTip(pingTip: String) {
105105
do {
106-
if self.statusMenu.item(withTag: 1) != nil {
107-
self.statusMenu.item(withTag: 1)!.title = pingTip
106+
DispatchQueue.main.async {
107+
if self.statusMenu.item(withTag: 1) != nil {
108+
self.statusMenu.item(withTag: 1)!.title = pingTip
109+
}
108110
}
109111
}
110112
}
@@ -114,11 +116,11 @@ class MenuController: NSObject, NSMenuDelegate {
114116
let _subMenus = getServerMenus()
115117
lock.lock()
116118
do {
117-
serverItems.submenu = _subMenus
118-
// fix: must be used from main thread only
119-
if configWindow != nil && configWindow.serversTableView != nil {
120-
DispatchQueue.main.async {
121-
configWindow.serversTableView.reloadData()
119+
DispatchQueue.main.async {
120+
self.serverItems.submenu = _subMenus
121+
// fix: must be used from main thread only
122+
if configWindow != nil && configWindow.serversTableView != nil {
123+
configWindow.serversTableView.reloadData()
122124
}
123125
}
124126
}

V2rayU/Ping.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ class PingSpeed: NSObject {
2929
NSLog("ping inPing")
3030
return
3131
}
32-
32+
// make sure core file
33+
V2rayLaunch.checkV2rayCore()
34+
// in ping
35+
inPing = true
36+
3337
killAllPing()
3438

3539
fastV2rayName = ""
3640
unpingServers = [String: Bool]()
3741
let itemList = V2rayServer.list()
3842
if itemList.count == 0 {
43+
inPing = false
3944
return
4045
}
4146
let langStr = Locale.current.languageCode
@@ -46,8 +51,6 @@ class PingSpeed: NSObject {
4651
pingTip = "Ping Speed - 测试中"
4752
}
4853
menuController.setStatusMenuTip(pingTip: pingTip)
49-
// in ping
50-
inPing = true
5154
let pingQueue = DispatchQueue(label: "pingQueue", qos: .background, attributes: .concurrent)
5255
for item in itemList {
5356
unpingServers[item.name] = true

V2rayU/Util.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ func killAllPing(){
536536
let pskillCmd = "ps aux | grep v2ray | grep '.V2rayU/.config.' | awk '{print $2}' | xargs kill"
537537
let msg = shell(launchPath: "/bin/bash", arguments: ["-c", pskillCmd])
538538
NSLog("killAllPing: \(String(describing: msg))")
539+
let rmPingJsonCmd = "rm -f ~/.V2rayU/.config.*.json"
540+
let msg1 = shell(launchPath: "/bin/bash", arguments: ["-c", rmPingJsonCmd])
541+
NSLog("rmPingJson: \(String(describing: msg1))")
539542
}
540543

541544
func killSelfV2ray(){

V2rayU/V2rayLaunch.swift

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,48 +48,53 @@ class V2rayLaunch: NSObject {
4848
}
4949

5050
// make sure new version
51-
print("install", AppResourcesPath)
51+
NSLog("install", AppResourcesPath)
5252
var needRunInstall = false
5353
if !FileManager.default.fileExists(atPath: v2rayCoreFile) {
54-
print("\(v2rayCoreFile) not exists,need install")
54+
NSLog("\(v2rayCoreFile) not exists,need install")
55+
needRunInstall = true
56+
}
57+
if !FileManager.default.isExecutableFile(atPath: v2rayCoreFile) {
58+
NSLog("\(v2rayCoreFile) not accessable")
5559
needRunInstall = true
5660
}
5761
if !FileManager.default.fileExists(atPath: v2rayCorePath+"/geoip.dat") {
58-
print("\(v2rayCorePath)/geoip.dat not exists,need install")
62+
NSLog("\(v2rayCorePath)/geoip.dat not exists,need install")
5963
needRunInstall = true
6064
}
6165
if !FileManager.default.fileExists(atPath: v2rayUTool) {
62-
print("\(v2rayUTool) not exists,need install")
66+
NSLog("\(v2rayUTool) not exists,need install")
6367
needRunInstall = true
6468
}
6569
if !FileManager.default.fileExists(atPath: PACAbpFile) {
66-
print("\(PACAbpFile) not exists,need install")
70+
NSLog("\(PACAbpFile) not exists,need install")
6771
needRunInstall = true
6872
}
6973
if !FileManager.default.fileExists(atPath: GFWListFilePath) {
70-
print("\(GFWListFilePath) not exists,need install")
74+
NSLog("\(GFWListFilePath) not exists,need install")
7175
needRunInstall = true
7276
}
7377
if !FileManager.default.fileExists(atPath: PACUserRuleFilePath) {
74-
print("\(PACUserRuleFilePath) not exists,need install")
78+
NSLog("\(PACUserRuleFilePath) not exists,need install")
7579
needRunInstall = true
7680
}
77-
78-
// V2rayUTool version
79-
let toolVersion = shell(launchPath: v2rayUTool, arguments: ["version"])
81+
82+
// use /bin/bash to fix crash when V2rayUTool is not exist
83+
let toolVersion = shell(launchPath: "/bin/bash", arguments: ["-c", "\(v2rayUTool) version"])
84+
NSLog("toolVersion - \(v2rayUTool): \(String(describing: toolVersion))")
8085
if toolVersion != nil {
8186
let _version = toolVersion ?? "" // old version
8287
if _version.contains("Usage:") {
83-
print("\(v2rayUTool) old version,need install")
88+
NSLog("\(v2rayUTool) old version,need install")
8489
needRunInstall = true
8590
} else {
8691
if !(_version >= "4.0.0") {
87-
print("\(v2rayUTool) old version,need install")
92+
NSLog("\(v2rayUTool) old version,need install")
8893
needRunInstall = true
8994
}
9095
}
9196
} else {
92-
print("\(v2rayUTool) not exists,need install")
97+
NSLog("\(v2rayUTool) not exists,need install")
9398
needRunInstall = true
9499
}
95100

@@ -149,7 +154,7 @@ class V2rayLaunch: NSObject {
149154
static func runAtStart(){
150155
// clear not available
151156
V2rayServer.clearItems()
152-
157+
153158
// install before launch
154159
V2rayLaunch.install()
155160

@@ -318,6 +323,17 @@ class V2rayLaunch: NSObject {
318323
}
319324
}
320325

326+
static func checkV2rayCore() {
327+
if !FileManager.default.fileExists(atPath: v2rayCoreFile) {
328+
print("\(v2rayCoreFile) not exists,need install")
329+
self.install()
330+
}
331+
if !FileManager.default.isExecutableFile(atPath: v2rayCoreFile) {
332+
print("\(v2rayCoreFile) not accessable")
333+
self.install()
334+
}
335+
}
336+
321337
static func setSystemProxy(mode: RunMode) {
322338
self.checkV2rayUTool()
323339

0 commit comments

Comments
 (0)