From beba554feb33b8fd1ae995ab716fc040089fb23e Mon Sep 17 00:00:00 2001 From: Shawn Schantz Date: Fri, 14 Aug 2026 14:03:34 -0400 Subject: [PATCH] feat(mac): load help and readme if not listed in options If the help file (welcome.htm) and readme file (readme.htm) are not listed in the options element of the kmp.json, check the file list. Read them from the package using their default filenames if they are found there. --- .../Persistence/Data/PackageSource.swift | 20 +++++++++++++++---- .../Persistence/PackageRepository.swift | 4 +--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mac/KeymanSettings/Sources/Persistence/Data/PackageSource.swift b/mac/KeymanSettings/Sources/Persistence/Data/PackageSource.swift index 75494968d0..e9d4013dab 100644 --- a/mac/KeymanSettings/Sources/Persistence/Data/PackageSource.swift +++ b/mac/KeymanSettings/Sources/Persistence/Data/PackageSource.swift @@ -10,6 +10,9 @@ import Foundation +let defaultHelpFilename = "welcome.htm" +let defaultReadmeFilename = "readme.htm" + public struct PackageSource: Identifiable, Decodable, Hashable, Equatable { public var id = UUID() let system: SystemInfo? @@ -35,16 +38,25 @@ public struct PackageSource: Identifiable, Decodable, Hashable, Equatable { var readmeFilename: String? { if let filename = options?.readmeFile { return filename - } else { - return nil } + if let fileArray = self.files { + if fileArray.contains(where: { $0.name == defaultReadmeFilename }) { + return defaultReadmeFilename + } + } + return nil } var helpFilename: String? { if let filename = options?.welcomeFile { return filename - } else { - return nil } + if let fileArray = self.files { + if fileArray.contains(where: { $0.name == defaultHelpFilename }) { + return defaultHelpFilename + } + } + + return nil } var graphicFilename: String? { if let filename = options?.graphicFile { diff --git a/mac/KeymanSettings/Sources/Persistence/PackageRepository.swift b/mac/KeymanSettings/Sources/Persistence/PackageRepository.swift index a353d10cbe..e35541969a 100644 --- a/mac/KeymanSettings/Sources/Persistence/PackageRepository.swift +++ b/mac/KeymanSettings/Sources/Persistence/PackageRepository.swift @@ -274,10 +274,8 @@ public class PackageRepository: PackageRepo { var packageSource: PackageSource? do { let jsonData = try Data(contentsOf: kmpFileUrl, options: .mappedIfSafe) - var source: PackageSource = try JSONDecoder().decode(PackageSource.self, from: jsonData) + packageSource = try JSONDecoder().decode(PackageSource.self, from: jsonData) - print("readPackage, packageName: \(source.packageName)") - packageSource = source } catch let error as LoadPackageError { // if we encounter a LoadPackageError, propagate it throw error