Explorar el Código

[新建] - 系统菜单,新建-截屏优化

liujiajie hace 11 meses
padre
commit
0842529e55

+ 19 - 4
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -1427,7 +1427,8 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenshot_SelectRectWithCompleteHandler { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let folderPath = self.createBaseFoldPath()
+                    let savePathOld = folderPath + "/screenShot.pdf"
                     var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
@@ -1496,7 +1497,8 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let folderPath = self.createBaseFoldPath()
+                    let savePathOld = folderPath + "/screenShot.pdf"
                     var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
@@ -1518,7 +1520,9 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let folderPath = self.createBaseFoldPath()
+                    let savePathOld = folderPath + "/screenShot.pdf"
+                    
                     var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
@@ -1540,7 +1544,10 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(0) { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let folderPath = self.createBaseFoldPath()
+                    let savePathOld = folderPath + "/screenShot.pdf"
+                    
+                    var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
                     let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
@@ -1554,6 +1561,14 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
             }
         }
     }
+    
+    func createBaseFoldPath() -> String {
+        let folderPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last?.appending("/\(Bundle.main.bundleIdentifier!)")
+        if (FileManager.default.fileExists(atPath: folderPath!) == false) {
+            try?FileManager.default.createDirectory(atPath: folderPath!, withIntermediateDirectories: false)
+        }
+        return folderPath ?? ""
+    }
 }
 
 // MARK: - KMSystemViewMenuProtocol