forked from alvincrisuy/clashX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: optimize config refresh strategy
- Loading branch information
1 parent
a0a246b
commit 69e344b
Showing
12 changed files
with
210 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// ProxyDelayHistoryMenu.swift | ||
// ClashX | ||
// | ||
// Created by yicheng on 2020/4/25. | ||
// Copyright © 2020 west2online. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import FlexibleDiff | ||
|
||
class ProxyDelayHistoryMenu: NSMenu { | ||
var currentHistory: [ClashProxySpeedHistory]? | ||
|
||
init(proxy: ClashProxy) { | ||
super.init(title: "") | ||
updateHistoryMenu(proxy: proxy) | ||
NotificationCenter.default.addObserver(self, selector: #selector(proxyInfoDidUpdate(note:)), name: .proxyUpdate(for: proxy.name), object: nil) | ||
} | ||
|
||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
deinit { | ||
NotificationCenter.default.removeObserver(self) | ||
} | ||
|
||
@objc private func proxyInfoDidUpdate(note: Notification) { | ||
guard let info = note.object as? ClashProxy else { return } | ||
updateHistoryMenu(proxy: info) | ||
} | ||
|
||
private func updateHistoryMenu(proxy: ClashProxy) { | ||
let historys = Array(proxy.history.reversed()) | ||
let change = Changeset(previous: currentHistory, current: historys, identifier: { $0.time }) | ||
currentHistory = historys | ||
if change.moves.count == 0 && change.mutations.count == 0 { | ||
change.removals.reversed().forEach { idx in | ||
removeItem(at: idx) | ||
} | ||
change.inserts.forEach { idx in | ||
let his = historys[idx] | ||
let item = NSMenuItem(title: his.displayString, action: nil, keyEquivalent: "") | ||
insertItem(item, at: idx) | ||
} | ||
} else { | ||
historys.map { his in | ||
NSMenuItem(title: his.displayString, action: nil, keyEquivalent: "") | ||
}.forEach { item in | ||
addItem(item) | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension ClashProxySpeedHistory: Equatable { | ||
static func == (lhs: ClashProxySpeedHistory, rhs: ClashProxySpeedHistory) -> Bool { | ||
return lhs.displayString == rhs.displayString | ||
} | ||
} |
Oops, something went wrong.