Browse Source

Demo - 暗黑模式完全自適應;列表中照片对比结果呈现(数值部分)

zhudongyong 2 years ago
parent
commit
b281cc24ec

+ 12 - 0
KdanAutoTest/KdanAuto.xcodeproj/project.pbxproj

@@ -22,6 +22,7 @@
 		24A6FF4B2930939D00B34F2E /* TextColorAutoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A6FF4A2930939D00B34F2E /* TextColorAutoTest.swift */; };
 		24A6FF4F2930A1E100B34F2E /* FontAutoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A6FF4E2930A1E100B34F2E /* FontAutoTest.swift */; };
 		24A6FF512930AC4D00B34F2E /* AutoTestAdvanceSettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A6FF502930AC4D00B34F2E /* AutoTestAdvanceSettingView.swift */; };
+		24AE7B4D298BD98300462BD3 /* CompareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE7B4C298BD98300462BD3 /* CompareViewController.swift */; };
 		24D70000292B6FD100DAB5EE /* SettingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24D7FFFF292B6FD100DAB5EE /* SettingViewController.xib */; };
 		24D70009292D14DA00DAB5EE /* AutoTestProtocal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24D70008292D14DA00DAB5EE /* AutoTestProtocal.swift */; };
 		24D7000B292D16BB00DAB5EE /* StringAutoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24D7000A292D16BB00DAB5EE /* StringAutoTest.swift */; };
@@ -113,6 +114,7 @@
 		24A6FF4A2930939D00B34F2E /* TextColorAutoTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextColorAutoTest.swift; sourceTree = "<group>"; };
 		24A6FF4E2930A1E100B34F2E /* FontAutoTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontAutoTest.swift; sourceTree = "<group>"; };
 		24A6FF502930AC4D00B34F2E /* AutoTestAdvanceSettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoTestAdvanceSettingView.swift; sourceTree = "<group>"; };
+		24AE7B4C298BD98300462BD3 /* CompareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompareViewController.swift; sourceTree = "<group>"; };
 		24D70001292B71FB00DAB5EE /* KdanAutoDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KdanAutoDebug.entitlements; sourceTree = "<group>"; };
 		24D70008292D14DA00DAB5EE /* AutoTestProtocal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoTestProtocal.swift; sourceTree = "<group>"; };
 		24D7000A292D16BB00DAB5EE /* StringAutoTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringAutoTest.swift; sourceTree = "<group>"; };
@@ -233,6 +235,14 @@
 			path = ActivityView;
 			sourceTree = "<group>";
 		};
+		24AE7B4B298BD97300462BD3 /* CompareViewController */ = {
+			isa = PBXGroup;
+			children = (
+				24AE7B4C298BD98300462BD3 /* CompareViewController.swift */,
+			);
+			path = CompareViewController;
+			sourceTree = "<group>";
+		};
 		24D70002292B94A100DAB5EE /* Norrmal */ = {
 			isa = PBXGroup;
 			children = (
@@ -365,6 +375,7 @@
 				24D7FFFC292B508600DAB5EE /* DataModel */,
 				24D7FFF9292B4FF500DAB5EE /* Setting */,
 				2451F58C2952E5850049FA9C /* FileConverter.swift */,
+				24AE7B4B298BD97300462BD3 /* CompareViewController */,
 			);
 			path = Class;
 			sourceTree = "<group>";
@@ -647,6 +658,7 @@
 				24D7FFFE292B509000DAB5EE /* DataModel.swift in Sources */,
 				24D7FF9B29261A6400DAB5EE /* AppDelegate.swift in Sources */,
 				243DACD32940C6E8008A8AA6 /* ActivityView.swift in Sources */,
+				24AE7B4D298BD98300462BD3 /* CompareViewController.swift in Sources */,
 				24D7000B292D16BB00DAB5EE /* StringAutoTest.swift in Sources */,
 				24DCE8A9295046A5004EBA35 /* TestCaseCellView.swift in Sources */,
 				24D7FFFB292B501100DAB5EE /* SettingViewController.swift in Sources */,

BIN
KdanAutoTest/KdanAuto.xcodeproj/project.xcworkspace/xcuserdata/zhudongyong.xcuserdatad/UserInterfaceState.xcuserstate


+ 4 - 4
KdanAutoTest/KdanAuto.xcodeproj/xcuserdata/zhudongyong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -14,8 +14,8 @@
             filePath = "KdanAuto/Class/AutoTestCase/AutoTest.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "562"
-            endingLineNumber = "562"
+            startingLineNumber = "615"
+            endingLineNumber = "615"
             landmarkName = "stringToImage(_:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -46,8 +46,8 @@
             filePath = "KdanAuto/Class/AutoTestCase/AutoTest.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "47"
-            endingLineNumber = "47"
+            startingLineNumber = "50"
+            endingLineNumber = "50"
             landmarkName = "autoTestFor(_:type:)"
             landmarkType = "7">
          </BreakpointContent>

+ 18 - 0
KdanAutoTest/KdanAuto/Assets.xcassets/AdvanceBackgrougColor.colorset/Contents.json

@@ -12,6 +12,24 @@
       },
       "idiom" : "universal"
     },
