Skip to content

Commit

Permalink
Finalize BareSwitcher, clean up the edges n whatnot
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenyDEV committed Jan 3, 2023
1 parent 8061f62 commit dd34702
Show file tree
Hide file tree
Showing 12 changed files with 749 additions and 582 deletions.
1 change: 0 additions & 1 deletion static/arc-sw.js

This file was deleted.

3 changes: 2 additions & 1 deletion static/index.html

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions static/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<!-- Embed -->

<script src="../uv/uv.bundle.js"></script>
<script src="../resources/appModules/selectBare.js"></script>

<script src="../resources/appModules/BareSwitcher.js"></script>
<script src="../resources/options.js"></script>
<meta name="theme-color" content="#5a189a">
<meta property=og:title content=Nebula>
<meta property="og:type" content="website" />
Expand Down Expand Up @@ -187,7 +187,10 @@ <h1 class="nebHeader" style='margin-left: .5%; font-family: "Roboto"; color: #4d
}
themeSelector.value = themeStored
proxySel.value = proxyStored
document.getElementById("bareLocationInput").value = localStorage.getItem("_BareLocation")

getBareLocation().then(bareLocation => {
document.getElementById("bareLocationInput").value = bareLocation;
});

</script>
</body>
Expand Down
103 changes: 103 additions & 0 deletions static/resources/appModules/BareSwitcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// NOTE: THIS FILE MUST BE ACCOMPANIED BY THE ULTRAVIOLET BUNDLE BECAUSE IT CONTAINS THE INDEXEDDB LIBRARY

const dbPromise = Ultraviolet.openDB('keyval-store', 1, {
upgrade (db) {
db.createObjectStore('keyval')
}
})

function getBareLocation () {
return dbPromise
.then(db => db.get('keyval', 'bareLocation'))
.then(value => value || '')
}

self.storage = {
async get (key) {
return (await dbPromise).get('keyval', key)
},

async set (key, val) {
return (await dbPromise).put('keyval', val, key)
},

async del (key) {
return (await dbPromise).delete('keyval', key)
}
}

function setBareLocation (location) {
if (
/^http(s?):\/\//.test(location) ||
(location.includes('.') && val.substr(0, 1) !== ' ') ||
location.includes('/bare/')
) {
storage.set('bareLocation', location)
return 'Bare is located at: ' + location
} else {
console.log(
'Invalid Location provided, please provide a server in the format of http(s)://server.domain.com/'
)
return 'Invalid Location provided'
}
}

function bareValidator (bareLocation) {
try {
// open a request to the bare location
var xmlHttp = new XMLHttpRequest()
xmlHttp.open('GET', bareLocation, false) // false for synchronous request
xmlHttp.send(null)
const _response = xmlHttp.responseText
// turn the response text into json

const response = JSON.parse(_response)

if (response.project.name === 'bare-server-node') {
console.log('Bare located at: ' + bareLocation + '')
return true
} else {
console.error('Bare not found at: ' + bareLocation)
return false
}
} catch (error) {
console.error(
'An error occured while attempting to identify the bare server at: ' +
bareLocation
)
return false
}
}

window.addEventListener('load', () => {
console.log('Loaded ')
const _loc = document.getElementById('bareLocationInput')
const indicator = document.getElementById('validIndicator')

// wait 3 seconds
setTimeout(() => {
if (bareValidator(_loc.value) === true) {
indicator.innerText = 'Connected to server: ' + _loc.value
indicator.style.color = '#42f851'
} else if (bareValidator(_loc.value) === false) {
indicator.innerText = 'Could not connect to server: ' + _loc.value
indicator.style.color = '#f45145bd'
}
}, 1000)

document
.getElementById('bareLocationInput')
.addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
if (bareValidator(_loc.value) === true) {
indicator.innerText = 'Connected to server: ' + _loc.value
indicator.style.color = '#42f851'
setBareLocation(_loc.value)
} else if (bareValidator(_loc.value) === false) {
_loc.value = ''
indicator.innerText = 'Could not connect to server: ' + _loc.value
indicator.style.color = '#f45145bd'
}
}
})
})
37 changes: 21 additions & 16 deletions static/resources/appModules/database-manager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// NOTE - This file is not used in the current version of the app.
// this is just a snippet of code that I am keeping for future reference.
// NOTE: THIS FILE MUST BE ACCOMPANIED BY THE ULTRAVIOLET BUNDLE BECAUSE IT CONTAINS THE INDEXEDDB LIBRARY


const dbPromise = Ultraviolet.openDB('keyval-store', 1, {
upgrade(db) {
db.createObjectStore('keyval');
},
});
upgrade (db) {
db.createObjectStore('keyval')
}
})

self.storage = {
async get(key) {
return (await dbPromise).get('keyval', key);
},
async set(key, val) {
return (await dbPromise).put('keyval', val, key);
},
async del(key) {
return (await dbPromise).delete('keyval', key);
},
}
async get (key) {
return (await dbPromise).get('keyval', key)
},

async set (key, val) {
return (await dbPromise).put('keyval', val, key)
},

async del (key) {
return (await dbPromise).delete('keyval', key)
}
}
74 changes: 0 additions & 74 deletions static/resources/appModules/selectBare.js

This file was deleted.

Loading

0 comments on commit dd34702

Please sign in to comment.