Skip to content

Commit

Permalink
Developer Mode added
Browse files Browse the repository at this point in the history
  • Loading branch information
cranci1 committed Apr 18, 2024
1 parent 39ddf2b commit 083f3d9
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 10 deletions.
8 changes: 6 additions & 2 deletions AnimeGen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
13910EC92B80D5C2009BF17E /* nekos-best.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13910EC82B80D5C2009BF17E /* nekos-best.swift */; };
13910ECB2B80D5C8009BF17E /* waifu-pics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13910ECA2B80D5C8009BF17E /* waifu-pics.swift */; };
139A2E0A2BA4D642003F2598 /* kyoko.swift in Sources */ = {isa = PBXBuildFile; fileRef = 139A2E092BA4D642003F2598 /* kyoko.swift */; };
13A2B7902BD1615600B79DF7 /* Developer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A2B78F2BD1615600B79DF7 /* Developer.swift */; };
13A325922B94D8A100F1C357 /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A325912B94D8A100F1C357 /* Secrets.swift */; };
13BE98C02B828B8000379AB7 /* nekosmoe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13BE98BF2B828B8000379AB7 /* nekosmoe.swift */; };
13C8011D2B94C5E900BFD198 /* HmtaiSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13C8011C2B94C5E900BFD198 /* HmtaiSender.swift */; };
Expand Down Expand Up @@ -70,6 +71,7 @@
13910EC82B80D5C2009BF17E /* nekos-best.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "nekos-best.swift"; sourceTree = "<group>"; };
13910ECA2B80D5C8009BF17E /* waifu-pics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "waifu-pics.swift"; sourceTree = "<group>"; };
139A2E092BA4D642003F2598 /* kyoko.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = kyoko.swift; sourceTree = "<group>"; };
13A2B78F2BD1615600B79DF7 /* Developer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Developer.swift; sourceTree = "<group>"; };
13A325912B94D8A100F1C357 /* Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = "<group>"; };
13BE98BF2B828B8000379AB7 /* nekosmoe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = nekosmoe.swift; sourceTree = "<group>"; };
13C8011C2B94C5E900BFD198 /* HmtaiSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HmtaiSender.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -164,6 +166,7 @@
13877B182B82001800251A60 /* SettingsPage.swift */,
13877B1D2B82024A00251A60 /* AboutPage.swift */,
13CC95072B8BA40100B5705E /* ApiPage.swift */,
13A2B78F2BD1615600B79DF7 /* Developer.swift */,
13CC95092B8BA43600B5705E /* API.xcassets */,
);
path = Settings;
Expand Down Expand Up @@ -289,6 +292,7 @@
13877B1E2B82024A00251A60 /* AboutPage.swift in Sources */,
13910EC52B80D5A6009BF17E /* pic-re.swift in Sources */,
1365E8202BB0112D005E0548 /* HistoryView.swift in Sources */,
13A2B7902BD1615600B79DF7 /* Developer.swift in Sources */,
1365E8222BB011F6005E0548 /* ImageHistory.swift in Sources */,
13C8011D2B94C5E900BFD198 /* HmtaiSender.swift in Sources */,
131515712BAB284A00A1C770 /* Refresh-API-Button.swift in Sources */,
Expand Down Expand Up @@ -449,7 +453,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = AnimeGen/AnimeGen.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 23;
DEVELOPMENT_TEAM = 399LMK6Q2Y;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AnimeGen/Info.plist;
Expand Down Expand Up @@ -484,7 +488,7 @@
CODE_SIGN_ENTITLEMENTS = AnimeGen/AnimeGen.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 23;
DEVELOPMENT_TEAM = 399LMK6Q2Y;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AnimeGen/Info.plist;
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions AnimeGen/Buttons/Refresh-API-Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension ViewController {
case "waifu.pics":
lastImage = imageView.image
loadImageFromWaifuPics()
case "Hmtai":
case "Hmtai api":
lastImage = imageView.image
startHmtaiLoader()
case "Nekos api":
Expand Down Expand Up @@ -66,7 +66,7 @@ extension ViewController {
@objc func apiButtonTapped() {
let alertController = UIAlertController(title: "Select API", message: nil, preferredStyle: .actionSheet)

let apiOptions = ["Purr", "kyoko", "nekos.moe", "Nekos api", "Hmtai", "waifu.pics", "nekos.best", "waifu.im", "pic.re"]
let apiOptions = ["Purr", "kyoko", "nekos.moe", "Nekos api", "Hmtai api", "waifu.pics", "nekos.best", "waifu.im", "pic.re"]
for option in apiOptions {
let action = UIAlertAction(title: option, style: .default) { _ in
self.apiButton.setTitle(option, for: .normal)
Expand Down
7 changes: 3 additions & 4 deletions AnimeGen/Secrets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import Foundation

struct Secrets {
static let apiToken = "Bot TokenHEREHEREHERE"
static var apiToken = "Bot DiscordBotTokenHere"

static let discordWebhookURL = URL(string: "YourWebhookUrl")!
static var discordWebhookURL = URL(string: "YourWebhookUrl")!

static let discordChannelId = "YourChannelIdHere"
static var discordChannelId = "YourChannelIdHere"
}

Binary file modified AnimeGen/Settings/.DS_Store
Binary file not shown.
95 changes: 95 additions & 0 deletions AnimeGen/Settings/Developer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// Developer.swift
// AnimeGen
//
// Created by cranci on 18/04/24.
//

import SwiftUI

struct DeveloperView: View {
@State private var apiToken: String
@State private var discordWebhookURL: String
@State private var discordChannelId: String

init() {
_apiToken = State(initialValue: UserDefaults.standard.string(forKey: "apiToken") ?? Secrets.apiToken)
_discordWebhookURL = State(initialValue: UserDefaults.standard.string(forKey: "discordWebhookURL") ?? Secrets.discordWebhookURL.absoluteString)
_discordChannelId = State(initialValue: UserDefaults.standard.string(forKey: "discordChannelId") ?? Secrets.discordChannelId)
}

var body: some View {
VStack {
VStack(spacing: 20) {
Text("Hmtai Preferences")
.font(.largeTitle)
.fontWeight(.semibold)
.frame(maxWidth: .infinity, alignment: .leading)

TextField("Bot DiscordTokenHere", text: $apiToken)
.padding()
.background(RoundedRectangle(cornerRadius: 10).stroke(Color.gray, lineWidth: 1))
Text("On this value you need to remove 'DiscordTokenHere' and replace it with your discord bot token. Dont remove the 'Bot' prefix and also leave the space.")
.font(.caption)
.padding(.top, -10)
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .leading)

TextField("Discord Webhook URL", text: $discordWebhookURL)
.padding()
.background(RoundedRectangle(cornerRadius: 10).stroke(Color.gray, lineWidth: 1))
Text("On this value make sure to put your discord webhook with the https://")
.font(.caption)
.padding(.top, -10)
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .leading)

TextField("Discord Channel ID", text: $discordChannelId)
.padding()
.background(RoundedRectangle(cornerRadius: 10).stroke(Color.gray, lineWidth: 1))
Text("On this value you need to past your discord channel ID.")
.font(.caption)
.padding(.top, -10)
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .leading)
}

Button(action: {
saveValues()
}) {
Text("Save")
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.accentColor)
.shadow(radius: 5)
)
}
.padding(.top, 20)

Spacer()
}
.padding()
.navigationBarTitle("Developer Settings", displayMode: .inline)
}

private func saveValues() {
UserDefaults.standard.set(apiToken, forKey: "apiToken")
UserDefaults.standard.set(discordWebhookURL, forKey: "discordWebhookURL")
UserDefaults.standard.set(discordChannelId, forKey: "discordChannelId")

Secrets.apiToken = apiToken
if let url = URL(string: discordWebhookURL) {
Secrets.discordWebhookURL = url
}
Secrets.discordChannelId = discordChannelId
}
}

