-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,8 @@ struct M1necraftApp: App { | |
} | ||
#endif | ||
} | ||
Settings { | ||
SettingsView(m: m) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// SettingsView.swift | ||
// M1necraft | ||
// | ||
// Created by Raphael Tang on 13/2/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SettingsView: View { | ||
@ObservedObject var m: ContentView.ViewModel | ||
var showCloseButton = false | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 5) { | ||
if showCloseButton { | ||
HStack { | ||
Spacer() | ||
CloseButton { | ||
m.activeSheet = nil | ||
} | ||
} | ||
} | ||
|
||
Text("Settings") | ||
.font(.title.bold()) | ||
.padding(.bottom, 8) | ||
Form { | ||
Button("Reset all data") { | ||
try! Paths.global.resetDataDir() | ||
try! Paths.global.mclLwjglnatives.folder?.delete() | ||
try! Paths.global.mclLwjglfatJar.file?.delete() | ||
try! Paths.global.mclJre.forEach { url in | ||
try url.value.folder?.delete() | ||
} | ||
|
||
// delete all installed versions | ||
try! supportedVersions.forEach { version in | ||
try version.isInstalledAt?.folder?.delete() | ||
} | ||
|
||
let jsonEncoder = JSONEncoder() | ||
let jsonDecoder = JSONDecoder() | ||
|
||
var launcherProfiles = try! jsonDecoder.decode(MinecraftLauncherProfiles.self, from: try! String(contentsOf: Paths.global.mclLauncherProfiles).data(using: .utf8)!) | ||
launcherProfiles.profiles.forEach { profileItem in | ||
if profileItem.key.hasPrefix("m1necraft") { | ||
launcherProfiles.profiles.removeValue(forKey: profileItem.key) | ||
} | ||
} | ||
|
||
try! String(data: jsonEncoder.encode(launcherProfiles), encoding: .utf8)?.write(to: Paths.global.mclLauncherProfiles, atomically: false, encoding: .utf8) | ||
|
||
m.setupStatus = .settingUp | ||
m.activeSheet = nil | ||
} | ||
} | ||
} | ||
.padding(.all, 20) | ||
.frame(width: 500) | ||
} | ||
} | ||
|
||
struct SettingsView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SettingsView(m: ContentView.ViewModel()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters