5 Commits

5 changed files with 78 additions and 21 deletions

View File

@@ -55,15 +55,7 @@ module W3DHubLauncher
if result.okay?
hash = JSON.parse(result.data)
MemCache[:settings].account = W3DHubLauncher::Worker::Api::Settings::Account.create(
user_id: hash["userid"],
username: hash["username"],
displayname: hash["displayname"],
avatar_uri: "",
access_token: hash["accessToken"],
refresh_token: hash["refreshToken"],
access_token_expiration_time: hash["accessTokenExpiry"]
)
MemCache[:settings].account = W3DHubLauncher::Worker::Api::Settings::Account.new(hash)
Worker::Api.update_settings(MemCache[:settings]) do |settings_result|
if settings_result.okay?

View File

@@ -38,10 +38,11 @@ module W3DHubLauncher
link("GAMES",height: 1.0, text_v_align: :center, font: FONT_BLACK, margin_left: PADDING) { page(Page::Games) }
link("SERVERS",height: 1.0, text_v_align: :center, font: FONT_BLACK, margin_left: PADDING) { page(Page::ServerBrowser) }
stack(fill: true)
image safe_get_image("#{ROOT_PATH}/media/icons/import.png"), height: 40, color: 0xff_bbbbbb, tip: "Downloads" do |img|
dialog(Dialog::Downloads)
stack(v_align: :center) do
button safe_get_image("#{ROOT_PATH}/media/icons/import.png"), image_height: 40, color: 0xff_bbbbbb, padding_left: QUARTER_PADDING, padding_right: QUARTER_PADDING, tip: "Downloads" do |img|
dialog(Dialog::Downloads)
end
end
image safe_get_image("#{ROOT_PATH}/media/icons/information.png"), height: 40, color: 0xff_bbbbbb, tip: "Notifications"
end
# application task status bar container
@application_task_status_bar_container = stack(width: 1.0, fill: true, margin_left: PADDING, visible: false) do
@@ -335,10 +336,11 @@ module W3DHubLauncher
def populate_account_information
account = MemCache[:settings].account
avatar_path = account ? "#{CACHE_PATH}/avatar_#{account&.user_id}#{File.extname(account&.avatar_uri)}" : nil
@account_container.clear do
# self avatar container
stack(width: 80, height: 1.0, background_image: rounded_avatar(safe_get_image("#{ROOT_PATH}/media/default.png")), tag: :account_avatar) do
stack(width: 80, height: 1.0, background_image: rounded_avatar(safe_get_image(avatar_path || "#{ROOT_PATH}/media/default.png")), tag: :account_avatar) do
# self online state container
stack(
width: 20,
@@ -346,9 +348,13 @@ module W3DHubLauncher
v_align: :bottom,
h_align: :right,
background_image: safe_get_image("#{ROOT_PATH}/media/ui/circle_small.png"),
background_image_color: account.signed_in? ? 0xff_26a269 : 0xff_77767b,
background_image_color: 0xff_77767b,
tag: :account_online_state
)
) do
if account.signed_in?
image safe_get_image("#{ROOT_PATH}/media/ui/circle_small.png"), width: 1.0, height: 1.0, color: 0xff_26a269, padding: 1
end
end
end
stack(fill: true, height: 1.0, margin_left: HALF_PADDING) do
@@ -377,6 +383,14 @@ module W3DHubLauncher
flow(fill: true)
end
end
if account && !account.avatar_uri.empty?
img = find_element_by_tag(@account_container, :account_avatar)
remote_image(avatar_path, url: account.avatar_uri, element: img) do |e, path|
e&.background_image = rounded_avatar(safe_get_image(path))
end
end
end
def button_up(id)

View File

@@ -2,6 +2,7 @@ module W3DHubLauncher
LARGE_PADDING = 40
PADDING = 20
HALF_PADDING = 10
QUARTER_PADDING = 5
ALPHA_BLACK = 0x88_000000
ALPHA_GRAY = 0x88_5e5c64

View File

@@ -372,7 +372,7 @@ module W3DHubLauncher
content_length: content_length
})
message_requester(query.request_id, Request::STATUS_IN_PROGRESS, progress_result.data, progress_result.error)
message_requester(request_id: query.request_id, status: Request::STATUS_IN_PROGRESS, data: progress_result.data, error: progress_result.error)
end
end

View File

@@ -93,21 +93,71 @@ module W3DHubLauncher
result
end
def user_login(username, password, &block)
def user_login(username, password)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({username: username, password: password}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/user-login", method: :post, body: body, headers: headers(form_encoded: true))
pp response
if response.okay?
hash = JSON.parse(response.data)
user_details_result = fetch_user_details(Integer(hash["userid"]))
user_details_hash = user_details_result.okay? ? JSON.parse(user_details_result.data) : {}
account = W3DHubLauncher::Worker::Api::Settings::Account.create(
user_id: hash["userid"],
username: hash["username"],
displayname: hash["displayname"],
avatar_uri: user_details_hash["avatar-uri"] || "",
access_token: hash["accessToken"],
refresh_token: hash["refreshToken"],
access_token_expiration_time: hash["accessTokenExpiry"]
)
result.data = account.to_json
end
result
end
def refresh_user_login()
def refresh_user_login(refresh_token)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({refreshToken: refresh_token}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/user-login", method: :post, body: body, headers: headers(form_encoded: true))
if response.okay?
hash = JSON.parse(response.data)
user_details_result = fetch_user_details(Integer(hash["userid"]))
user_details_hash = user_details_result.okay? ? JSON.parse(user_details_result.data) : {}
account = W3DHubLauncher::Worker::Api::Settings::Account.create(
user_id: hash["userid"],
username: hash["username"],
displayname: hash["displayname"],
avatar_uri: user_details_hash["avatar-uri"] || "",
access_token: hash["accessToken"],
refresh_token: hash["refreshToken"],
access_token_expiration_time: hash["accessTokenExpiry"]
)
result.data = account.to_json
end
result
end
def fetch_user_details()
def fetch_user_details(user_id)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({id: user_id}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-user-details", method: :post, body: body, headers: headers(form_encoded: true))
result.data = response.data if response.okay?
result
end
def fetch_applications
@@ -152,7 +202,7 @@ module W3DHubLauncher
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-server-events", method: :post, body: "data={\"serverPath\":\"#{category}\"}", headers: headers(form_encoded: true))
end
def fetch_test_events(category)
def fetch_test_events
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-testing-times")
end