Skip to content

Commit

Permalink
0.5.5 => add permissions section to welcome page
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytumal committed Jan 31, 2025
1 parent e61509b commit ec73d73
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 5 deletions.
9 changes: 9 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />

<!--
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
Expand Down Expand Up @@ -48,6 +49,14 @@
<action android:name="web.bmdominatezz.gravy.client" />
</intent-filter>
</receiver>
<service
android:name=".NotificationListener"
android:exported="true"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package web.bmdominatezz.gravy;

import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;

public class NotificationListener extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d("NotificationListener", "Notification received: " + sbn.getPackageName());
// You can extract title, text, and other details from sbn.getNotification().extras
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.d("NotificationListener", "Notification removed: " + sbn.getPackageName());
}
}
51 changes: 51 additions & 0 deletions android/app/src/main/java/web/bmdominatezz/gravy/WebInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static web.bmdominatezz.gravy.GrooveExperience.*;

import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
Expand Down Expand Up @@ -38,6 +39,7 @@
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;

import com.google.android.material.color.MaterialColors;
Expand All @@ -56,8 +58,10 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.jar.JarException;

import kotlin.contracts.Returns;
import rikka.shizuku.Shizuku;
import rikka.shizuku.ShizukuBinderWrapper;

Expand Down Expand Up @@ -945,4 +949,51 @@ public String getSystemAccentColor(String arg) {
ContextCompat.getColor(mainActivity, android.R.color.darker_gray))));
}
}

@JavascriptInterface
public String checkPermission(String permission) {
if (Objects.equals(permission, "CONTACTS")) {
return String.valueOf(mainActivity.checkSelfPermission(android.Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED);
} else if (Objects.equals(permission, "PHOTOS")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
boolean hasImages = mainActivity.checkSelfPermission(android.Manifest.permission.READ_MEDIA_IMAGES)
== PackageManager.PERMISSION_GRANTED;
boolean hasVideos = mainActivity.checkSelfPermission(android.Manifest.permission.READ_MEDIA_VIDEO)
== PackageManager.PERMISSION_GRANTED;
return String.valueOf(hasImages && hasVideos);
} else {
return String.valueOf(mainActivity.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED);
}
} else if (Objects.equals(permission, "NOTIFICATIONS")) {
Set<String> enabledListeners = NotificationManagerCompat.getEnabledListenerPackages(mainActivity);
return String.valueOf(enabledListeners.contains(mainActivity.getPackageName()));
} else {
return "false";
}
}

@JavascriptInterface
public void requestPermission(String permission) {
mainActivity.runOnUiThread(() -> {
if ("CONTACTS".equals(permission)) {
Log.d("groovelauncher", "checkPermission: " + permission);
mainActivity.requestPermissions(new String[]{android.Manifest.permission.READ_CONTACTS}, 1);
} else if ("PHOTOS".equals(permission)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
mainActivity.requestPermissions(new String[]{
android.Manifest.permission.READ_MEDIA_IMAGES,
android.Manifest.permission.READ_MEDIA_VIDEO
}, 2);
} else {
mainActivity.requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
}
} else if ("NOTIFICATIONS".equals(permission)) {
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS);
intent.setData(Uri.parse("package:" + mainActivity.getPackageName()));
mainActivity.startActivity(intent);
}
});
}
}
38 changes: 38 additions & 0 deletions src/scripts/grooveMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,44 @@ class GrooveMock {
return "#AA00FF"
}
}
permissionMock ={
"CONTACTS": "false",
"PHOTOS": "false",
"NOTIFICATIONS": "false"
}
checkPermission(permission) {
switch (permission) {
case "CONTACTS":
return this.permissionMock["CONTACTS"]
break;
//photos
case "PHOTOS":
return this.permissionMock["PHOTOS"]
break;
case "NOTIFICATIONS":
return this.permissionMock["NOTIFICATIONS"]
break;
default:
return "false"
break;
}
}
requestPermission(permission) {
switch (permission) {
case "CONTACTS":
this.permissionMock["CONTACTS"] = "true"
break;
//photos
case "PHOTOS":
this.permissionMock["PHOTOS"] = "true"
break;
case "NOTIFICATIONS":
this.permissionMock["NOTIFICATIONS"] = "true"
break;
default:
break;
}
}
}// Create a reusable AudioContext
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();

Expand Down
17 changes: 17 additions & 0 deletions src/styles/pages/welcome.scss
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,21 @@ body.fade-out #background {
}
}
}
}
div.permission-group{
p.permission-title{
span.permission-icon{
&.checked{
color: var(--accent-color);
}
}
}
p.permission-description{
opacity: .5;
}
button.metro-button.link{
margin: 0px 0px 0px auto;
padding: 0px;
opacity: 1 !important;
}
}
57 changes: 52 additions & 5 deletions src/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { i18n, greetings } from './scripts/localeManager';
await i18n.init();
window.i18n = i18n;
window.greetings = greetings
const allPermissions = ["CONTACTS", "PHOTOS", "NOTIFICATIONS"]

