Skip to content

Commit

Permalink
4.2.1 修复配置页面死锁崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Jul 7, 2024
1 parent 2d5030e commit 8036d99
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ target 'V2rayU' do

# Pods for V2rayU
pod 'FirebaseAnalytics', '~> 10.24.0'
pod 'FirebaseCrashlytics'
pod 'SwiftyJSON'/
pod 'FirebaseCrashlytics', '~> 10.24.0'
pod 'SwiftyJSON'
# master branch
pod 'Preferences', :git => 'https://github.com/sindresorhus/Preferences.git'
pod 'QRCoder'
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PODS:

DEPENDENCIES:
- FirebaseAnalytics (~> 10.24.0)
- FirebaseCrashlytics
- FirebaseCrashlytics (~> 10.24.0)
- MASShortcut
- Preferences (from `https://github.com/sindresorhus/Preferences.git`)
- QRCoder
Expand Down Expand Up @@ -178,6 +178,6 @@ SPEC CHECKSUMS:
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
Yams: e10dae147f517ed57ecae37c5e8681bdf8fcab65

PODFILE CHECKSUM: d61ad825ad5d61b2b98237544e21946c9babe3a0
PODFILE CHECKSUM: 94ab23e73805bd5279654adc5ea4b4c31f94b8af

COCOAPODS: 1.15.2
4 changes: 2 additions & 2 deletions V2rayU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -886,7 +886,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
33 changes: 16 additions & 17 deletions V2rayU/ConfigWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
// add
V2rayServer.add()

DispatchQueue.main.sync {
DispatchQueue.main.async {
V2rayServer.loadConfig()
// reload data
self.serversTableView.reloadData()
Expand All @@ -187,7 +187,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel

// delete server config
case 1:
DispatchQueue.main.sync {
DispatchQueue.main.async {
// get seleted index
let idx = self.serversTableView.selectedRow
// remove
Expand Down Expand Up @@ -562,7 +562,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel

v2rayConfig.parseJson(jsonText: self.configText.string)
if v2rayConfig.errors.count > 0 {
DispatchQueue.main.sync {
DispatchQueue.main.async {
self.errTip.stringValue = v2rayConfig.errors[0]
}
}
Expand All @@ -579,7 +579,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
}
self.refreshServerList(ok: errMsg.count == 0)
} else {
DispatchQueue.main.sync {
DispatchQueue.main.async {
self.errTip.stringValue = errMsg
}
}
Expand Down Expand Up @@ -898,27 +898,27 @@ extension ConfigWindowController: NSTableViewDataSource {
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
let v2rayItemList = V2rayServer.list()
// set cell data
if v2rayItemList.count >= row {
if row < v2rayItemList.count {
return v2rayItemList[row].remark
}
return nil
}

// edit cell
func tableView(_ tableView: NSTableView, setObjectValue: Any?, for forTableColumn: NSTableColumn?, row: Int) {
func tableView(_ tableView: NSTableView, setObjectValue: Any?, for tableColumn: NSTableColumn?, row: Int) {
guard let remark = setObjectValue as? String else {
NSLog("remark is nil")
return
}
DispatchQueue.global().async {
// edit item remark
V2rayServer.edit(rowIndex: row, remark: remark)
// reload table
// reload table on main thread
DispatchQueue.main.async {
tableView.reloadData()
// reload menu
menuController.showServers()
}
// reload menu
menuController.showServers()
}
}
}
Expand All @@ -942,25 +942,24 @@ extension ConfigWindowController: NSTableViewDelegate {
if dropOperation == .above {
return .move
}
return NSDragOperation()
return []
}

func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
var oldIndexes = [Int]()
info.enumerateDraggingItems(options: [], for: tableView, classes: [NSPasteboardItem.self], searchOptions: [:], using: {
(draggingItem: NSDraggingItem, idx: Int, stop: UnsafeMutablePointer<ObjCBool>) in
info.enumerateDraggingItems(options: [], for: tableView, classes: [NSPasteboardItem.self], searchOptions: [:]) { (draggingItem, _, _) in
if let str = (draggingItem.item as! NSPasteboardItem).string(forType: NSPasteboard.PasteboardType(rawValue: self.tableViewDragType)),
let index = Int(str) {
oldIndexes.append(index)
}
})
}

var oldIndexOffset = 0
var newIndexOffset = 0
var oldIndexLast = 0
var newIndexLast = 0

// For simplicity, the code below uses `tableView.moveRowAtIndex` to move rows around directly.
// For simplicity, the code below uses `tableView.moveRow(at:to:)` to move rows around directly.
// You may want to move rows in your content array and then call `tableView.reloadData()` instead.
for oldIndex in oldIndexes {
if oldIndex < row {
Expand All @@ -978,12 +977,12 @@ extension ConfigWindowController: NSTableViewDelegate {
V2rayServer.move(oldIndex: oldIndexLast, newIndex: newIndexLast)
DispatchQueue.main.async {
// set selected
self.serversTableView.selectRowIndexes(NSIndexSet(index: newIndexLast) as IndexSet, byExtendingSelection: false)
self.serversTableView.selectRowIndexes(IndexSet(integer: newIndexLast), byExtendingSelection: false)
// reload table
self.serversTableView.reloadData()
// reload menu
menuController.showServers()
}
// reload menu
menuController.showServers()
}
return true
}
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/Preference/PreferenceRouting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final class PreferenceRoutingViewController: NSViewController, PreferencePane, N
// add
V2rayRoutings.add(remark: "new-rule", json: V2rayRoutings.default_rule_content)

DispatchQueue.main.sync {
DispatchQueue.main.async {
V2rayRoutings.loadConfig()
// reload data
self.routingsTableView.reloadData()
Expand All @@ -103,7 +103,7 @@ final class PreferenceRoutingViewController: NSViewController, PreferencePane, N

// delete server config
case 1:
DispatchQueue.main.sync {
DispatchQueue.main.async {
// get seleted index
let idx = self.routingsTableView.selectedRow
// remove
Expand Down

0 comments on commit 8036d99

Please sign in to comment.