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.
This commit is contained in:
Shawn Schantz 2026-08-14 14:03:34 -04:00
parent 895151d89a
commit beba554feb
2 changed files with 17 additions and 7 deletions

View file

@ -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 {

View file

@ -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