-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
207 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
- Fixed crash when replying | ||
- Fixed crash when importing new themes | ||
- Fixed crash when long pressing on comment | ||
- | ||
- Fixed random name in exported themes | ||
- Now exported themes have ".winston" extension (zip will continue to work though) | ||
- Sharing zip to winston is now allowed | ||
- ".winston" open in one tap into winston and imports it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// importTheme.swift | ||
// winston | ||
// | ||
// Created by Igor Marcossi on 02/10/23. | ||
// | ||
|
||
import Foundation | ||
import Zip | ||
import Defaults | ||
|
||
func importTheme(at rawFileURL: URL) -> Bool { | ||
do { | ||
let fileManager = FileManager.default | ||
let docUrls = fileManager.urls(for: .documentDirectory, in: .userDomainMask) | ||
guard let documentDirectory: URL = docUrls.first else { return false } | ||
let fileURL = documentDirectory.appendingPathComponent("\(UUID().uuidString).zip") | ||
|
||
if fileManager.fileExists(atPath: fileURL.path()) { | ||
try? fileManager.removeItem(at: fileURL) | ||
} | ||
|
||
let gotAccess = rawFileURL.startAccessingSecurityScopedResource() | ||
if !gotAccess { return false } | ||
try? fileManager.copyItem(at: rawFileURL, to: fileURL) | ||
rawFileURL.stopAccessingSecurityScopedResource() | ||
let unzipDirectory = try Zip.quickUnzipFile(fileURL) | ||
let themeJsonURL = unzipDirectory.appendingPathComponent("theme.json") | ||
let themeData = try Data(contentsOf: themeJsonURL) | ||
let theme = try JSONDecoder().decode(WinstonTheme.self, from: themeData) | ||
|
||
let urls = try fileManager.contentsOfDirectory(at: unzipDirectory, includingPropertiesForKeys: nil) | ||
let destinationURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! | ||
for url in urls { | ||
if url.lastPathComponent != "theme.json" { | ||
let destinationFileURL = destinationURL.appendingPathComponent(url.lastPathComponent) | ||
try? fileManager.removeItem(at: destinationFileURL) | ||
try fileManager.moveItem(at: url, to: destinationFileURL) | ||
} | ||
} | ||
|
||
DispatchQueue.main.async { | ||
Defaults[.themesPresets].append(theme) | ||
} | ||
|
||
return true | ||
} catch { | ||
print("Failed to unzip file with error: \(error)") | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.