diff --git a/src/App.tsx b/src/App.tsx
index a8a1a51..ebc9166 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -322,6 +322,7 @@ function App() {
const [isOpenSendQortSuccess, setIsOpenSendQortSuccess] = useState(false)
const [rootHeight, setRootHeight] = useState('100%')
const [isSettingsOpen, setIsSettingsOpen] = useState(false)
+ const qortalRequestCheckbox1Ref = useRef(null);
useEffect(() => {
if(!isMobile) return
// Function to set the height of the app to the viewport height
@@ -569,10 +570,21 @@ function App() {
!isMainWindow
) {
try {
+ console.log('payloadbefore', message.payload)
+
await showQortalRequest(message?.payload)
- sendResponse(true)
+ console.log('payload', message.payload)
+ if(message?.payload?.checkbox1){
+ console.log('qortalRequestCheckbox1Ref.current', qortalRequestCheckbox1Ref.current)
+ sendResponse({accepted: true,
+ checkbox1: qortalRequestCheckbox1Ref.current
+ })
+ return
+ }
+ sendResponse({accepted: true})
} catch (error) {
- sendResponse(false)
+ console.log('error', error)
+ sendResponse({accepted: false})
} finally {
window.close();
}
@@ -1811,7 +1823,7 @@ function App() {
{isShowQortalRequest && !isMainWindow && (
<>
-
+
{messageQortalRequest?.text3}
+ {messageQortalRequest?.checkbox1 &&
+ (
+
+ {
+ qortalRequestCheckbox1Ref.current = e.target.checked
+ }}
+ edge="start"
+ tabIndex={-1}
+ disableRipple
+ defaultChecked={messageQortalRequest?.checkbox1?.value}
+ sx={{
+ "&.Mui-checked": {
+ color: "white", // Customize the color when checked
+ },
+ "& .MuiSvgIcon-root": {
+ color: "white",
+ },
+ }}
+ />
+
+ {messageQortalRequest?.checkbox1?.label}
+
+ )}
+
{
+ chrome.storage.local.get([key], function (result) {
+ if (chrome.runtime.lastError) {
+ return reject(chrome.runtime.lastError);
+ }
+ resolve(result[key]);
+ });
+ });
+ }
+
+ // Promisify chrome.storage.local.set
+ function setLocalStorage(data) {
+ return new Promise((resolve, reject) => {
+ chrome.storage.local.set(data, function () {
+ if (chrome.runtime.lastError) {
+ return reject(chrome.runtime.lastError);
+ }
+ resolve();
+ });
+ });
+ }
+
+
+ export async function setPermission(key, value) {
+ try {
+ // Get the existing qortalRequestPermissions object
+ const qortalRequestPermissions = (await getLocalStorage('qortalRequestPermissions')) || {};
+
+ // Update the permission
+ qortalRequestPermissions[key] = value;
+
+ // Save the updated object back to storage
+ await setLocalStorage({ qortalRequestPermissions });
+
+ console.log('Permission set for', key);
+ } catch (error) {
+ console.error('Error setting permission:', error);
+ }
+ }
+
+ export async function getPermission(key) {
+ try {
+ // Get the qortalRequestPermissions object from storage
+ const qortalRequestPermissions = (await getLocalStorage('qortalRequestPermissions')) || {};
+
+ // Return the value for the given key, or null if it doesn't exist
+ return qortalRequestPermissions[key] || null;
+ } catch (error) {
+ console.error('Error getting permission:', error);
+ return null;
+ }
+ }
+
chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
if (request) {
switch (request.action) {
diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts
index 62efe2d..70e18e1 100644
--- a/src/qortalRequests/get.ts
+++ b/src/qortalRequests/get.ts
@@ -13,6 +13,7 @@ import {
uint8ArrayStartsWith,
uint8ArrayToBase64,
} from "../qdn/encryption/group-encryption";
+import { getPermission, setPermission } from "../qortalRequests";
import { fileToBase64 } from "../utils/fileReading";
async function getUserPermission(payload: any) {
@@ -219,27 +220,34 @@ export const getListItems = async (data) => {
const errorMsg = `Missing fields: ${missingFieldsString}`;
throw new Error(errorMsg);
}
- let skip = false;
- // if (window.parent.reduxStore.getState().app.qAPPAutoLists) {
- // skip = true
- // }
- let resPermission;
- if (!skip) {
- // res1 = await showModalAndWait(
- // actions.GET_LIST_ITEMS,
- // {
- // list_name: data.list_name
- // }
- // )
+ const value = await getPermission('qAPPAutoLists') || false;
+ let skip = false;
+ if (value) {
+ skip = true
+ }
+ let resPermission;
+ let acceptedVar
+ let checkbox1Var
+ if (!skip) {
resPermission = await getUserPermission({
text1: "Do you give this application permission to",
text2: "Access the list",
text3: data.list_name,
+ checkbox1: {
+ value: value,
+ label: 'Always allow lists to be retrieved automatically'
+ }
});
+ const {accepted, checkbox1} = resPermission
+ acceptedVar = accepted
+ checkbox1Var = checkbox1
+ setPermission('qAPPAutoLists', checkbox1)
+
}
- console.log("resPermission", resPermission);
- if (resPermission || skip) {
+
+
+ if (acceptedVar || skip) {
const url = await createEndpoint(`/lists/${data.list_name}`);
console.log("url", url);
const response = await fetch(url);
@@ -247,6 +255,7 @@ export const getListItems = async (data) => {
if (!response.ok) throw new Error("Failed to fetch");
const list = await response.json();
+ console.log('list', list)
return list;
} else {
throw new Error("User declined to share list");
@@ -275,8 +284,9 @@ export const addListItems = async (data) => {
text2: `Add the following to the list ${list_name}:`,
text3: items.join(', ')
});
+ const {accepted} = resPermission
- if (resPermission) {
+ if (accepted) {
const url = await createEndpoint(`/lists/${list_name}`);
console.log("url", url);
const body = {
@@ -327,8 +337,9 @@ export const deleteListItems = async (data) => {
text2: `Remove the following from the list ${list_name}:`,
text3: item
});
-
- if (resPermission) {
+ const {accepted} = resPermission
+
+ if (accepted) {
const url = await createEndpoint(`/lists/${list_name}`);
console.log("url", url);
const body = {