Skip to content
49 changes: 48 additions & 1 deletion mac/Config/Config/ConfigDebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import KeymanSettings
struct ConfigDebugView: View {
@EnvironmentObject var settings: SettingsContainer
@State private var isShowingSheet = false

// for drag and drop package installation
@State private var dropError: DropKmpError?
@State private var isShowingDropKmpAlert = false
@State private var alertMessage = ""
@State private var isHovering = false

var body: some View {
VStack {
Expand Down Expand Up @@ -41,7 +47,48 @@ struct ConfigDebugView: View {
.frame(width: 700, height: 500)
}


VStack {
Text("Drag a single .kmp archive here")
.font(.system(.body, design: .monospaced))
.multilineTextAlignment(.center)
.padding()
.frame(width: 350, height: 180)
.background(Color(NSColor.controlBackgroundColor))
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(isHovering ? Color.accentColor : Color.gray, lineWidth: 2)
)
// Accept URL drops
.dropDestination(for: URL.self) { urls, _ in
// reject drop if it is more than one file
guard let droppedFileUrl = urls.first, urls.count == 1 else {
let error = DropKmpError.tooManyFiles
self.alertMessage = error.localizedDescription
self.isShowingDropKmpAlert = true
return false // the drop failed
}
do {
try settings.processDroppedKmpFile(at: droppedFileUrl)
return true // the drop was successful
} catch {
self.alertMessage = error.localizedDescription
self.isShowingDropKmpAlert = true
return false

}
} isTargeted: { hovering in
isHovering = hovering
}
}
.padding()
// alert triggers automatically when $dropError becomes non-nil
.alert("Package Installation Failed", isPresented: $isShowingDropKmpAlert) {
Button("OK", role: .cancel) { }
} message: {
Text(alertMessage)
}

ScrollView {
VStack(alignment: .leading, spacing: 6) {
ForEach(Array(settings.singleKeyboardPackages.enumerated()), id: \.offset) { index, package in
Expand Down
18 changes: 0 additions & 18 deletions mac/Config/Config/ConfigTests/ConfigTests.swift

This file was deleted.

9 changes: 6 additions & 3 deletions mac/Config/Config/KeyboardSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,17 @@ struct KeyboardSearchView: NSViewRepresentable {
if let downloadFileUrl {
print("Download of \(downloadFileUrl.path()) was successful.")
if let settings {
settings.packageDownloadComplete(kmpFileUrl: downloadFileUrl)
do {
try settings.packageDownloadComplete(kmpFileUrl: downloadFileUrl)
} catch {
// MAC-CONFIG-TODO: communicate failed install to user
}
}
}
}

// MAC-CONFIG-TODO: remove package if it already exists

func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?) {
// MAC-CONFIG-TODO: communicate failed install to user
print("Download failed with error: \(error.localizedDescription)")
}

Expand Down
38 changes: 37 additions & 1 deletion mac/Config/Config/MainConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ struct MainConfigView: View {
@State private var selectedTab = 0
@State private var packageSelectedForHelpUrl: URL? = nil

// for drag and drop package installation
@State private var dropError: DropKmpError?
@State private var isShowingDropKmpAlert = false
@State private var alertMessage = ""
@State private var isHovering = false

/**
* Assigns packageSelectedForHelpUrl the url argument and changes the selected tab to the help tab
*/
Expand Down Expand Up @@ -58,7 +64,37 @@ struct MainConfigView: View {
showHelpTab(for: url) })
}
.formStyle(.grouped)

// highlight border with accent color when hovering over view
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.accentColor, lineWidth: 2).opacity(isHovering ? 1 : 0))
.animation(.easeInOut(duration: 0.2), value: isHovering)
// accepts URL drops
.dropDestination(for: URL.self) { urls, _ in
// reject drop if it is more than one file
guard let droppedFileUrl = urls.first, urls.count == 1 else {
let error = DropKmpError.tooManyFiles
self.alertMessage = error.localizedDescription
self.isShowingDropKmpAlert = true
return false // the drop failed
}
do {
try settings.processDroppedKmpFile(at: droppedFileUrl)
return true // the drop was successful
} catch {
self.alertMessage = error.localizedDescription
self.isShowingDropKmpAlert = true
return false

}
} isTargeted: { hovering in
isHovering = hovering
}
// alert triggers automatically when $dropError becomes non-nil
.alert("Package Installation Failed", isPresented: $isShowingDropKmpAlert) {
Button("OK", role: .cancel) { }
} message: {
Text(alertMessage)
}

// the Spacer pushes the contents of the VStack to the top of the VStack
Spacer()
}
Expand Down
6 changes: 3 additions & 3 deletions mac/Config/Config/PackageRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct PackageRowView: View {
// if the package contains one keyboard, show the keyboard name, otherwise show the package name
Text(isSingleKeyboardPackage ? keyboard.name: package.packageName)
.font(.title)

// see keyboard help button
if let url = package.helpFileUrl {
IconButtonView(
Expand All @@ -84,8 +84,6 @@ public struct PackageRowView: View {
.toggleStyle(.switch)
.gridColumnAlignment(.leading)
}


}

// if the package contains multiple keyboards shows an HStack with the keyboard name and toggle button for each keyboard in the package
Expand Down Expand Up @@ -124,6 +122,8 @@ public struct PackageRowView: View {
}
}
}
// animate changes in the package list
.animation(.easeInOut, value: packages)
// binds the visibilty state to the alert builder
.alert("Are you sure you want to delete the keyboard \"\(selectedPackage?.packageName ?? "")\"?",
isPresented: $isShowingDeleteAlert,
Expand Down
2 changes: 1 addition & 1 deletion mac/Config/Installation/InputMethodUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public class InputMethodUtil {

NSWorkspace.shared.openApplication(at: inputMethodUrl, configuration: openConfig) { (app, error) in
if let error = error {
print("Could not launch Keyman input method: \(error.localizedDescription)")
print("Could not launch Keyman input method at \(inputMethodUrl), due to error: \(error.localizedDescription), code: \(error._code)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public protocol PackageRepo {
func loadSinglePackage(packageUrl: URL) throws -> KeymanPackage
func getDownloadUrl(for kmpFilename: String) -> URL
func getUnzipDestinationUrl(for packageName: String) -> URL
func getInstallationUrlForPackageName(packageName: String) -> URL
func buildInstallationUrlForPackageName(packageName: String) -> URL
func cleanupTempDirectory()
}
Loading