mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
added saved permissions local
This commit is contained in:
parent
9521978335
commit
9660e04d8d
54
src/App.tsx
54
src/App.tsx
@ -322,6 +322,7 @@ function App() {
|
|||||||
const [isOpenSendQortSuccess, setIsOpenSendQortSuccess] = useState(false)
|
const [isOpenSendQortSuccess, setIsOpenSendQortSuccess] = useState(false)
|
||||||
const [rootHeight, setRootHeight] = useState('100%')
|
const [rootHeight, setRootHeight] = useState('100%')
|
||||||
const [isSettingsOpen, setIsSettingsOpen] = useState(false)
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false)
|
||||||
|
const qortalRequestCheckbox1Ref = useRef(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(!isMobile) return
|
if(!isMobile) return
|
||||||
// Function to set the height of the app to the viewport height
|
// Function to set the height of the app to the viewport height
|
||||||
@ -569,10 +570,21 @@ function App() {
|
|||||||
!isMainWindow
|
!isMainWindow
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
console.log('payloadbefore', message.payload)
|
||||||
|
|
||||||
await showQortalRequest(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) {
|
} catch (error) {
|
||||||
sendResponse(false)
|
console.log('error', error)
|
||||||
|
sendResponse({accepted: false})
|
||||||
} finally {
|
} finally {
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
@ -1811,7 +1823,7 @@ function App() {
|
|||||||
|
|
||||||
{isShowQortalRequest && !isMainWindow && (
|
{isShowQortalRequest && !isMainWindow && (
|
||||||
<>
|
<>
|
||||||
<Spacer height="100px" />
|
<Spacer height="120px" />
|
||||||
|
|
||||||
<TextP
|
<TextP
|
||||||
sx={{
|
sx={{
|
||||||
@ -1846,6 +1858,42 @@ function App() {
|
|||||||
>
|
>
|
||||||
{messageQortalRequest?.text3}
|
{messageQortalRequest?.text3}
|
||||||
</TextP>
|
</TextP>
|
||||||
|
{messageQortalRequest?.checkbox1 &&
|
||||||
|
(
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
gap: "10px",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '90%',
|
||||||
|
marginTop: '20px'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
onChange={(e)=> {
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Typography sx={{
|
||||||
|
fontSize: '14px'
|
||||||
|
}}>{messageQortalRequest?.checkbox1?.label}</Typography>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
|
||||||
<Spacer height="29px" />
|
<Spacer height="29px" />
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -1,5 +1,62 @@
|
|||||||
import { addListItems, decryptData, deleteListItems, encryptData, getListItems, getUserAccount, sendCoin } from "./qortalRequests/get";
|
import { addListItems, decryptData, deleteListItems, encryptData, getListItems, getUserAccount, sendCoin } from "./qortalRequests/get";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Promisify chrome.storage.local.get
|
||||||
|
function getLocalStorage(key) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
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) => {
|
chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
if (request) {
|
if (request) {
|
||||||
switch (request.action) {
|
switch (request.action) {
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
uint8ArrayStartsWith,
|
uint8ArrayStartsWith,
|
||||||
uint8ArrayToBase64,
|
uint8ArrayToBase64,
|
||||||
} from "../qdn/encryption/group-encryption";
|
} from "../qdn/encryption/group-encryption";
|
||||||
|
import { getPermission, setPermission } from "../qortalRequests";
|
||||||
import { fileToBase64 } from "../utils/fileReading";
|
import { fileToBase64 } from "../utils/fileReading";
|
||||||
|
|
||||||
async function getUserPermission(payload: any) {
|
async function getUserPermission(payload: any) {
|
||||||
@ -219,27 +220,34 @@ export const getListItems = async (data) => {
|
|||||||
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
let skip = false;
|
const value = await getPermission('qAPPAutoLists') || 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
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
|
|
||||||
|
let skip = false;
|
||||||
|
if (value) {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
let resPermission;
|
||||||
|
let acceptedVar
|
||||||
|
let checkbox1Var
|
||||||
|
if (!skip) {
|
||||||
resPermission = await getUserPermission({
|
resPermission = await getUserPermission({
|
||||||
text1: "Do you give this application permission to",
|
text1: "Do you give this application permission to",
|
||||||
text2: "Access the list",
|
text2: "Access the list",
|
||||||
text3: data.list_name,
|
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}`);
|
const url = await createEndpoint(`/lists/${data.list_name}`);
|
||||||
console.log("url", url);
|
console.log("url", url);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
@ -247,6 +255,7 @@ export const getListItems = async (data) => {
|
|||||||
if (!response.ok) throw new Error("Failed to fetch");
|
if (!response.ok) throw new Error("Failed to fetch");
|
||||||
|
|
||||||
const list = await response.json();
|
const list = await response.json();
|
||||||
|
console.log('list', list)
|
||||||
return list;
|
return list;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("User declined to share list");
|
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}:`,
|
text2: `Add the following to the list ${list_name}:`,
|
||||||
text3: items.join(', ')
|
text3: items.join(', ')
|
||||||
});
|
});
|
||||||
|
const {accepted} = resPermission
|
||||||
|
|
||||||
if (resPermission) {
|
if (accepted) {
|
||||||
const url = await createEndpoint(`/lists/${list_name}`);
|
const url = await createEndpoint(`/lists/${list_name}`);
|
||||||
console.log("url", url);
|
console.log("url", url);
|
||||||
const body = {
|
const body = {
|
||||||
@ -327,8 +337,9 @@ export const deleteListItems = async (data) => {
|
|||||||
text2: `Remove the following from the list ${list_name}:`,
|
text2: `Remove the following from the list ${list_name}:`,
|
||||||
text3: item
|
text3: item
|
||||||
});
|
});
|
||||||
|
const {accepted} = resPermission
|
||||||
if (resPermission) {
|
|
||||||
|
if (accepted) {
|
||||||
const url = await createEndpoint(`/lists/${list_name}`);
|
const url = await createEndpoint(`/lists/${list_name}`);
|
||||||
console.log("url", url);
|
console.log("url", url);
|
||||||
const body = {
|
const body = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user