Skip to content

Commit

Permalink
Add Edge / IE
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryHuangHD committed Dec 26, 2020
1 parent 89d6984 commit c29b19d
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 26 deletions.
16 changes: 12 additions & 4 deletions UserAgency.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

/* Begin PBXBuildFile section */
D8250FE5259335ED00B88649 /* Mac.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FE4259335ED00B88649 /* Mac.swift */; };
D8250FE9259335FC00B88649 /* PC.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FE8259335FC00B88649 /* PC.swift */; };
D8250FE9259335FC00B88649 /* WindowsPC.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FE8259335FC00B88649 /* WindowsPC.swift */; };
D8250FED2593360B00B88649 /* AndroidPhone.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FEC2593360B00B88649 /* AndroidPhone.swift */; };
D8250FF1259336C600B88649 /* Chrome.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FF0259336C600B88649 /* Chrome.swift */; };
D8250FF5259336DD00B88649 /* Firefox.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8250FF4259336DD00B88649 /* Firefox.swift */; };
D85BFE512594912C0051F637 /* AndroidPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85BFE502594912C0051F637 /* AndroidPad.swift */; };
D85BFE55259491680051F637 /* iPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85BFE54259491680051F637 /* iPad.swift */; };
D86742392597EB2000E0B65E /* Edge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86742382597EB2000E0B65E /* Edge.swift */; };
D867423D2597EC5D00E0B65E /* IE.swift in Sources */ = {isa = PBXBuildFile; fileRef = D867423C2597EC5D00E0B65E /* IE.swift */; };
D899BEBA2591DA4C004390B1 /* UserAgency.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D899BEB02591DA4C004390B1 /* UserAgency.framework */; };
D899BEBF2591DA4C004390B1 /* UserAgencyBaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D899BEBE2591DA4C004390B1 /* UserAgencyBaseTests.swift */; };
D899BEC12591DA4C004390B1 /* UserAgency.h in Headers */ = {isa = PBXBuildFile; fileRef = D899BEB32591DA4C004390B1 /* UserAgency.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -66,12 +68,14 @@

/* Begin PBXFileReference section */
D8250FE4259335ED00B88649 /* Mac.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mac.swift; sourceTree = "<group>"; };
D8250FE8259335FC00B88649 /* PC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PC.swift; sourceTree = "<group>"; };
D8250FE8259335FC00B88649 /* WindowsPC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowsPC.swift; sourceTree = "<group>"; };
D8250FEC2593360B00B88649 /* AndroidPhone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AndroidPhone.swift; sourceTree = "<group>"; };
D8250FF0259336C600B88649 /* Chrome.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Chrome.swift; sourceTree = "<group>"; };
D8250FF4259336DD00B88649 /* Firefox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Firefox.swift; sourceTree = "<group>"; };
D85BFE502594912C0051F637 /* AndroidPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AndroidPad.swift; sourceTree = "<group>"; };
D85BFE54259491680051F637 /* iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iPad.swift; sourceTree = "<group>"; };
D86742382597EB2000E0B65E /* Edge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Edge.swift; sourceTree = "<group>"; };
D867423C2597EC5D00E0B65E /* IE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IE.swift; sourceTree = "<group>"; };
D899BEB02591DA4C004390B1 /* UserAgency.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UserAgency.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D899BEB32591DA4C004390B1 /* UserAgency.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserAgency.h; sourceTree = "<group>"; };
D899BEB42591DA4C004390B1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -194,7 +198,7 @@
D8F0C43F2591F1FB005088E5 /* iPhone.swift */,
D85BFE54259491680051F637 /* iPad.swift */,
D8250FE4259335ED00B88649 /* Mac.swift */,
D8250FE8259335FC00B88649 /* PC.swift */,
D8250FE8259335FC00B88649 /* WindowsPC.swift */,
);
path = UserDevice;
sourceTree = "<group>";
Expand All @@ -206,6 +210,8 @@
D8250FF0259336C600B88649 /* Chrome.swift */,
D8250FF4259336DD00B88649 /* Firefox.swift */,
D8F0C4432591F5FC005088E5 /* Safari.swift */,
D86742382597EB2000E0B65E /* Edge.swift */,
D867423C2597EC5D00E0B65E /* IE.swift */,
);
path = UserApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -357,13 +363,15 @@
D85BFE512594912C0051F637 /* AndroidPad.swift in Sources */,
D8250FE5259335ED00B88649 /* Mac.swift in Sources */,
D8250FF5259336DD00B88649 /* Firefox.swift in Sources */,
D8250FE9259335FC00B88649 /* PC.swift in Sources */,
D86742392597EB2000E0B65E /* Edge.swift in Sources */,
D8250FE9259335FC00B88649 /* WindowsPC.swift in Sources */,
D8F0C4382591F0E7005088E5 /* UserDevice.swift in Sources */,
D8F0C4402591F1FB005088E5 /* iPhone.swift in Sources */,
D8250FF1259336C600B88649 /* Chrome.swift in Sources */,
D8F0C4272591E67A005088E5 /* UserAgency.swift in Sources */,
D8F0C4442591F5FC005088E5 /* Safari.swift in Sources */,
D85BFE55259491680051F637 /* iPad.swift in Sources */,
D867423D2597EC5D00E0B65E /* IE.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions UserAgency/UserAgency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class UserAgency {
public init() {
}

public func setUserApp(_ app: UserApp?) -> UserAgency {
public func setApp(_ app: UserApp?) -> UserAgency {
userApp = app
return self
}

public func setUserDevice(_ device: UserDevice?) -> UserAgency {
public func setDevice(_ device: UserDevice?) -> UserAgency {
userDevice = device
return self
}
Expand Down
10 changes: 5 additions & 5 deletions UserAgency/UserApp/Chrome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class Chrome: UserApp {

/*
// iPhone / iPad
AppleWebKit/{$layoutEngine_iOS} (KHTML, like Gecko) CriOS/{softwareVersion} Mobile/{$build_iOS} Safari/{$layoutEngine_iOS}
AppleWebKit/{$layoutEngine_iOS} (KHTML, like Gecko) CriOS/{$softwareVersion} Mobile/{$build_iOS} Safari/{$layoutEngine_iOS}
// Android Phone / Tablet
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{softwareVersion} Mobile Safari/{$layoutEngine}
// Mac / PC
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{softwareVersion} Safari/{$layoutEngine}
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{$softwareVersion} Mobile Safari/{$layoutEngine}
// Mac / WindowsPC
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{$softwareVersion} Safari/{$layoutEngine}
*/

public init() {
Expand Down Expand Up @@ -51,7 +51,7 @@ public class Chrome: UserApp {
}

if userDevice is Mac
|| userDevice is PC {
|| userDevice is WindowsPC {
return String(format: "AppleWebKit/%@ (KHTML, like Gecko) Chrome/%@ Safari/%@",
arguments: [layoutEngine,
softwareVersion,
Expand Down
73 changes: 73 additions & 0 deletions UserAgency/UserApp/Edge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Edge.swift
// UserAgency
//
// Created by Terry Huang on 2020/12/27.
//

import Foundation

public class Edge: UserApp {
weak var userDevice: UserDevice?

var layoutEngine_iOS = "605.1.15"
var version_iOS = "14.0"
var build_iOS = "15E148"

var softwareVersion_Chrome = "87.0.4280.101"

var layoutEngine = "537.36"
var softwareVersion = "45.12.24.5121"

/*
// iPhone / iPad
AppleWebKit/{$layoutEngine_iOS} (KHTML, like Gecko) Version/{$version_iOS} EdgiOS/{$softwareVersion} Mobile/{$build_iOS} Safari/{$layoutEngine_iOS}
// Android Phone / Tablet
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{$softwareVersion_Chrome} Mobile Safari/{$layoutEngine_iOS} EdgA/{$softwareVersion}
// Mac / WindowsPC
AppleWebKit/{$layoutEngine} (KHTML, like Gecko) Chrome/{$softwareVersion_Chrome} Safari/{$layoutEngine} Edg/{$softwareVersion_Chrome}
*/

public init() {
}

public func setUserDevice(_ device: UserDevice?) {
userDevice = device
}

public func getResultSystemInformation() -> String {
return ""
}

public func getResultPlatform() -> String {
if userDevice == nil {
return ""
}

if userDevice is iPhone
|| userDevice is iPad {
return String(format: "AppleWebKit/%@ (KHTML, like Gecko) Version/%@ EdgiOS/%@ Mobile/%@ Safari/%@",
arguments: [layoutEngine_iOS,
version_iOS,
softwareVersion,
build_iOS,
layoutEngine_iOS])
}

if userDevice is Mac
|| userDevice is WindowsPC {
return String(format: "AppleWebKit/%@ (KHTML, like Gecko) Chrome/%@ Safari/%@ Edg/%@",
arguments: [layoutEngine,
softwareVersion_Chrome,
layoutEngine,
softwareVersion_Chrome])
}

return String(format: "AppleWebKit/%@ (KHTML, like Gecko) Chrome/%@ Mobile Safari/%@ EdgA/%@",
arguments: [layoutEngine,
softwareVersion_Chrome,
layoutEngine_iOS,
softwareVersion])
}
}

6 changes: 3 additions & 3 deletions UserAgency/UserApp/Firefox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Firefox: UserApp {
// Android Phone / Tablet
; rv:{$softwareVersion}
Gecko/{$softwareVersion} Firefox/{$softwareVersion}
// Mac / PC
// Mac / WindowsPC
; rv:{$softwareVersion}
Gecko/{$geckoVersion_PC_Mac} Firefox/{$softwareVersion}
*/
Expand All @@ -43,7 +43,7 @@ public class Firefox: UserApp {
if userDevice is AndroidPhone
|| userDevice is AndroidPad
|| userDevice is Mac
|| userDevice is PC {
|| userDevice is WindowsPC {
return String(format: "; rv:%@",
arguments: [softwareVersion])
}
Expand All @@ -66,7 +66,7 @@ public class Firefox: UserApp {
}

if userDevice is Mac
|| userDevice is PC {
|| userDevice is WindowsPC {
return String(format: "Gecko/%@ Firefox/%@",
arguments: [geckoVersion_PC_Mac,
softwareVersion])
Expand Down
42 changes: 42 additions & 0 deletions UserAgency/UserApp/IE.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// IE.swift
// UserAgency
//
// Created by Terry Huang on 2020/12/27.
//

import Foundation

public class IE: UserApp {
weak var userDevice: UserDevice?

var layoutEngine = "7.0"
var softwareVersion = "11.0"

/*
// WindowsPC
; Trident/{$layoutEngine}; rv:{$softwareVersion}
like Gecko
*/

public init() {
}

public func setUserDevice(_ device: UserDevice?) {
userDevice = device
}

public func getResultSystemInformation() -> String {
return String(format: "; Trident/%@; rv:%@",
arguments: [layoutEngine,
softwareVersion])
}

public func getResultPlatform() -> String {
if userDevice == nil {
return ""
}

return "like Gecko"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public class PC: UserDevice {
public class WindowsPC: UserDevice {
weak var userApp: UserApp?

var osVersion = "10.0"
Expand Down
16 changes: 8 additions & 8 deletions UserAgencyExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ class ViewController: UIViewController {
// Do any additional setup after loading the view.

print(UserAgency()
.setUserDevice(iPhone())
.setUserApp(Safari())
.setDevice(iPhone())
.setApp(Safari())
.getString())

print(UserAgency()
.setUserDevice(Mac())
.setUserApp(Firefox())
.setDevice(Mac())
.setApp(Firefox())
.getString())

print(UserAgency()
.setUserDevice(PC())
.setUserApp(Chrome())
.setDevice(WindowsPC())
.setApp(Chrome())
.getString())

print(UserAgency()
.setUserDevice(AndroidPhone())
.setUserApp(Chrome())
.setDevice(AndroidPhone())
.setApp(Chrome())
.getString())
}
}
Expand Down
2 changes: 1 addition & 1 deletion UserAgencyTests/UserAgencyBaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UserAgencyTests: XCTestCase {
iPhone(),
iPad(),
Mac(),
PC()
WindowsPC()
]

allApp = [
Expand Down
4 changes: 2 additions & 2 deletions UserAgencyTests/UserAgencySafariTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UserAgencySafariTests: XCTestCase {
}

func test_iPhone() throws {
agent?.setUserDevice(iphone).setUserApp(safari)
agent?.setUserDevice(iphone).setApp(safari)

XCTAssertTrue(agent!.getString().contains("iPhone OS"))
XCTAssertTrue(agent!.getString().contains("like Mac OS X"))
Expand All @@ -36,7 +36,7 @@ class UserAgencySafariTests: XCTestCase {
}

func test_Mac() throws {
agent?.setUserDevice(mac).setUserApp(safari)
agent?.setUserDevice(mac).setApp(safari)

XCTAssertTrue(agent!.getString().contains("Macintosh"))
XCTAssertTrue(agent!.getString().contains("Mac OS X"))
Expand Down

0 comments on commit c29b19d

Please sign in to comment.