@@ -20,8 +20,36 @@ struct MailPluginManager {
20
20
21
21
let pluginURL = FileManager . default. homeDirectoryForCurrentUser. appendingPathComponent ( " Library/Mail/Bundles " ) . appendingPathComponent ( mailBundleName + " .mailbundle " )
22
22
23
+ let localPluginURL = Bundle . main. url ( forResource: mailBundleName, withExtension: " mailbundle " ) !
24
+
23
25
var isMailPluginInstalled : Bool {
24
- return FileManager . default. fileExists ( atPath: pluginURL. path)
26
+ //Check if the plug-in is compatible by comparing the IDs
27
+ guard FileManager . default. fileExists ( atPath: pluginURL. path) else {
28
+ return false
29
+ }
30
+
31
+ let infoPlistURL = pluginURL. appendingPathComponent ( " Contents/Info.plist " )
32
+ let localInfoPlistURL = localPluginURL. appendingPathComponent ( " Contents/Info.plist " )
33
+
34
+ guard let infoPlistData = try ? Data ( contentsOf: infoPlistURL) ,
35
+ let infoPlistDict = try ? PropertyListSerialization . propertyList ( from: infoPlistData, options: [ ] , format: nil ) as? [ String : AnyHashable ] ,
36
+ let localInfoPlistData = try ? Data ( contentsOf: localInfoPlistURL) ,
37
+ let localInfoPlistDict = try ? PropertyListSerialization . propertyList ( from: localInfoPlistData, options: [ ] , format: nil ) as? [ String : AnyHashable ]
38
+ else { return false }
39
+
40
+ //Compare the supported plug-ins
41
+ let uuidEntries = localInfoPlistDict. keys. filter ( { $0. contains ( " PluginCompatibilityUUIDs " ) } )
42
+ for uuidEntry in uuidEntries {
43
+ guard let localEntry = localInfoPlistDict [ uuidEntry] as? [ String ] ,
44
+ let installedEntry = infoPlistDict [ uuidEntry] as? [ String ]
45
+ else { return false }
46
+
47
+ if localEntry != installedEntry {
48
+ return false
49
+ }
50
+ }
51
+
52
+ return true
25
53
}
26
54
27
55
/// Shows a NSSavePanel to install the mail plugin at the required place.
@@ -58,9 +86,12 @@ struct MailPluginManager {
58
86
throw PluginError . permissionNotGranted
59
87
}
60
88
61
- let localPluginURL = Bundle . main. url ( forResource: mailBundleName, withExtension: " mailbundle " ) !
62
-
63
89
do {
90
+ //Remove old plug-ins first
91
+ if FileManager . default. fileExists ( atPath: pluginURL. path) {
92
+ try FileManager . default. removeItem ( at: pluginURL)
93
+ }
94
+
64
95
try FileManager . default. createDirectory ( at: pluginsFolderURL, withIntermediateDirectories: true , attributes: nil )
65
96
} catch {
66
97
print ( error. localizedDescription)
0 commit comments