Skip to content

Commit

Permalink
Can exclude domain names (note: just domain names). Closes #5 if that…
Browse files Browse the repository at this point in the history
…'s ok.
  • Loading branch information
Marco Filetti committed Dec 14, 2015
1 parent d910456 commit 37aa0eb
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 19 deletions.
185 changes: 171 additions & 14 deletions JustUsed/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions JustUsed/DiMe Data/HistoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ class HistoryManager: NSObject, RecentDocumentUpdateDelegate, BrowserHistoryUpda

func newHistoryItems(newURLs: [BrowserHistItem]) {
for newURL in newURLs {
let infoElem = DocumentInformationElement(fromSafariHist: newURL)
let event = DesktopEvent(infoElem: infoElem, ofType: TrackingType.Browser(newURL.browser), withDate: newURL.date, andLocation: newURL.location)
sendToDiMe(event)
if !newURL.excludedFromDiMe {
let infoElem = DocumentInformationElement(fromSafariHist: newURL)
let event = DesktopEvent(infoElem: infoElem, ofType: TrackingType.Browser(newURL.browser), withDate: newURL.date, andLocation: newURL.location)
sendToDiMe(event)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions JustUsed/Model/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
defaultPrefs[JustUsedConstants.prefDiMeServerURL] = "http://localhost:8080/api"
defaultPrefs[JustUsedConstants.prefDiMeServerUserName] = "Test1"
defaultPrefs[JustUsedConstants.prefDiMeServerPassword] = "123456"
let defaultExcludeDomains = ["localhost", "talkgadget.google.com"]
defaultPrefs[JustUsedConstants.prefExcludeDomains] = defaultExcludeDomains
defaultPrefs[JustUsedConstants.prefSendPlainTexts] = 1
defaultPrefs[JustUsedConstants.prefSendSafariHistory] = 1
NSUserDefaults.standardUserDefaults().registerDefaults(defaultPrefs)
Expand Down
22 changes: 22 additions & 0 deletions JustUsed/Model/GenericBrowserHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ struct BrowserHistItem: Equatable {
let url: String
let title: String?
let location: Location?
let excludedFromDiMe: Bool

init(browser: BrowserType, date: NSDate, url: String, title: String?, location: Location?) {
self.browser = browser
self.date = date
self.url = url
self.title = title
self.location = location

// Set excluded property if url's domain is in exclude list
if let url = NSURL(string: self.url), domain = url.host {
let excludeDomains = NSUserDefaults.standardUserDefaults().valueForKey(JustUsedConstants.prefExcludeDomains) as! [String]
let filteredDomains = excludeDomains.filter({domain.rangeOfString($0) != nil})
if filteredDomains.count > 0 {
excludedFromDiMe = true
} else {
excludedFromDiMe = false
}
} else {
excludedFromDiMe = false
}
}
}

func ==(lhs: BrowserHistItem, rhs: BrowserHistItem) -> Bool {
Expand Down
24 changes: 23 additions & 1 deletion JustUsed/UI/DiMePreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,29 @@ class DiMePreferencesViewController: NSViewController {
// similar set here
sendSafariHistCell.bind("value", toObject: NSUserDefaultsController.sharedUserDefaultsController(), withKeyPath: "values." + JustUsedConstants.prefSendSafariHistory, options: options)

logsPathLabel.stringValue = AppSingleton.logsURL.path ?? "<nil>"
logsPathLabel.stringValue = AppSingleton.logsURL.path ?? "<Nothing logged so far>"

}

/// Domain names
@IBOutlet weak var userDefaultsAC: NSArrayController!
@IBOutlet weak var domainsTable: NSTableView!
@IBOutlet weak var newDomainField: NSTextField!

@IBAction func removeButtonPress(sender: NSButton) {
if domainsTable.selectedRow != -1 {
userDefaultsAC.removeObjectAtArrangedObjectIndex(domainsTable.selectedRow)
}
}

@IBAction func addButtonPress(sender: NSButton) {
let newVal = newDomainField.stringValue.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
if newVal.characters.count > 0 {
let cont = userDefaultsAC.content as! [String]
if cont.indexOf(newVal) == nil {
userDefaultsAC.addObject(newVal)
}
newDomainField.stringValue = ""
}
}
}
2 changes: 2 additions & 0 deletions JustUsed/UI/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class BrowserTrackerDataSource: NSObject, NSTableViewDataSource {
} else {
return JustUsedConstants.kUnkownLocationString
}
} else if tableColumn!.identifier == JustUsedConstants.kBHistoryExcluded {
return allHistory[row].excludedFromDiMe ? "Yes" : "No"
} else {
return allHistory[row].url
}
Expand Down
5 changes: 5 additions & 0 deletions JustUsed/Utils/JustUsedConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class JustUsedConstants {
static let kMimeType = "Mime type"
static let kLocTitle = "Location description"
static let kBHistoryBrowser = "Browser"
static let kBHistoryExcluded = "Excluded"
static let kBHistoryDate = "URL Visit time"
static let kBHistoryURL = "Visited URL"
static let kBHistoryTitle = "Page title"
static let kMenuImageName = "DiMeTemplate"

// MARK: - Preference identifiers

/// Preference index representing list of excluded domains.
/// - Note: changing this requires manual change in the preferences' array controller
static let prefExcludeDomains = "pref.excludeDomains"

/// URL of the DiMe server (bound in the preferences window)
static let prefDiMeServerURL = "dime.serverinfo.url"

Expand Down
2 changes: 1 addition & 1 deletion Stuff/dmg/makedmg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

# requires PeyeDF.app in the current folder (latest binary)

appdmg appdmg.json PeyeDF.dmg
appdmg appdmg.json "Mac Desktop Tracker.dmg"

0 comments on commit 37aa0eb

Please sign in to comment.