Skip to content

Commit

Permalink
feat: use new cookie api
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelxk committed Oct 23, 2021
1 parent e3c2728 commit 254be8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"module": "readonly",
"process": "readonly",
"require": "readonly",
"__dirname": "readonly"
"__dirname": "readonly",
"cookieStore": "readonly"
},
"env": {
"browser": true,
Expand Down
48 changes: 23 additions & 25 deletions src/provider/lowebutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,65 @@ export function isElectron() {
}

export function cookieGet(cookieRequest, callback) {
if (!isElectron()) {
if (cookieStore in window) {
cookieStore.get(cookieRequest).then((cookie) => {
callback(cookie);
});
} else {
return chrome.cookies.get(cookieRequest, (cookie) => {
callback(cookie);
});
}
window.api.getCookie(cookieRequest).then((cookieArray) => {
let cookie = null;
if (cookieArray.length > 0) {
[cookie] = cookieArray;
}
callback(cookie);
});
}
export async function cookieGetPromise(cookieRequest) {
return new Promise((res, rej) => {
if (!isElectron()) {
chrome.cookies.get(cookieRequest, (cookie) => {
if (cookieStore in window) {
cookieStore.get(cookieRequest).then((cookie) => {
res(cookie);
});
} else {
window.api.getCookie(cookieRequest).then((cookieArray) => {
let cookie = null;
if (cookieArray.length > 0) {
[cookie] = cookieArray;
}
chrome.cookies.get(cookieRequest, (cookie) => {
res(cookie);
});
}
});
}

export function cookieSet(cookie, callback) {
if (!isElectron()) {
if (cookieStore in window) {
cookieStore.set(cookie).then(() => {
callback();
});
} else {
return chrome.cookies.set(cookie, (arg1, arg2) => {
callback(arg1, arg2);
});
}
window.api.setCookie(cookie);
callback(null);
}
export function cookieSetPromise(cookie) {
return new Promise((res, rej) => {
if (!isElectron()) {
if (cookieStore in window) {
cookieStore.set(cookie).then(() => {
res();
});
} else {
return chrome.cookies.set(cookie, (arg1, arg2) => {
res(arg1, arg2);
});
}
window.api.setCookie(cookie).then(() => {
res(null);
});
});
}

export function cookieRemove(cookie, callback) {
if (!isElectron()) {
if (cookieStore in window) {
cookieStore.delete(cookie).then(() => {
callback();
});
} else {
return chrome.cookies.remove(cookie, (arg1, arg2) => {
callback(arg1, arg2);
});
}
window.api.removeCookie(cookie.url, cookie.name);
callback(null);
}

// function setPrototypeOfLocalStorage() {
Expand Down

0 comments on commit 254be8a

Please sign in to comment.