Skip to content

Commit

Permalink
feat: create function to update legendary metadata when necessary + a…
Browse files Browse the repository at this point in the history
…dd visual indicator
  • Loading branch information
vapidinfinity committed Oct 19, 2024
1 parent 11f6dbb commit 84b7f80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
7 changes: 2 additions & 5 deletions Mythic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/
try? files.moveItem(at: legendaryOldConfig, to: Legendary.configurationFolder)
}

// MARK: Refresh legendary metadata
Task(priority: .utility) {
try? await Legendary.command(arguments: ["status"], identifier: "refreshMetadata") { _ in }
}

Legendary.updateMetadata()

// MARK: Autosync Epic savedata
Task(priority: .utility) {
try? await Legendary.command(arguments: ["sync-saves"], identifier: "sync-saves") { _ in }
Expand Down
17 changes: 14 additions & 3 deletions Mythic/Utilities/Legendary/LegendaryInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,24 @@ final class Legendary {

return nil
}


/// Create an asynchronous task to update Legendary's stored metadata.
static func updateMetadata() {
if VariableManager.shared.getVariable("isLegendaryFetchingInstallableGames") != true {
Task(priority: .utility) {
VariableManager.shared.setVariable("isLegendaryFetchingInstallableGames", value: true)
try? await command(arguments: ["list"], identifier: "fetchInstallableGames", waits: true) { _ in }
VariableManager.shared.setVariable("isLegendaryFetchingInstallableGames", value: false)
}
}
}

/**
Retrieves game thumbnail image from legendary's downloaded metadata.

- Parameters:
- of: The game to fetch the thumbnail of.
- type: The aspect ratio of the image to fetch the thumbnail of.
- of: The game to fetch the thumbnail of.
- type: The aspect ratio of the image to fetch the thumbnail of.

- Returns: The URL of the retrieved image.
*/
Expand Down
13 changes: 11 additions & 2 deletions Mythic/Views/Navigation/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import SwordRPC
/// A view displaying the user's library of games.
struct LibraryView: View {
@ObservedObject private var operation: GameOperation = .shared

@ObservedObject private var variables: VariableManager = .shared

// MARK: - State Variables
@State private var isGameImportSheetPresented = false
@State private var filterOptions: GameListFilterOptions = .init()
Expand All @@ -44,7 +45,15 @@ struct LibraryView: View {
}
.help("Import a game")
}


ToolbarItem(placement: .status) {
if variables.getVariable("isLegendaryFetchingInstallableGames") == true {
ProgressView()
.controlSize(.small)
.help("Mythic is checking your Epic library for new games.")
}
}

ToolbarItem(placement: .confirmationAction) {
Toggle("Installed", isOn: $filterOptions.showInstalled)
}
Expand Down

0 comments on commit 84b7f80

Please sign in to comment.