struct DeveloperView_Previews: PreviewProvider {
static var previews: some View {
DeveloperView()
}
}
22 changes: 21 additions & 1 deletion AnimeGen/Settings/SettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct SettingsPage: View {
// Content
@State private var explicitCont = UserDefaults.standard.bool(forKey: "enableExplictiCont")

// Devloper Mode
@State private var developerMode = UserDefaults.standard.bool(forKey: "enableDeveloperMode")

var body: some View {
NavigationView {
Form {
Expand Down Expand Up @@ -67,7 +70,6 @@ struct SettingsPage: View {
}

Section(header: Text("Content"), footer: Text("Caution: This content is on the borderline of explicit material and includes adult content. Viewer discretion is advised.")) {

Toggle("Explicit Contents", isOn: Binding(
get: { self.explicitCont },
set: { newValue in
Expand All @@ -77,6 +79,24 @@ struct SettingsPage: View {
))
}

Section(header: Text("Developer")) {

Toggle("Developer Mode", isOn: Binding(
get: { self.developerMode },
set: { newValue in
self.developerMode = newValue
UserDefaults.standard.set(newValue, forKey: "enableDeveloperMode")
}
))

if UserDefaults.standard.bool(forKey: "enableDeveloperMode") {
NavigationLink(destination: DeveloperView()) {
Text("Developer Settings")
.foregroundColor(.accentColor)
}
}
}

Section(header: Text("About AnimeGen")) {
NavigationLink(destination: AboutPage()) {
Text("About")
Expand Down
2 changes: 1 addition & 1 deletion AnimeGen/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class ViewController: UIViewController {
loadImageFromNekosBest()
case "waifu.pics":
loadImageFromWaifuPics()
case "Hmtai":
case "Hmtai api":
startHmtaiLoader()
case "Nekos api":
loadImageFromNekosapi()
Expand Down

0 comments on commit 083f3d9

Please sign in to comment.