Skip to content

Commit

Permalink
A few more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinark committed Oct 2, 2023
1 parent 9ffab39 commit b9f3f12
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 64 deletions.
5 changes: 4 additions & 1 deletion TestFlight/WhatToTest.en-US.txt
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
30 changes: 29 additions & 1 deletion winston.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
659F68022A84E32300989300 /* VotesCluster.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659F68012A84E32300989300 /* VotesCluster.swift */; };
659FDEA82A87798300103414 /* VoteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659FDEA72A87798300103414 /* VoteButton.swift */; };
65AA535D2A8BB27900275299 /* FAQPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AA535C2A8BB27900275299 /* FAQPanel.swift */; };
EC051C472ACAF2DC00E9D9ED /* themeFileIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = EC051C462ACAF2DC00E9D9ED /* themeFileIcon.png */; };
EC082F252A65FB4300BA2727 /* MeasureOnce.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC082F242A65FB4300BA2727 /* MeasureOnce.swift */; };
EC082F272A66132600BA2727 /* CommentLinkMore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC082F262A66132600BA2727 /* CommentLinkMore.swift */; };
EC082F292A66134C00BA2727 /* CommentLinkFull.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC082F282A66134C00BA2727 /* CommentLinkFull.swift */; };
Expand Down Expand Up @@ -195,6 +196,7 @@
EC9269F22A51A732003F33B1 /* HighlightedTextEditor in Frameworks */ = {isa = PBXBuildFile; productRef = EC9269F12A51A732003F33B1 /* HighlightedTextEditor */; };
EC9269F72A52B02E003F33B1 /* Shrinkable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9269F62A52B02E003F33B1 /* Shrinkable.swift */; };
EC92FBDE2A589BE200391D1D /* SquircleUIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC92FBDD2A589BE200391D1D /* SquircleUIKit.swift */; };
EC97F0282ACB006A001814A6 /* importTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97F0272ACB006A001814A6 /* importTheme.swift */; };
EC9BB1BB2A89E98D0070CD97 /* hidePost.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9BB1BA2A89E98D0070CD97 /* hidePost.swift */; };
EC9BB1BD2A8ACD300070CD97 /* AlphabetJumper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9BB1BC2A8ACD300070CD97 /* AlphabetJumper.swift */; };
EC9BB1C02A8B05AA0070CD97 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = EC9BB1BF2A8B05AA0070CD97 /* Nuke */; };
Expand Down Expand Up @@ -373,6 +375,8 @@
659F68012A84E32300989300 /* VotesCluster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VotesCluster.swift; sourceTree = "<group>"; };
659FDEA72A87798300103414 /* VoteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoteButton.swift; sourceTree = "<group>"; };
65AA535C2A8BB27900275299 /* FAQPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FAQPanel.swift; sourceTree = "<group>"; };
EC051C2A2ACAEFC500E9D9ED /* QuickLookThumbnailing.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLookThumbnailing.framework; path = System/Library/Frameworks/QuickLookThumbnailing.framework; sourceTree = SDKROOT; };
EC051C462ACAF2DC00E9D9ED /* themeFileIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = themeFileIcon.png; sourceTree = "<group>"; };
EC082F242A65FB4300BA2727 /* MeasureOnce.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeasureOnce.swift; sourceTree = "<group>"; };
EC082F262A66132600BA2727 /* CommentLinkMore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentLinkMore.swift; sourceTree = "<group>"; };
EC082F282A66134C00BA2727 /* CommentLinkFull.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentLinkFull.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -543,6 +547,7 @@
EC9269E72A514AA6003F33B1 /* DownAttributedString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownAttributedString.swift; sourceTree = "<group>"; };
EC9269F62A52B02E003F33B1 /* Shrinkable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shrinkable.swift; sourceTree = "<group>"; };
EC92FBDD2A589BE200391D1D /* SquircleUIKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SquircleUIKit.swift; sourceTree = "<group>"; };
EC97F0272ACB006A001814A6 /* importTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = importTheme.swift; sourceTree = "<group>"; };
EC9BB1BA2A89E98D0070CD97 /* hidePost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = hidePost.swift; sourceTree = "<group>"; };
EC9BB1BC2A8ACD300070CD97 /* AlphabetJumper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlphabetJumper.swift; sourceTree = "<group>"; };
EC9EAEC32A4AAB470074D06B /* fromHex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = fromHex.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -719,6 +724,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
EC051C292ACAEFC500E9D9ED /* Frameworks */ = {
isa = PBXGroup;
children = (
EC051C2A2ACAEFC500E9D9ED /* QuickLookThumbnailing.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
EC08541C2A4BFEF100E88389 /* RedditAPI */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -936,6 +949,7 @@
ECAA8B662A75261000D9D636 /* winston-everywhere */,
EC6CBE342A7D6E760089EAA0 /* LICENSE.md */,
EC6CBE322A7D6BF80089EAA0 /* README.md */,
EC051C292ACAEFC500E9D9ED /* Frameworks */,
EC593AD52A4673B2002D6454 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -952,6 +966,7 @@
EC593AD62A4673B2002D6454 /* winston */ = {
isa = PBXGroup;
children = (
EC7078F52ACAD93800A83240 /* assets */,
EC8B814C2AC96506000DC827 /* extensions */,
ECC10C752A4A8746009124BE /* components */,
EC2D275A2A4FBEF7006444D6 /* modifiers */,
Expand Down Expand Up @@ -1052,6 +1067,14 @@
path = managed;
sourceTree = "<group>";
};
EC7078F52ACAD93800A83240 /* assets */ = {
isa = PBXGroup;
children = (
EC051C462ACAF2DC00E9D9ED /* themeFileIcon.png */,
);
path = assets;
sourceTree = "<group>";
};
EC8B814C2AC96506000DC827 /* extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1272,6 +1295,7 @@
ECF314E42ABC187400DFDDBA /* hashableCGSize.swift */,
ECF5B3062AC83AE600355589 /* getAppIcon.swift */,
EC75D7422AC96D0200594250 /* getEnabledTheme.swift */,
EC97F0272ACB006A001814A6 /* importTheme.swift */,
);
path = utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1492,7 +1516,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1430;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
TargetAttributes = {
EC593AD32A4673B2002D6454 = {
Expand Down Expand Up @@ -1552,6 +1576,7 @@
EC593ADC2A4673B3002D6454 /* Assets.xcassets in Resources */,
EC6CBE332A7D6BF80089EAA0 /* README.md in Resources */,
ECA30A172A5FA08500BB19D1 /* WhatToTest.en-US.txt in Resources */,
EC051C472ACAF2DC00E9D9ED /* themeFileIcon.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1780,6 +1805,7 @@
650ACAFC2A87A36900A7C600 /* calcVotes.swift in Sources */,
ECC2C7B42AAB4A64000E196C /* ThemeEditPanel.swift in Sources */,
ECF064EB2A7F2AC50088C2C0 /* Router.swift in Sources */,
EC97F0282ACB006A001814A6 /* importTheme.swift in Sources */,
ECE2859B2A5010E2009CF9DD /* DataBlock.swift in Sources */,
EC75D7432AC96D0200594250 /* getEnabledTheme.swift in Sources */,
ECF974432AA170D300C3BC75 /* TipJar.swift in Sources */,
Expand Down Expand Up @@ -2033,6 +2059,7 @@
INFOPLIST_FILE = winston/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Winston;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "Winston needs access to your documents to save/import themes.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Winston needs access to your library to be able to download images.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -2072,6 +2099,7 @@
INFOPLIST_FILE = winston/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Winston;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_NSDocumentsFolderUsageDescription = "Winston needs access to your documents to save/import themes.";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Winston needs access to your library to be able to download images.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>11</integer>
<integer>9</integer>
</dict>
<key>SwiftDate (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>12</integer>
<integer>10</integer>
</dict>
<key>SwiftDate (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
<integer>8</integer>
</dict>
<key>winston.xcscheme_^#shared#^_</key>
<dict>
Expand Down
55 changes: 55 additions & 0 deletions winston/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>winston</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>themeFileIcon</string>
<key>CFBundleTypeName</key>
<string>Winston theme file</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>lo.cafe.winston.theme-file</string>
</array>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Winston theme zip file</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.zip-archive</string>
</array>
</dict>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down Expand Up @@ -35,5 +64,31 @@
<string>processing</string>
<string>remote-notification</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.zip-archive</string>
<string>public.data</string>
<string>public.content</string>
</array>
<key>UTTypeDescription</key>
<string>Winston theme file</string>
<key>UTTypeIconFiles</key>
<array>
<string>themeFileIcon</string>
</array>
<key>UTTypeIdentifier</key>
<string>lo.cafe.winston.theme-file</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>winston</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
17 changes: 17 additions & 0 deletions winston/Tabber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct Tabber: View {
@State var activeTab = TabIdentifier.posts

@State var credModalOpen = false
@State var importedThemeAlert = false

// @State var tabBarHeight: CGFloat?
@StateObject private var inboxPayload = TabPayload("inboxRouter")
Expand Down Expand Up @@ -207,6 +208,13 @@ struct Tabber: View {
} message: {
Text("Something went wrong, but winston's is a fast cat, got the bug in his fangs and brought it to you. What do you wanna do?")
}
.alert("Success!", isPresented: $importedThemeAlert) {
Button("Nice!", role: .cancel) {
importedThemeAlert = false
}
} message: {
Text("The theme was imported successfully. Enable it in \"Themes\" section in the Settings tab.")
}
.onAppear {
if showTestersCelebrationModal {
showTipJarModal = false
Expand Down Expand Up @@ -240,6 +248,15 @@ struct Tabber: View {
}
}
.onOpenURL { url in
if url.absoluteString.hasSuffix(".winston") || url.absoluteString.hasSuffix(".zip") {
TempGlobalState.shared.globalLoader.enable("Importing...")
let result = importTheme(at: url)
TempGlobalState.shared.globalLoader.dismiss()
if result {
importedThemeAlert = true
}
return
}
let parsed = parseRedditURL(url.absoluteString)
withAnimation {
switch parsed {
Expand Down
Binary file added winston/assets/themeFileIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion winston/components/Links/PostLink/PostLinkCompact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ struct PostLinkCompact: View {
.zIndex(1)
.frame(maxWidth: .infinity, alignment: .topLeading)

SubsNStuffLine(showSub: showSub, feedsAndSuch: feedsAndSuch, post: post, sub: sub, routerProxy: routerProxy, over18: over18)
if !showSubsAtTop {
SubsNStuffLine(showSub: showSub, feedsAndSuch: feedsAndSuch, post: post, sub: sub, routerProxy: routerProxy, over18: over18)
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion winston/models/WinstonTheme/WinstonTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct WinstonTheme: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
func duplicate() -> WinstonTheme {
var copy = self
copy.id = UUID().uuidString
copy.metadata.name = randomWord().capitalized
if copy.metadata.name == "Default" { copy.metadata.name = randomWord().capitalized }
return copy
}

Expand Down
51 changes: 51 additions & 0 deletions winston/utils/importTheme.swift
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
}
}
2 changes: 1 addition & 1 deletion winston/utils/redditURLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum RedditURLType: Equatable, Hashable {
}

func parseRedditURL(_ rawUrlString: String) -> RedditURLType {
let urlString = rawUrlString.replacingOccurrences(of: "winstonapp://", with: "https://app.winston.lo.cafe/")
let urlString = rawUrlString.replacingOccurrences(of: "winstonapp://", with: "https://app.winston.lo.cafe/").replacingOccurrences(of: "https://reddit.com/", with: "https://app.winston.lo.cafe/")
guard let urlComponents = URLComponents(string: urlString) else {
return .other(link: urlString)
}
Expand Down
17 changes: 12 additions & 5 deletions winston/utils/saveAndLoadImages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,23 @@ func createZip(images: [String], theme: WinstonTheme) throws -> URL {
let jsonData = try JSONEncoder().encode(theme)
try jsonData.write(to: jsonURL)

let zipName = "\(theme.metadata.name) Theme - Winston"
let zipName = UUID().uuidString
let zipURL = documentDirectory.appendingPathComponent("\(zipName).zip")

if fileManager.fileExists(atPath: zipURL.path()) {
try fileManager.removeItem(at: zipURL)
}

try Zip.zipFiles(paths: imgURLs + [jsonURL], zipFilePath: zipURL, password: nil, progress: nil)

let winstonFileName = "\(theme.metadata.name)-Theme"
let winstonFileNameURL = documentDirectory.appendingPathComponent("\(winstonFileName).winston")

if fileManager.fileExists(atPath: winstonFileNameURL.path()) {
try fileManager.removeItem(at: winstonFileNameURL)
}

let zipFilePath = try Zip.quickZipFiles(imgURLs + [jsonURL], fileName: zipName)
// replace with your ZipArchive class and its usage
// make sure theme.json and images are added to the zip file
try fileManager.moveItem(at: zipURL, to: winstonFileNameURL)

return zipFilePath
return winstonFileNameURL
}
2 changes: 2 additions & 0 deletions winston/views/Settings/views/BehaviorPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ struct BehaviorPanel: View {

Section {
LabeledSlider(label: "Loading limit", value: Binding(get: { CGFloat(feedPostsLoadLimit) }, set: { val in feedPostsLoadLimit = Int(val) }), range: 15...100)
.themedListRowBG(enablePadding: true)
} footer: {
Text("Sets how many posts to load per chunk (loads more on scroll)")
}
.themedListDividers()

Section {
Toggle("Navigation everywhere", isOn: $enableSwipeAnywhere)
Expand Down
Loading

0 comments on commit b9f3f12

Please sign in to comment.