forked from wzdnzd/ShadowsocksX-NG-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRulesController.swift
More file actions
53 lines (44 loc) · 1.75 KB
/
UserRulesController.swift
File metadata and controls
53 lines (44 loc) · 1.75 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
//
// UserRulesController.swift
// ShadowsocksX-NG
//
// Created by 周斌佳 on 16/8/1.
// Copyright © 2016年 qiuyuzhou. All rights reserved.
//
import Cocoa
class UserRulesController: NSWindowController {
@IBOutlet var userRulesView: NSTextView!
override func windowDidLoad() {
super.windowDidLoad()
let fileMgr = FileManager.default
if !fileMgr.fileExists(atPath: PACUserRuleFilePath) {
let src = Bundle.main.path(forResource: "user-rule", ofType: "txt")
try! fileMgr.copyItem(atPath: src!, toPath: PACUserRuleFilePath)
}
let str = try? String(contentsOfFile: PACUserRuleFilePath, encoding: String.Encoding.utf8)
userRulesView.string = str ?? ""
}
@IBAction func didCancel(_ sender: AnyObject) {
window?.performClose(self)
}
@IBAction func didOK(_ sender: AnyObject) {
if let str = userRulesView?.string {
do {
try str.data(using: String.Encoding.utf8)?.write(to: URL(fileURLWithPath: PACUserRuleFilePath), options: .atomic)
if GeneratePACFile() {
// Popup a user notification
let notification = NSUserNotification()
notification.title = "PAC has been updated by User Rules.".localized
NSUserNotificationCenter.default
.deliver(notification)
} else {
let notification = NSUserNotification()
notification.title = "It's failed to update PAC by User Rules.".localized
NSUserNotificationCenter.default
.deliver(notification)
}
} catch {}
}
window?.performClose(self)
}
}