Skip to content

Commit

Permalink
Local icons support
Browse files Browse the repository at this point in the history
  • Loading branch information
remixer-dec committed Jun 16, 2024
1 parent 9555a47 commit 50b550a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ let app = {
const fbHost = 'https://firebasestorage.googleapis.com/'
const fbPrefix = 'v0/b/rugame-db' + '.appspot.com/o/public%2F'
const FirebaseScreenshotLoader = V2RangedScreenshotLoader.bind(null, fbHost, fbPrefix, true)
const FirebaseIconLoader = V3IconLoader.bind(null, fbHost, fbPrefix)
const FirebaseIconLoader = V3IconLoader.bind(null, fbHost, fbPrefix, '', true)
const IconLoader = import.meta.env.PROD ? FirebaseIconLoader : V3IconLoader

app = PV.reactive(app)
app.datasource = new DataSourceManager(V2DataSource, FirebaseIconLoader, FirebaseScreenshotLoader, app)
app.datasource = new DataSourceManager(V2DataSource, IconLoader, FirebaseScreenshotLoader, app)
Router.initialize(app)

window.app = app
Expand Down
17 changes: 13 additions & 4 deletions src/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ class IconLoader {
}

class V3IconLoader extends IconLoader {
constructor(host, prefix) {
constructor(host, prefix, postfix = '/data', replaceSlashes = false) {
super()
this.host = host
this.prefix = prefix
this.prefix = prefix || ''
this.postfix = postfix
this.grid = this.postfix + '/icon_grid.png?alt=media'
this.replaceSlashes = replaceSlashes
this.grid = replaceSlashes ? this.grid.replace(/\//g, '%2F') : this.grid
}

getIcon(appId, dir) {
if (app.config.icons_grid) {
return this.host + this.prefix + ((dir + '/icon_grid.png?alt=media').replace(/\//g, '%2F'))
return this.host + this.prefix + dir + this.grid
} else {
return this.getDefaultIcon(dir)
}
Expand All @@ -52,9 +56,14 @@ class V3IconLoader extends IconLoader {

loadIconsGrid(dir) {
if (!app.config.icons_grid) return
if (!this.host) {
this.host = app.datasource.ds.host
}
if (app.datasource.ds.contentDirs.indexOf(dir) === -1) return this.getDefaultIcon(dir)
loadedDirs[dir] = false
const url = this.host + this.prefix + ((dir + '/icons.meta.json?alt=media').replace(/\//g, '%2F'))
let metadataFilePath = '/icons.meta.json?alt=media'
metadataFilePath = this.replaceSlashes ? metadataFilePath.replace(/\//g, '%2F') : metadataFilePath
const url = this.host + this.prefix + (dir + this.postfix + metadataFilePath)
fetchJSON(url).then(metadata => {
const [width, height] = metadata.resolution
const missing = metadata.missing === 'all' ? {has: x => true} : new Set(metadata.missing)
Expand Down
3 changes: 3 additions & 0 deletions src/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ main {
image-rendering: pixelated;
border-radius: 4px;
}
.mdl-layout__header > .mdl-layout-icon {
top: 20px
}
.external-icon {
fill: white;
width: 34px;
Expand Down

0 comments on commit 50b550a

Please sign in to comment.