import { GrooveMock, BuildConfigMock } from "./scripts/grooveMock.js";
window.GrooveRole = "main"
Expand Down Expand Up @@ -106,12 +107,15 @@ var setup = {
accessibility: true,
pick_accent: true,
whats_new: true,
permissions: true
}
const updatedApp = !!localStorage["lastVersion"]
setup.welcome_back = updatedApp
setup.update_wizard = updatedApp && localStorage["lastVersion"] != Groove.getAppVersion()
setup.pick_accent = !!!localStorage["accentColor"]
setup.accessibility = !!!localStorage["theme"] && !!!localStorage["UIScale"]
setup.permissions = !allPermissions.some(e => !Groove.checkPermission(e))

if (updatedApp) {
document.querySelector("#page-welcome > div.setup-body > h1").innerText = "Welcome back"
document.querySelector("#page-welcome > div.setup-body > p:nth-child(3)").innerText = "Let’s check a few details to enhance your updated experience."
Expand All @@ -127,9 +131,12 @@ document.querySelector("#page-welcome button.right-btn").addEventListener("flowC
} else if (setup.pick_accent) {
goToPage(4)
history.push(4)
} else if (setup.whats_new) {
} else if (setup.permissions) {
goToPage(5)
history.push(5)
} else if (setup.whats_new) {
goToPage(6)
history.push(6)
}
})
document.querySelector("#page-wizard button.left-btn").addEventListener("flowClick", (e) => {
Expand Down Expand Up @@ -170,9 +177,12 @@ document.querySelector("#update-loading button.right-btn").addEventListener("flo
} else if (setup.pick_accent) {
goToPage(4)
history.push(4)
} else if (setup.whats_new) {
} else if (setup.permissions) {
goToPage(5)
history.push(5)
} else if (setup.whats_new) {
goToPage(6)
history.push(6)
}
})
document.querySelector("#page-access button.left-btn").addEventListener("flowClick", (e) => {
Expand All @@ -185,9 +195,12 @@ document.querySelector("#page-access button.right-btn").addEventListener("flowCl
if (setup.pick_accent) {
goToPage(4)
history.push(4)
} else if (setup.whats_new) {
} else if (setup.permissions) {
goToPage(5)
history.push(5)
} else if (setup.whats_new) {
goToPage(6)
history.push(6)
}
})
document.querySelector("#accent-color-picker button.left-btn").addEventListener("flowClick", (e) => {
Expand All @@ -196,9 +209,23 @@ document.querySelector("#accent-color-picker button.left-btn").addEventListener(

})
document.querySelector("#accent-color-picker button.right-btn").addEventListener("flowClick", (e) => {
if (setup.whats_new) {
if (setup.permissions) {
goToPage(5)
history.push(5)
} else if (setup.whats_new) {
goToPage(6)
history.push(6)
}
})
document.querySelector("#page-permissions button.left-btn").addEventListener("flowClick", (e) => {
goToPage(history.slice(-2)[0])
history.pop()

})
document.querySelector("#page-permissions button.right-btn").addEventListener("flowClick", (e) => {
if (setup.whats_new) {
goToPage(6)
history.push(6)
}
})
document.querySelector("#page-readme button.left-btn").addEventListener("flowClick", (e) => {
Expand Down Expand Up @@ -255,7 +282,7 @@ document.querySelector("#page-readme button.right-btn").addEventListener("flowCl
} catch (error) {
}
}
goToPage(6);
goToPage(7);
setTimeout(() => {
if (GrooveBoard.backendMethods.setupNeeded()) {
GrooveBoard.alert("Setup Error", "Something went wrong while setting up. Please try again.", [{
Expand Down Expand Up @@ -325,6 +352,7 @@ function startFlipping() {
}

import { isChristmas, snowStorm } from "./scripts/fun/snow.js";
import { set } from "lodash";


function updateScript() {
Expand Down Expand Up @@ -444,5 +472,24 @@ if (firstWelcome && localStorage["welcomeLocalesDownloaded"] != "true") {
}, 500);

}
document.querySelectorAll("div.permission-group").forEach((e, index) => {
function interval() {
const granted = Groove.checkPermission(allPermissions[index]) == "true"
if (granted) {
e.querySelector("button").style.display = "none"
e.querySelector("span.permission-icon").innerText = "󰄬"
e.querySelector("span.permission-icon").classList.add("checked")
} else {
e.querySelector("button").style.display = "block"
e.querySelector("span.permission-icon").innerText = ""
e.querySelector("span.permission-icon").classList.remove("checked")
}
}
e.querySelector("button").addEventListener("flowClick", () => {
Groove.requestPermission(allPermissions[index])
})
setInterval(interval, 1000)
interval()
})
GrooveBoard.backendMethods.setUIScale(1, true)
Groove.appReady()
1 change: 1 addition & 0 deletions www/assets/defaultlocales/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"uninstall": "Uninstall",
"cancel": "Cancel",
"apply": "Apply",
"allow": "Allow",
"try_again": "Try again",
"light": "Light",
"dark": "Dark",
Expand Down
17 changes: 17 additions & 0 deletions www/assets/defaultlocales/welcome.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
"title": "Choose your color",
"description": "Pick a color that matches your mood."
},
"permissions":{
"title": "Permissions",
"groups":{
"contacts":{
"title": "Contacts",
"description": "Access to contacts is needed to display your contacts live tile."
},
"photos":{
"title": "Photos",
"description": "Access to photos is needed to display your photos live tile."
},
"notifications":{
"title": "Notifications",
"description": "Access to notifications is needed to display your notifications live tile."
}
}
},
"whatsnew": {
"title": "What's New?"
},
Expand Down
Loading

0 comments on commit ec73d73

Please sign in to comment.