+    {
+      "appearances" : [
+        {
+          "appearance" : "luminosity",
+          "value" : "light"
+        }
+      ],
+      "color" : {
+        "color-space" : "srgb",
+        "components" : {
+          "alpha" : "1.000",
+          "blue" : "0.925",
+          "green" : "0.925",
+          "red" : "0.925"
+        }
+      },
+      "idiom" : "universal"
+    },
     {
       "appearances" : [
         {

+ 1 - 1
KdanAutoTest/KdanAuto/Base.lproj/Main.storyboard

@@ -280,7 +280,7 @@
                                                     <rect key="frame" x="-100" y="-100" width="475" height="16"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                 </scroller>
-                                                <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="0.9616724738675958" horizontal="NO" id="RDM-Fo-oeX">
+                                                <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="RDM-Fo-oeX">
                                                     <rect key="frame" x="459" y="0.0" width="16" height="113"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                 </scroller>

+ 53 - 0
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -19,6 +19,9 @@ class AutoTest : NSObject, AutoTestProtocal {
     var _type : String = "Others"
     var _extention : String = "rtf"
     
+    var _degree : Double = 0.0
+    var _fileDegree : [Double] = []
+    
     class func autoTestFor(_ fileType:NSString ,type:NSString) -> AutoTest? {
         let key = String(fileType) + "." + String(type)
         
@@ -136,6 +139,10 @@ class AutoTest : NSObject, AutoTestProtocal {
             let checkDirectory = self.checkFileDirectory()
             let originDirectory = self.originFileDirectory()
             let resultDirectory = self.resultFileDirectory()
+            
+            var degree = Double(0);
+            var count = Int(0)
+            
             for fileName in files {
                 let fName = NSString(string: fileName).deletingPathExtension
                 let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
@@ -176,6 +183,9 @@ class AutoTest : NSObject, AutoTestProtocal {
                             items.add(fName)
                         }
                         
+                        var subDegree = Double(0);
+                        var subCount = Int(0)
+                        
                         for item in items {
                             let subFileName = item as! String
                             let subResultPath = NSString(string: resultDirectory).appendingPathComponent(subFileName+"."+_extention)
@@ -205,6 +215,9 @@ class AutoTest : NSObject, AutoTestProtocal {
                                         if fabs(degree-100.0) >= 0.01 {
                                             color = NSColor.red
                                         }
+                                        subDegree += degree
+                                        subCount += 1
+                                        
                                         self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
                                                                                             attributes:[.foregroundColor : color]))
                                     }
@@ -218,6 +231,16 @@ class AutoTest : NSObject, AutoTestProtocal {
                             processThumbSemaphore.wait()
                             
                         }
+                        
+                        if subCount != 0 {
+                            subDegree = subDegree/Double(subCount)
+                        }else {
+                            subDegree = 0.0
+                        }
+                        
+                        _fileDegree.append(subDegree)
+                        degree += subDegree;
+                        count += 1
                     }
                 }else {
                     reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
@@ -225,16 +248,42 @@ class AutoTest : NSObject, AutoTestProtocal {
                 }
             }
             
+            if count != 0 {
+                _degree = degree/Double(count)
+            }else {
+                _degree = 0.0
+            }
+            
             _status = .Finished
         }else {
             _status = .Normal
         }
     }
     
+    
     func testReport() -> NSAttributedString? {
         return reportString
     }
     
+    func degree() -> Double {
+        return _degree
+    }
+    
+//    func testReportOfFile(_ fileName:String) -> NSAttributedString? {
+//        
+//    }
+    
+    func degreeOfFile(_ fileName:String) -> Double {
+        let files = DataModel.shared.originFilesFor(_fileType, type: _type) as [String]
+        
+        let index = files.firstIndex(of: fileName)
+        
+        if index == NSNotFound || index! >= _fileDegree.count {
+            return 0
+        }else {
+            return _fileDegree[index!]
+        }
+    }
     
     //  Image compare
     func compareJPEG(_ resultPath:String, checkPath:String) -> Double {
@@ -540,6 +589,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                 }
             }
         }
+        
+        
+        _degree = 0.0;
+        _fileDegree.removeAll()
     }
 }
 

+ 7 - 0
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTestProtocal.swift

@@ -34,6 +34,13 @@ protocol AutoTestProtocal : NSObjectProtocol {
     func autoTest()
     
     func testReport() -> NSAttributedString?
+    /** Default is 0.0, The range of value is [0, 1]
+     */
+    func degree() -> Double
+//    func testReportOfFile(_ fileName:String) -> NSAttributedString?
+    /** Default is 0.0, The range of value is [0, 1]
+     */
+    func degreeOfFile(_ fileName:String) -> Double
     
     /**
      Replace the refrence image for next image check test

+ 15 - 0
KdanAutoTest/KdanAuto/Class/CompareViewController/CompareViewController.swift

@@ -0,0 +1,15 @@
+//
+//  CompareViewController.swift
+//  KdanAuto
+//
+//  Created by 朱东勇 on 2023/2/2.
+//
+
+import Foundation
+import AppKit
+
+class CompareViewController: NSViewController {
+    
+    
+    
+}

+ 15 - 4
KdanAutoTest/KdanAuto/Class/Norrmal/AutoTestAdvanceSettingView.swift

@@ -49,13 +49,21 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
         }
     }
     
-    func updateBGColor() {
-        self.wantsLayer = true;
-        self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
+    func isDarkMode() -> Bool {
+        let apperace = NSApplication.shared.effectiveAppearance
         
-        self.setNeedsDisplay(self.bounds)
+        return apperace.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
     }
     
+    func updateBGColor() {
+        self.wantsLayer = true;
+        if (isDarkMode()) {
+            self.layer?.backgroundColor = NSColor(white: 0.196, alpha: 1).cgColor
+        }else {
+            self.layer?.backgroundColor = NSColor(white: 0.925, alpha: 1).cgColor
+        }
+//        self.layer?.backgroundColor = NSColor(named: "AdvanceBackgrougColor")?.cgColor
+    }
     
     // Setter
     let kCheckBtnDefaultHeight = 25.0
@@ -292,4 +300,7 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
         _fileList.reloadData()
     }
     
+    func fileCellNeedShowReport(_ cell: TestFileCellView, fileName: String) {
+        
+    }
 }

+ 10 - 1
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestFileCellView.swift

@@ -10,6 +10,8 @@ import AppKit
 
 protocol TestFileCellViewDelegate : NSObjectProtocol {
     func fileCellNeedReplace(_ cell:TestFileCellView, fileName:String)
+    
+    func fileCellNeedShowReport(_ cell:TestFileCellView, fileName:String)
 }
 
 class TestFileCellView : NSTableCellView {
@@ -17,6 +19,7 @@ class TestFileCellView : NSTableCellView {
     @IBOutlet var _sepLine : NSView!
     
     @IBOutlet var _replaceBtn : NSButton!
+    @IBOutlet var _testReportBtn : NSButton!
     
     var _title : String!
     var _isExpad: Bool!
@@ -72,10 +75,16 @@ class TestFileCellView : NSTableCellView {
         return _typeInfo
     }
     
-    
+    // IBActionn
     @IBAction func replaceAction(_ sender:NSButton) {
         if _delegate != nil {
             _delegate?.fileCellNeedReplace(self, fileName: _title)
         }
     }
+    
+    @IBAction func showReportAction(_ sender:NSButton) {
+        if _delegate != nil {
+            _delegate?.fileCellNeedShowReport(self, fileName: _title)
+        }
+    }
 }

+ 14 - 2
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestFileCellView.xib

@@ -27,9 +27,9 @@
                     <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                 </customView>
                 <button verticalHuggingPriority="750" id="1iY-9V-oMo">
-                    <rect key="frame" x="265" y="-2" width="77" height="32"/>
+                    <rect key="frame" x="229" y="-2" width="61" height="32"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
-                    <buttonCell key="cell" type="push" title="Replace" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fG4-an-Nhx">
+                    <buttonCell key="cell" type="push" title="替换" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fG4-an-Nhx">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
                     </buttonCell>
@@ -37,10 +37,22 @@
                         <action selector="replaceAction:" target="Ob6-j8-aNh" id="Biy-Jl-sf8"/>
                     </connections>
                 </button>
+                <button verticalHuggingPriority="750" id="k7x-WS-SBq">
+                    <rect key="frame" x="278" y="-1" width="61" height="32"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
+                    <buttonCell key="cell" type="push" title="100%" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3nC-F1-RVr">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                    <connections>
+                        <action selector="showReportAction:" target="Ob6-j8-aNh" id="m1v-7B-LUA"/>
+                    </connections>
+                </button>
             </subviews>
             <connections>
                 <outlet property="_replaceBtn" destination="1iY-9V-oMo" id="oZj-hx-Yyo"/>
                 <outlet property="_sepLine" destination="Dg0-nG-U3m" id="fck-m4-6W4"/>
+                <outlet property="_testReportBtn" destination="k7x-WS-SBq" id="Aku-Zy-2rn"/>
                 <outlet property="_titleLbl" destination="EgA-BQ-X23" id="Kft-ve-pVP"/>
                 <outlet property="textField" destination="EgA-BQ-X23" id="j2n-kB-6EY"/>
             </connections>