diff --git a/lib/api.rb b/lib/api.rb index 3323a88..8561114 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -123,8 +123,8 @@ class W3DHub # /apis/w3dhub/1/get-news # Client sends an Authorization header bearer token which is received from logging in (Optional) - # Client requests news for a specific application/game e.g.: data={"category":"ia"} - # Response is a JSON hash with a "highlighted" and "news" keys; the "news" on seems to be the desired one + # Client requests news for a specific application/game e.g.: data={"category":"ia"} ("launcher-home" retrieves the weekly hub updates) + # Response is a JSON hash with a "highlighted" and "news" keys; the "news" one seems to be the desired one def self.news(category) response = W3DHUB_API_CONNECTION.post( path: "apis/w3dhub/1/get-news", diff --git a/lib/application_manager.rb b/lib/application_manager.rb index 0d3748d..6732f9c 100644 --- a/lib/application_manager.rb +++ b/lib/application_manager.rb @@ -84,11 +84,20 @@ class W3DHub end def uninstall(app_id, channel) - puts "Uninstall Request: #{app_idchannel}" + puts "Uninstall Request: #{app_id} #{channel}" return false if !installed?(app_id, channel) || installing?(app_id, channel) - @tasks.push(Uninstaller.new(app_id, channel)) + return false unless (game = Store.applications.games.find { |g| g.id == app_id}) + + push_state( + States::ConfirmDialog, + title: "Uninstall #{game.name}?", + message: "Are you sure you want to uninstall #{game.name} (#{channel})?", + accept_callback: proc { + @tasks.push(Uninstaller.new(app_id, channel)) + } + ) end def show_folder(app_id, channel, type) diff --git a/lib/states/confirm_dialog.rb b/lib/states/confirm_dialog.rb new file mode 100644 index 0000000..ff039d6 --- /dev/null +++ b/lib/states/confirm_dialog.rb @@ -0,0 +1,49 @@ +class W3DHub + class States + class ConfirmDialog < CyberarmEngine::GuiState + def setup + window.show_cursor = true + + theme(W3DHub::THEME) + + background 0xee_444444 + + stack(width: 1.0, height: 1.0, margin: 128, background: 0xee_222222) do + flow(width: 1.0, height: 0.1, padding: 8) do + background 0x88_000000 + + image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 0.04, align: :center, color: 0xaa_ff0000 + + tagline "#{@options[:title]}", width: 0.9, text_align: :center + end + + stack(width: 1.0, height: 0.78, padding: 16) do + para @options[:message], width: 1.0, text_align: :center + end + + flow(width: 1.0, height: 0.1, padding: 8) do + button "Cancel", width: 0.25 do + pop_state + @options[:cancel_callback]&.call + end + + stack(width: 0.5) + + button "Confirm", width: 0.25, background: 0xff_800000, hover: { background: 0xff_d00000 }, active: { background: 0xff_600000, color: 0xff_ffffff } do + pop_state + @options[:accept_callback]&.call + end + end + end + end + + def draw + previous_state&.draw + + Gosu.flush + + super + end + end + end +end diff --git a/w3dhub.rb b/w3dhub.rb index d2260ed..a51b64c 100644 --- a/w3dhub.rb +++ b/w3dhub.rb @@ -44,6 +44,7 @@ require_relative "lib/states/boot" require_relative "lib/states/interface" require_relative "lib/states/message_dialog" require_relative "lib/states/prompt_dialog" +require_relative "lib/states/confirm_dialog" require_relative "lib/api" require_relative "lib/api/service_status"