Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Importing AppleEvents, remove old executables before importing new on…
…es, clean up
  • Loading branch information
adku committed Aug 29, 2019
commit 5847eadf2800f6a8e78785fe97e21a178f926ad8
13 changes: 13 additions & 0 deletions Source/Model/AppleEventRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@ class AppleEventRule: NSObject {

var value: Bool { return valueString == "Allow" }

override init() {
super.init()
}

init(source: Executable, destination: Executable, value: Bool) {
self.source = source
self.destination = destination
if value{
valueString = "Allow"
} else {
valueString = "Deny"
}
}
}
31 changes: 24 additions & 7 deletions Source/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,28 @@ extension Model {
}

func importProfile(tccProfile: TCCProfile) {

if let content = tccProfile.content.first {

for (_, policies) in content.services {
getExecutablesFromAllPolicies(policies: policies)
}
self.removeExecutables()

for (key, policies) in content.services {
getExecutablesFromAllPolicies(policies: policies)

for policy in policies {
let executable = getExecutable(bundleIdentifier: policy.identifier)
if policy.allowed {
executable?.policy.setValue("Allow", forKey: key)
if key == ServicesKeys.appleEvents.rawValue {
if let source = executable, let receiverIdentifier = policy.receiverIdentifier,
let destination = findExecutableUsing(bundleIdentifier: receiverIdentifier) {

let appleEvent = AppleEventRule(source: source, destination: destination, value: policy.allowed)
executable?.appleEvents.append(appleEvent)
}
} else {
executable?.policy.setValue("Deny", forKey: key)
if policy.allowed {
executable?.policy.setValue("Allow", forKey: key)
} else {
executable?.policy.setValue("Deny", forKey: key)
}
}
}
}
Expand Down Expand Up @@ -222,4 +230,13 @@ extension Model {
}
return nil
}

func removeExecutables() {
for executable in self.selectedExecutables {
executable.appleEvents = []
executable.policy = Policy()
}
self.selectedExecutables = []
self.current = nil
}
}