Commit 5a9cdfe2 authored by Gregor Longariva's avatar Gregor Longariva 💬
Browse files

using appDelegate instance instead of reintializing Mounter class

parent 5626d662
......@@ -42,7 +42,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
//
// initalize class which will perform all the automounter tasks
let mounter = self.mounter
self.mountpath = mounter.mountpath
//
......@@ -75,7 +74,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let netConnection = Monitor.shared
let status = netConnection.netOn
NSLog("Current Network Path is \(status)")
mounter.mountShares()
self.mounter.mountShares()
})
}
......@@ -83,7 +82,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
//
// unmount all shares befor leaving
if userDefaults.bool(forKey: "unmountOnExit") == true {
mounter.unmountAllShares()
self.mounter.unmountAllShares()
}
//
// end network monitoring
......@@ -141,7 +140,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem(title: NSLocalizedString("About Network Share Mounter", comment: "About Network Share Mounter"),
action: #selector(AppDelegate.openHelpURL(_:)), keyEquivalent: ""))
}
// menu.addItem(NSMenuItem(title: NSLocalizedString("Network Share Mounter", comment: "Info"), action: #selector(AppDelegate.showInfo(_:)), keyEquivalent: "P"))
menu.addItem(NSMenuItem(title: NSLocalizedString("Mount shares", comment: "Mount shares"),
action: #selector(AppDelegate.mountManually(_:)), keyEquivalent: "m"))
menu.addItem(NSMenuItem(title: NSLocalizedString("Unmount shares", comment: "Unmount shares"),
......
......@@ -51,7 +51,7 @@ class Mounter {
init() {
// create subfolder in home to mount shares in
if let userDefaultsLocation = userDefaults.string(forKey: "location") {
if userDefaults.string(forKey: "location") != nil {
self.mountpath = NSString(string: userDefaults.string(forKey: "location")!).expandingTildeInPath
} else {
self.mountpath = NSString(string: "~/\(self.localizedFolder)").expandingTildeInPath
......@@ -132,10 +132,10 @@ extension Mounter {
// if directory is a regular directory go on
if !isDirectoryFilesystemMount(atPath: path.appendingPathComponent(filePath)) {
//
// Clean up directories only if defined in userdefaults
// Clean up the directory containing the mounts only if defined in userdefaults
if userDefaults.bool(forKey: "cleanupLocationDirectory") == true {
//
// if the function has a parameter we want ot handle files
// if the function has a parameter we want to handle files
if let unwrappedFilename = filename {
if !isDirectoryFilesystemMount(atPath: path.appendingPathComponent(filePath)) {
let deleteFile = path.appendingPathComponent(filePath).appendingPathComponent(unwrappedFilename)
......
......@@ -14,8 +14,8 @@ class NetworkShareMounterViewController: NSViewController {
let userDefaults = UserDefaults.standard
@objc dynamic var launchAtLogin = LaunchAtLogin.kvo
// let customshares = UserDefaults(suiteName: config.defaultsDomain)?.array(forKey: "customNetworkShares") as? [String] ?? []
let appDelegate = NSApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
......@@ -60,9 +60,8 @@ class NetworkShareMounterViewController: NSViewController {
if shareArray.contains(shareString) {
NSLog("\(shareString) is already in list of user's customNetworkShares")
} else {
let mounter = Mounter.init()
do {
try mounter.doTheMount(forShare: usersNewShare.stringValue)
try appDelegate.mounter.doTheMount(forShare: usersNewShare.stringValue)
shareArray.append(usersNewShare.stringValue)
userDefaults.set(shareArray, forKey: "customNetworkShares")
usersNewShare.stringValue=""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment