Skip to content

Commit

Permalink
v1.27.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Jan 27, 2023
2 parents 09ac7ce + 8dc4d3d commit 8536a94
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.27.1",
"version": "1.27.2",
"description": "An extension for automating your browser by connecting blocks",
"repository": {
"type": "git",
Expand Down
8 changes: 5 additions & 3 deletions src/components/content/shared/SharedElementSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ function onKeydown(event) {
'selected'
);
}
function onClick(event) {
function onMousedown(event) {
event.preventDefault();
event.stopPropagation();
retrieveElementsRect(event, 'selected');
}
function onMessage({ data }) {
Expand All @@ -309,17 +311,17 @@ function onMessage({ data }) {
}
function attachListeners() {
window.addEventListener('scroll', onScroll);
document.addEventListener('click', onClick);
window.addEventListener('message', onMessage);
document.addEventListener('keydown', onKeydown);
window.addEventListener('mousemove', onMousemove);
document.addEventListener('mousedown', onMousedown);
}
function detachListeners() {
window.removeEventListener('scroll', onScroll);
document.removeEventListener('click', onClick);
window.removeEventListener('message', onMessage);
document.removeEventListener('keydown', onKeydown);
window.removeEventListener('mousemove', onMousemove);
document.removeEventListener('mousedown', onMousedown);
}
watch(
Expand Down
2 changes: 1 addition & 1 deletion src/content/blocksHandler/handlerEventClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function eventClick(block) {
return;
}

simulateClickElement(element, () => element.click());
simulateClickElement(element);
},
onError(error) {
reject(error);
Expand Down
1 change: 1 addition & 0 deletions src/content/services/webService.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ window.addEventListener('user-logout', () => {
});

window.addEventListener('app-mounted', async () => {
console.log('haha');
try {
const STORAGE_KEY = 'supabase.auth.token';
const session = parseJSON(localStorage.getItem(STORAGE_KEY), null);
Expand Down
2 changes: 2 additions & 0 deletions src/content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export function simulateClickElement(element) {
} else {
element.dispatchEvent(new PointerEvent('click', { bubbles: true }));
}

element.focus?.();
}

export function generateLoopSelectors(
Expand Down
31 changes: 27 additions & 4 deletions src/stores/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
import defu from 'defu';
import browser from 'webextension-polyfill';
import deepmerge from 'lodash.merge';
import { fetchGapi } from '@/utils/api';
import { fetchGapi, fetchApi } from '@/utils/api';

export const useStore = defineStore('main', {
storageMap: {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const useStore = defineStore('main', {
this.settings = deepmerge(this.settings, settings);
await this.saveToStorage('settings');
},
async checkGDriveIntegration(force = false) {
async checkGDriveIntegration(force = false, retryCount = 0) {
try {
if (this.integrationsRetrieved.googleDrive && !force) return;

Expand All @@ -58,8 +58,31 @@ export const useStore = defineStore('main', {
);
if (!result) return;

this.integrations.googleDrive =
result.scope.includes('auth/drive.file');
const isIntegrated = result.scope.includes('auth/drive.file');
const { sessionToken } = await browser.storage.local.get(
'sessionToken'
);

if (!isIntegrated && sessionToken?.refresh && retryCount < 3) {
const response = await fetchApi(
`/me/refresh-session?token=${sessionToken.refresh}`,
{ auth: true }
);
const refreshResult = await response.json();
if (!response.ok) throw new Error(refreshResult.message);

await browser.storage.local.set({
sessionToken: {
...sessionToken,
access: refreshResult.token,
},
});
await this.checkGDriveIntegration(force, retryCount + 1);

return;
}

this.integrations.googleDrive = isIntegrated;
} catch (error) {
console.error(error);
}
Expand Down
10 changes: 6 additions & 4 deletions src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import secrets from 'secrets';
import browser from 'webextension-polyfill';
import { parseJSON, isObject } from './helper';

export async function fetchApi(path, options) {
export async function fetchApi(path, options = {}) {
const urlPath = path.startsWith('/') ? path : `/${path}`;
const headers = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -161,7 +161,8 @@ export function validateOauthToken() {
);
if (response.status === 400 && sessionToken.refresh && retryCount <= 3) {
const refreshResponse = await fetchApi(
`/me/refresh-session?token=${sessionToken.refresh}`
`/me/refresh-session?token=${sessionToken.refresh}`,
{ auth: true }
);
const refreshResult = await refreshResponse.json();

Expand Down Expand Up @@ -211,11 +212,12 @@ export async function fetchGapi(url, resource = {}, options = {}) {
response.status === 403 &&
result?.error?.message.includes('insufficient authentication scopes');
if (
(response.status === 401 || insufficientScope) &&
(!sessionToken.access || response.status === 401 || insufficientScope) &&
sessionToken.refresh
) {
const refreshResponse = await fetchApi(
`/me/refresh-session?token=${sessionToken.refresh}`
`/me/refresh-session?token=${sessionToken.refresh}`,
{ auth: true }
);
const refreshResult = await refreshResponse.json();

Expand Down

0 comments on commit 8536a94

Please sign in to comment.