Skip to content

Commit

Permalink
0.2.2 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytumal committed Aug 25, 2024
1 parent 0982279 commit d21f304
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 47 deletions.
44 changes: 44 additions & 0 deletions android/.idea/other.xml

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

4 changes: 2 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "web.bmdominatezz.gravy"
minSdk = 26
targetSdk = 34
versionCode = 21 //011
versionName = "0.2.1-beta.2"
versionCode = 22 //011
versionName = "0.2.2-beta.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import android.net.Uri;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;


public class AppChangeReceiver {
MainActivity mainActivity;
static MainActivity mainActivity;

AppChangeReceiver(MainActivity m) {
this.mainActivity = m;
Expand All @@ -30,12 +33,26 @@ public void onReceive(Context context, Intent intent) {
Uri data = intent.getData();
String packageName = data != null ? data.getSchemeSpecificPart() : null;
// Handle the app install here
JSONObject argument = new JSONObject();
try {
argument.put("packagename", packageName);
} catch (JSONException e) {
throw new RuntimeException(e);
}
mainActivity.webEvents.dispatchEvent(WebEvents.events.appInstall, argument);
Log.d("TAG", "onReceive: APP INSTALL");
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
// App uninstalled
Uri data = intent.getData();
String packageName = data != null ? data.getSchemeSpecificPart() : null;
// Handle the app uninstall here
JSONObject argument = new JSONObject();
try {
argument.put("packagename", packageName);
} catch (JSONException e) {
throw new RuntimeException(e);
}
mainActivity.webEvents.dispatchEvent(WebEvents.events.appUninstall, argument);
Log.d("TAG", "onReceive: APP UNINSTALL");
}
}
Expand Down
12 changes: 9 additions & 3 deletions android/app/src/main/java/web/bmdominatezz/gravy/WebEvents.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package web.bmdominatezz.gravy;

import android.content.Context;
import android.util.Log;
import android.webkit.WebView;

import org.json.JSONObject;
Expand All @@ -14,7 +15,9 @@ public enum events {
backButtonPress,
homeButtonPress,
activityPause,
activityResume
activityResume,
appInstall,
appUninstall
}

WebEvents(Context c, WebView w) {
Expand All @@ -23,11 +26,14 @@ public enum events {
}

public void dispatchEvent(String eventName, JSONObject arguments) {
String script = "";
if (arguments == null) {
webView.evaluateJavascript("window.dispatchEvent(new Event(\"" + eventName + "\"))", null);
script = "window.dispatchEvent(new CustomEvent(\"" + eventName + "\"))";
} else {
webView.evaluateJavascript("window.dispatchEvent(new Event(\"" + eventName + "\"), " + arguments.toString() + ")", null);
script = "window.dispatchEvent(new CustomEvent(\"" + eventName + "\", {detail:" + arguments.toString() + "}))";
}
Log.d("groovelauncher", "dispatchEventScript: " + script);
webView.evaluateJavascript(script, null);
}

public void dispatchEvent(events eventName, JSONObject arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.json.JSONObject;

public class WebInterface {
private MainActivity mainActivity;
private final MainActivity mainActivity;

WebInterface(MainActivity mainActivity) {
this.mainActivity = mainActivity;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "npm run build:webpack && npm run build:scss && npm run build:internal-apps && npm run build:android",
"build:webpack": "npx webpack",
"build:scss": "sass --no-source-map src/styles.scss www/dist/styles.css",
"build:android": "cp -R www/* android/app/src/main/assets/",
"build:android": "rm -rf android/app/src/main/assets/* && cp -R www/* android/app/src/main/assets/",
"build:internal-apps": "node build-internal-apps.js",
"build:production": "rm -rf android/app/src/main/assets/* && npx webpack --env production && sass --no-source-map --style=compressed src/styles.scss www/dist/styles.css && node build-internal-apps.js --production && npm run build:android"
},
Expand Down
27 changes: 17 additions & 10 deletions src/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import GrooveMock from "./scripts/GrooveMock.js";

const GrooveMockInstance = !window.Groove
if (GrooveMockInstance) {
window.Groove = new GrooveMock("./mock/apps.json")
document.body.classList.add("groove-mock")
}
import startUpSequence from "./scripts/startUpSequence";
import jQuery from "jquery";
window.$ = jQuery
import appTransition from "./scripts/appTransition.js";
import clickDetectorConfig from "./scripts/clickDetector.js";
import { GrooveScroll, GrooveSlide } from "./scripts/overscrollFramework.js";
import { boardMethods } from "./scripts/GrooveBoard";
import imageStore from "./scripts/imageStore.js";
import startUpSequence from "./scripts/startUpSequence";
import detectDeviceType from "./scripts/detectDeviceType";
import GrooveBoard from "./scripts/GrooveBoard";
import iconPackConverter from "./scripts/iconPack.js";
Expand All @@ -17,13 +24,10 @@ import applyOverscroll from "./scripts/overscrollFramework.js";
window.normalizeDiacritics = (input = "") => {
return normalizeSync(input)
}
import GrooveMock from "./scripts/GrooveMock.js";
import BScroll from "better-scroll";

window.imageStore = imageStore
const GrooveMockInstance = !window.Groove
if (GrooveMockInstance) {
window.Groove = new GrooveMock("./mock/apps.json")
}

var allappsarchive = []
window["allappsarchive"] = allappsarchive

Expand All @@ -38,14 +42,17 @@ const scrollers = {
scrollX: false,
scrollY: true,
mouseWheel: true,

}),
app_page_scroller: new GrooveScroll('#main-home-slider > div > div:nth-child(2) > div > div.app-list', {
scrollX: false,
scrollY: true,
mouseWheel: true,

})
}),
letter_selector_scroller: new GrooveScroll('div.letter-selector', {
scrollX: false,
scrollY: true,
mouseWheel: true,
}),
}

