Skip to content

Commit

Permalink
v0.0.1-alpha.6 - Finalizing the settings account tab.
Browse files Browse the repository at this point in the history
Added a done button which closes the settings UI.
Displays a warning before the user logs out of the last saved account. If they proceed with the logout, they will be redirected to the login UI.
Added startup handling for when the user has 0 saved accounts. They will be brought directly to the login UI.
Accounts are now validated each time they are switched.
  • Loading branch information
dscalzi committed May 31, 2018
1 parent 91c842d commit 74a60a6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 21 deletions.
42 changes: 41 additions & 1 deletion app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,13 @@ body, button {
#settingsNavItemsContent {
display: flex;
flex-direction: column;
position: relative;
}

/* Navigation item shared styles. */
.settingsNavItem {
background: none;
border: none;
border-radius: 7px;
text-align: left;
margin: 5px 0px;
padding: 0px 20px;
Expand All @@ -948,6 +948,46 @@ body, button {
text-shadow: none;
}

/* Content container for the done button. */
#settingsNavContentBottom {
position: absolute;
bottom: 20%;
}

/* Settings navigational divider. */
.settingsNavDivider {
width: 75%;
height: 0.5px;
background: rgba(255, 255, 255, 0.75);
margin-left: auto;
margin-bottom: 25px;
}

/* Settings done button styles. */
#settingsNavDone {
background: none;
border: none;
text-align: left;
margin: 5px 0px;
padding: 0px 20px;
color: white;
cursor: pointer;
outline: none;
transition: 0.25s ease;
}
#settingsNavDone:hover,
#settingsNavDone:focus {
text-shadow: 0px 0px 20px white, 0px 0px 20px white, 0px 0px 20px white;
}
#settingsNavDone:active {
text-shadow: 0px 0px 20px rgba(255, 255, 255, 0.75), 0px 0px 20px rgba(255, 255, 255, 0.75), 0px 0px 20px rgba(255, 255, 255, 0.75);
color: rgba(255, 255, 255, 0.75);
}
#settingsNavDone:disabled {
color: rgba(255, 255, 255, 0.75);
pointer-events: none;
}

/* Right hand side of the settings container, for tabs. */
#settingsContainerRight {
height: 100%;
Expand Down
68 changes: 52 additions & 16 deletions app/assets/js/scripts/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const settingsNavDone = document.getElementById('settingsNavDone')
const settingsAddAccount = document.getElementById('settingsAddAccount')
const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts')

Expand Down Expand Up @@ -32,6 +33,11 @@ function setupSettingsTabs(){
})
}

/* Closes the settings view and saves all data. */
settingsNavDone.onclick = () => {
switchView(getCurrentView(), VIEWS.landing)
}

/**
* Account Management Tab
*/
Expand Down Expand Up @@ -64,9 +70,7 @@ function bindAuthAccountSelect(){
}
val.setAttribute('selected', '')
val.innerHTML = 'Selected Account ✔'
ConfigManager.setSelectedAccount(val.closest('.settingsAuthAccount').getAttribute('uuid'))
ConfigManager.save()
updateSelectedAccount(ConfigManager.getSelectedAccount())
setSelectedAccount(val.closest('.settingsAuthAccount').getAttribute('uuid'))
}
})
}
Expand All @@ -79,21 +83,53 @@ function bindAuthAccountSelect(){
function bindAuthAccountLogOut(){
Array.from(document.getElementsByClassName('settingsAuthAccountLogOut')).map((val) => {
val.onclick = (e) => {
const parent = val.closest('.settingsAuthAccount')
const uuid = parent.getAttribute('uuid')
const prevSelAcc = ConfigManager.getSelectedAccount()
AuthManager.removeAccount(uuid).then(() => {
if(uuid === prevSelAcc.uuid){
const selAcc = ConfigManager.getSelectedAccount()
refreshAuthAccountSelected(selAcc.uuid)
updateSelectedAccount(selAcc)
}
})
$(parent).fadeOut(250, () => {
parent.remove()
})
let isLastAccount = false
if(Object.keys(ConfigManager.getAuthAccounts()).length === 1){
isLastAccount = true
setOverlayContent(
'Warning<br>This is Your Last Account',
'In order to use the launcher you must be logged into at least one account. You will need to login again after.<br><br>Are you sure you want to log out?',
'I\'m Sure',
'Cancel'
)
setOverlayHandler(() => {
processLogOut(val, isLastAccount)
switchView(getCurrentView(), VIEWS.login)
toggleOverlay(false)
})
setDismissHandler(() => {
toggleOverlay(false)
})
toggleOverlay(true, true)
} else {
processLogOut(val, isLastAccount)
}

}
})
}

/**
* Process a log out.
*
* @param {Element} val The log out button element.
* @param {boolean} isLastAccount If this logout is on the last added account.
*/
function processLogOut(val, isLastAccount){
const parent = val.closest('.settingsAuthAccount')
const uuid = parent.getAttribute('uuid')
const prevSelAcc = ConfigManager.getSelectedAccount()
AuthManager.removeAccount(uuid).then(() => {
if(!isLastAccount && uuid === prevSelAcc.uuid){
const selAcc = ConfigManager.getSelectedAccount()
refreshAuthAccountSelected(selAcc.uuid)
updateSelectedAccount(selAcc)
validateSelectedAccount()
}
})
$(parent).fadeOut(250, () => {
parent.remove()
})
}

/**
Expand Down
10 changes: 8 additions & 2 deletions app/assets/js/scripts/uibinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ function showMainUI(){
document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
$('#main').show()

const isLoggedIn = Object.keys(ConfigManager.getAuthAccounts()).length > 0

// If this is enabled in a development environment we'll get ratelimited.
// The relaunch frequency is usually far too high.
if(!isDev){
if(!isDev && isLoggedIn){
validateSelectedAccount().then((v) => {
if(v){
console.log('%c[AuthManager]', 'color: #209b07; font-weight: bold', 'Account access token validated.')
Expand All @@ -76,7 +78,11 @@ function showMainUI(){
if(ConfigManager.isFirstLaunch()){
$(VIEWS.welcome).fadeIn(1000)
} else {
$(VIEWS.landing).fadeIn(1000)
if(isLoggedIn){
$(VIEWS.landing).fadeIn(1000)
} else {
$(VIEWS.login).fadeIn(1000)
}
}

setTimeout(() => {
Expand Down
4 changes: 4 additions & 0 deletions app/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<button class="settingsNavItem" rSc="settingsTabMinecraft">Minecraft</button>
<button class="settingsNavItem" rSc="settingsTabJava">Java</button>
<button class="settingsNavItem" rSc="settingsTabLauncher">Launcher</button>
<div id="settingsNavContentBottom">
<div class="settingsNavDivider"></div>
<button id="settingsNavDone">Done</button>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "westeroscraftlauncher",
"version": "0.0.1-alpha.6",
"version": "0.0.1-alpha.7",
"description": "Custom modded launcher for Westeroscraft",
"productName": "WesterosCraft Launcher",
"main": "index.js",
Expand Down

1 comment on commit 74a60a6

@dscalzi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit title should be alpha 7 >.<

Please sign in to comment.