Skip to content

Commit

Permalink
initialize apps asynchronously in GrooveMock and update related calls
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytumal committed Jan 17, 2025
1 parent 3b03c07 commit 8ef2e41
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
Empty file added scripts/build-pages.js
Empty file.
1 change: 1 addition & 0 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ window.GrooveRole = "main"
if (GrooveMockInstance) {
//window.Groove = new GrooveMock("./mock/apps.json")
window.Groove = new GrooveMock("./mock/apps.json")
await Groove.initializeApps()
window.BuildConfig = new BuildConfigMock()
document.body.classList.add("groove-mock")
}
Expand Down
54 changes: 29 additions & 25 deletions src/scripts/grooveMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,39 @@ class GrooveMock {
this.#retrievedApps = [];

// Use async/await pattern instead of callback
this.#initializeApps();
this.initializeApps();
}

async #initializeApps() {
try {
const response = await fetch(this.mockURL);
const data = await response.json();
initializeApps() {
return new Promise(async (resolve, reject) => {
try {
const response = await fetch(this.mockURL);
const data = await response.json();

this.#retrievedApps = data.apps
.filter(app => app.packageName !== 'web.bmdominatezz.gravy')
.map(app => ({
packageName: app.packageName,
label: app.label,
type: app.type
}));
this.#retrievedApps = data.apps
.filter(app => app.packageName !== 'web.bmdominatezz.gravy')
.map(app => ({
packageName: app.packageName,
label: app.label,
type: app.type
}));

this.#retrievedApps.push({
packageName: CONSTANTS.INTERNAL_SETTINGS_APP,
label: 'Groove Settings',
type: 0
});
this.#retrievedApps.push({
packageName: CONSTANTS.INTERNAL_TWEAKS_APP,
label: 'Groove Tweaks',
type: 0
});
} catch (error) {
console.error('Failed to initialize apps:', error);
}
this.#retrievedApps.push({
packageName: CONSTANTS.INTERNAL_SETTINGS_APP,
label: 'Groove Settings',
type: 0
});
this.#retrievedApps.push({
packageName: CONSTANTS.INTERNAL_TWEAKS_APP,
label: 'Groove Tweaks',
type: 0
});
resolve(true)
} catch (error) {
console.error('Failed to initialize apps:', error);
reject(error);
}
})
}

getSystemInsets() {
Expand Down
5 changes: 3 additions & 2 deletions src/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ window.GrooveRole = "main"
if (GrooveMockInstance) {
//window.Groove = new GrooveMock("./mock/apps.json")
window.Groove = new GrooveMock("./mock/apps.json")
await Groove.initializeApps()
window.BuildConfig = new BuildConfigMock()
document.body.classList.add("groove-mock")
}
Expand Down Expand Up @@ -265,7 +266,7 @@ document.querySelector("#page-readme button.right-btn").addEventListener("flowCl
goToPage(7)

setTimeout(() => {
location.href = new URL("./",location).href
location.href = new URL("./", location).href
}, 500);
}

Expand Down Expand Up @@ -373,7 +374,7 @@ if (firstWelcome && localStorage["welcomeLocalesDownloaded"] != "true") {
var localesFinished = false
var localeProceed = true
setTimeout(async () => {
if(!BuildConfig.signed()){
if (!BuildConfig.signed()) {
updateLoaderText("")
finishLocale()
return;
Expand Down

0 comments on commit 8ef2e41

Please sign in to comment.