window.scrollers = scrollers
Expand Down Expand Up @@ -188,7 +195,7 @@ startUpSequence([
groupedEntries.push(letter_selector_entries[0].slice(i, i + 4));
}

const letterSelectorDiv = $('.letter-selector');
const letterSelectorDiv = $('.letter-selector > div');

groupedEntries.forEach(group => {
const $rowDiv = $('<div>', { class: 'letter-selector-row' });
Expand Down
43 changes: 40 additions & 3 deletions src/scripts/GrooveBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ const backendMethods = {
if (document.querySelectorAll(`div.groove-home-tile[packagename="${tile.p}"]`).length > 0) return

const homeTile = GrooveElements.wHomeTile(tile.ii, tile.i, tile.t, tile.p, "", tile.s)
if(iconPackDB[tile.p]){
if(iconPackDB[tile.p].pack == 0){
homeTile.classList.add("iconpack0")
}
}
const el = window.tileListGrid.addWidget(
homeTile,
{
Expand Down Expand Up @@ -583,10 +588,10 @@ const backendMethods = {
},
},
wallpaper: {
context: new OffscreenCanvas(
context: window["OffscreenCanvas"] ? new OffscreenCanvas(
window.innerWidth,
window.innerHeight + 50
).getContext("2d"),
).getContext("2d") : document.createElement("canvas"),
load: async (image, doNotSave = false) => {
if (window.lastClippedWallpaper)
URL.revokeObjectURL(window.lastClippedWallpaper);
Expand All @@ -608,7 +613,7 @@ const backendMethods = {
ctx.canvas.width,
ctx.canvas.height
);
const blob = await ctx.canvas.convertToBlob()
const blob = await getCanvasBlob(ctx.canvas)
const rurl = await backendMethods.wallpaper.loadBlob(blob)
if (!doNotSave) {
await imageStore.saveImage("wallpaper", blob);
Expand Down Expand Up @@ -668,6 +673,13 @@ const backendMethods = {
if (await imageStore.hasImage("wallpaper")) imageStore.removeImage("wallpaper")
},
},
appInstall: (packagename) => {
GrooveBoard.backendMethods.reloadApps()
},
appUninstall: (packagename) => {
tileListGrid.removeWidget(document.querySelector(`div.groove-home-tile[packagename="${packagename}"]`))
GrooveBoard.backendMethods.reloadApps()
}
};
function listHistory() {
return
Expand All @@ -686,6 +698,12 @@ window.addEventListener("homeButtonPress", function () {
//if(!!window.canPressHomeButton)
backendMethods.navigation.home();
});
window.addEventListener("appInstall", function (e) {
backendMethods.appInstall(e.detail.packagename)
});
window.addEventListener("appUninstall", function (e) {
backendMethods.appUninstall(e.detail.packagename)
});
window.addEventListener('message', (event) => {
if (event.data["action"]) {
if (event.data.action == "setTheme") {
Expand All @@ -702,5 +720,24 @@ window.addEventListener('message', (event) => {
}
}
});
function getCanvasBlob(canvas, mimeType = 'image/png') {
if (canvas["convertToBlob"]) {
// If the canvas is an OffscreenCanvas, use convertToBlob
return canvas.convertToBlob({ type: mimeType });
} else if (canvas instanceof HTMLCanvasElement) {
// If the canvas is a regular HTMLCanvasElement, use toBlob
return new Promise((resolve, reject) => {
canvas.toBlob(blob => {
if (blob) {
resolve(blob);
} else {
reject(new Error('Failed to convert canvas to blob'));
}
}, mimeType);
});
} else {
return Promise.reject(new Error('Invalid canvas type'));
}
}

export default { boardMethods, backendMethods };
4 changes: 4 additions & 0 deletions src/scripts/appTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ const appTransition = {
}, 2000);
startAnim()
setTimeout(() => {
scrollers.main_home_scroller.scrollTo(0,0)
mainHomeSlider.style.visibility = "hidden"
console.log("hey")
document.querySelectorAll(".app-transition-selected").forEach(e => e.classList.remove("app-transition-selected"))
}, 600);
},
onResume: (back = false, firstintro = false) => {
mainHomeSlider.style.removeProperty("visibility")
clearTimeout(window.appTransitionLaunchError)
scrollers.main_home_scroller.scrollTo(0, 0)
mainHomeSlider.classList.remove("app-transition-on-pause")
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/grooveMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GrooveMock {

}
getSystemInsets() {
return JSON.stringify({ left: 0, top: 102, right: 0, bottom: 50 })
return JSON.stringify({ left: 0, top: 20, right: 0, bottom: 50 })
}
retrieveApps() {
return JSON.stringify(this.#retrievedApps)
Expand Down
20 changes: 2 additions & 18 deletions src/scripts/startUpSequence.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
const timeout = 10000


const startUpSequence = function (loaders, finish) {
var timeouttimer
function onError(e) {
clearTimeout(timeouttimer)
// console.error(e.message)
try {
const loader = document.getElementById("loader")
loader.style.backgroundColor = "red"
loader.style.justifyContent = "start"
loader.style.paddingLeft = "30px"
loader.innerText = ":(\nOh no!\n"
loader.innerHTML += "<span class='errormessage'></span>"
const errormessage = loader.querySelector(".errormessage")
errormessage.style.display = "contents"
errormessage.style.fontSize = "30px"
errormessage.innerText = e.message
} catch (error) {
alert(":(\nOh no!\n" + e.message)
}
throw e;

window.throwError(e)
}

var lastindex = 0
Expand Down
Loading

0 comments on commit d21f304

Please sign in to comment.