From 733f9ae7b8c6873415b1ab9ed754f5bd964e60a6 Mon Sep 17 00:00:00 2001 From: osy Date: Fri, 11 Aug 2023 18:19:06 -0700 Subject: [PATCH] main: allow switching between UUP Dump and ESD Convert modes --- CrystalFetch.xcodeproj/project.pbxproj | 4 ++ Source/ContentView.swift | 6 +++ Source/CrystalFetch-Info.plist | 17 +++++-- Source/Main.swift | 8 ++-- Source/ShowWindowButtonView.swift | 62 ++++++++++++++++++++++++++ Source/SimpleContentView.swift | 8 ++-- 6 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 Source/ShowWindowButtonView.swift diff --git a/CrystalFetch.xcodeproj/project.pbxproj b/CrystalFetch.xcodeproj/project.pbxproj index f22b667..ecd6ca4 100644 --- a/CrystalFetch.xcodeproj/project.pbxproj +++ b/CrystalFetch.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 844A8EFF2A86CA8C009A389C /* SimpleContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844A8EFE2A86CA8C009A389C /* SimpleContentView.swift */; }; 844A8F032A86E86F009A389C /* EULAView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844A8F022A86E86F009A389C /* EULAView.swift */; }; 844A8F062A86F92F009A389C /* esd2iso.sh in Resources */ = {isa = PBXBuildFile; fileRef = 844A8F052A86F92F009A389C /* esd2iso.sh */; }; + 84EB35722A870EA7004F252E /* ShowWindowButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84EB35712A870EA6004F252E /* ShowWindowButtonView.swift */; }; CEC09F0F2A6BB66200980857 /* Main.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC09F0E2A6BB66200980857 /* Main.swift */; }; CEC09F112A6BB66200980857 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC09F102A6BB66200980857 /* ContentView.swift */; }; CEC09F132A6BB66300980857 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CEC09F122A6BB66300980857 /* Assets.xcassets */; }; @@ -495,6 +496,7 @@ 844A8EFE2A86CA8C009A389C /* SimpleContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleContentView.swift; sourceTree = ""; }; 844A8F022A86E86F009A389C /* EULAView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EULAView.swift; sourceTree = ""; }; 844A8F052A86F92F009A389C /* esd2iso.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = esd2iso.sh; sourceTree = ""; }; + 84EB35712A870EA6004F252E /* ShowWindowButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowWindowButtonView.swift; sourceTree = ""; }; CEC09F0B2A6BB66200980857 /* CrystalFetch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CrystalFetch.app; sourceTree = BUILT_PRODUCTS_DIR; }; CEC09F0E2A6BB66200980857 /* Main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.swift; sourceTree = ""; }; CEC09F102A6BB66200980857 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -961,6 +963,7 @@ CEC09F362A6E5B7600980857 /* BuildDetails.swift */, CEC09F382A6E5D5C00980857 /* BuildEditions.swift */, CEC09F342A6DF33C00980857 /* BuildsListView.swift */, + 84EB35712A870EA6004F252E /* ShowWindowButtonView.swift */, CEC09F272A6DBED400980857 /* Worker.swift */, CEC09F122A6BB66300980857 /* Assets.xcassets */, CEC09F172A6BB66300980857 /* CrystalFetch.entitlements */, @@ -1582,6 +1585,7 @@ CEC09F3D2A6EECC700980857 /* Downloader.swift in Sources */, CEC09F2D2A6DC60500980857 /* UUPDetails.swift in Sources */, CEC09F352A6DF33C00980857 /* BuildsListView.swift in Sources */, + 84EB35722A870EA7004F252E /* ShowWindowButtonView.swift in Sources */, CEC09F392A6E5D5C00980857 /* BuildEditions.swift in Sources */, 844A8F032A86E86F009A389C /* EULAView.swift in Sources */, CEC09F2F2A6DC72000980857 /* UUPEditions.swift in Sources */, diff --git a/Source/ContentView.swift b/Source/ContentView.swift index 4888985..e03661b 100644 --- a/Source/ContentView.swift +++ b/Source/ContentView.swift @@ -54,6 +54,12 @@ struct ContentView: View { ProgressView() } } + ToolbarItem(placement: .navigation) { + ShowWindowButtonView(id: "ESDConvert") { + Label("Simple…", systemImage: "arrowshape.turn.up.backward.fill") + }.disabled(worker.isBusy) + .help("Build installation for the latest release through ESD conversion.") + } ToolbarItem(placement: .principal) { Button { worker.refresh(findDefault: true) diff --git a/Source/CrystalFetch-Info.plist b/Source/CrystalFetch-Info.plist index 462eb93..ac101d7 100644 --- a/Source/CrystalFetch-Info.plist +++ b/Source/CrystalFetch-Info.plist @@ -2,25 +2,34 @@ + CFBundleURLTypes + + + CFBundleURLSchemes + + crystalfetch + + + + ITSAppUsesNonExemptEncryption + NSAppTransportSecurity NSAllowsArbitraryLoads NSExceptionDomains - tlu.dl.delivery.mp.microsoft.com + dl.delivery.mp.microsoft.com NSExceptionAllowsInsecureHTTPLoads - dl.delivery.mp.microsoft.com + tlu.dl.delivery.mp.microsoft.com NSExceptionAllowsInsecureHTTPLoads - ITSAppUsesNonExemptEncryption - diff --git a/Source/Main.swift b/Source/Main.swift index 77551fb..0fdb9a7 100644 --- a/Source/Main.swift +++ b/Source/Main.swift @@ -21,16 +21,16 @@ struct Main: App { @StateObject private var worker = Worker() var body: some Scene { - WindowGroup(id: "simple") { + WindowGroup(id: "ESDConvert") { SimpleContentView().environmentObject(worker) .frame(minWidth: 500, idealWidth: 500, minHeight: 300, idealHeight: 300) - } + }.handlesExternalEvents(matching: Set(["ESDConvert"])) - WindowGroup(id: "advanced") { + WindowGroup(id: "UUPDump") { ContentView().environmentObject(worker) .frame(minWidth: 800, minHeight: 400) }.commands { SidebarCommands() - } + }.handlesExternalEvents(matching: Set(["UUPDump"])) } } diff --git a/Source/ShowWindowButtonView.swift b/Source/ShowWindowButtonView.swift new file mode 100644 index 0000000..9ecd8d7 --- /dev/null +++ b/Source/ShowWindowButtonView.swift @@ -0,0 +1,62 @@ +// +// Copyright © 2023 Turing Software, LLC. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import SwiftUI + +struct ShowWindowButtonView: View { + let id: String + let label: () -> Label + + @Environment(\.dismiss) private var dismiss + + var body: some View { + if #available(macOS 13, *) { + ShowWindowButtonViewNew(id: id, label: label) + } else { + Button(action: { + open(id: id) + dismiss() + }, label: label) + } + } + + private func open(id: String) { + let url = URL(string: "crystalfetch://\(id)")! + NSWorkspace.shared.open(url) + } +} + +@available(macOS 13, *) +private struct ShowWindowButtonViewNew: View { + let id: String + let label: () -> Label + + @Environment(\.openWindow) private var openWindow + @Environment(\.dismiss) private var dismiss + + var body: some View { + Button(action: { + openWindow(id: id) + dismiss() + }, label: label) + } +} + +#Preview { + ShowWindowButtonView(id: "UUPDump") { + Text("All builds…") + } +} diff --git a/Source/SimpleContentView.swift b/Source/SimpleContentView.swift index 82ec519..329c32c 100644 --- a/Source/SimpleContentView.swift +++ b/Source/SimpleContentView.swift @@ -29,8 +29,6 @@ struct SimpleContentView: View { @State private var languages: [DisplayString] = [] @State private var editions: [DisplayString] = [] - @Environment(\.openWindow) private var openWindow - var body: some View { VStack { Form { @@ -87,11 +85,10 @@ struct SimpleContentView: View { } } HStack { - Button { - - } label: { + ShowWindowButtonView(id: "UUPDump") { Text("All builds…") }.disabled(worker.isBusy) + .help("Build custom installation for any build through UUP Dump.") Spacer() if worker.isBusy { Button(role: .cancel) { @@ -133,6 +130,7 @@ struct SimpleContentView: View { .padding() .onAppear { worker.refreshEsdCatalog() + refreshList() } .onChange(of: worker.completedDownloadUrl) { newValue in if newValue != nil {