Skip to content

Commit 1c5987a

Browse files
authored
Feature/without host permission (#48)
* fixed bug with scheduler and stale runOn value * fixed bug with slidePanel error * fixed bug with deleting a scheduled automation * optional host permissions ui improvements * working on removing permissions
1 parent 85efe85 commit 1c5987a

File tree

12 files changed

+108
-30
lines changed

12 files changed

+108
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "your-rapport",
3-
"version": "0.25.0",
3+
"version": "0.26.0",
44
"description": "A chrome extension for saving screenshots and making them searchable.",
55
"license": "Commercial",
66
"scripts": {

src/backgrounds/automation-runner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ async function queueScheduledAutomations(){
6262
for (const scheduledAutomation of scheduledAutomations) {
6363
const interval = CronExpressionParser.parse(scheduledAutomation.crontab);
6464
// run automation
65-
if(!scheduledAutomation?.nextRunOn || scheduledAutomation.nextRunOn <= utcNow) {
65+
const nextRunOn = getUtc(interval.next().toDate());
66+
// getNextRunTime address a bug when the updated crontab was changed, but the nextRunOn isn't for a while.
67+
if(!scheduledAutomation?.nextRunOn || scheduledAutomation.nextRunOn <= utcNow || nextRunOn <= utcNow) {
6668
// add bulk automation url
6769
const automation = BulkAutomationUrl.createBulkAutomationJob(scheduledAutomation.url, {
6870
keepTabOpen: scheduledAutomation.keepTabOpen ?? false,
@@ -76,8 +78,9 @@ async function queueScheduledAutomations(){
7678
automations.push(automation)
7779
scheduledAutomation.prevRanOn = utcNow;
7880
if(interval.hasNext()){
79-
scheduledAutomation.nextRunOn = getUtc(interval.next().toDate());
81+
scheduledAutomation.nextRunOn = nextRunOn;
8082
}
83+
8184
else{
8285
// deactivate the scheduled automation if no future time exists
8386
scheduledAutomation.active = false;

src/components/TopAppBar.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ import { getUser } from '../models/schemas/User';
1515
import SyncIcon from '@mui/icons-material/Sync';
1616
import SyncDisabledIcon from '@mui/icons-material/SyncDisabled';
1717
import { Configuration } from '../models/schemas/Configuration';
18+
import SecurityIcon from '@mui/icons-material/Security';
19+
import { allSitesAccessApproved, removeAllSitesAccess, requestAllSitesAccess } from '../services/manifest_permissions';
1820

1921
export default function TopAppBar() {
2022
const [anchorEl, setAnchorEl] = React.useState(null);
2123
const open = Boolean(anchorEl);
2224
const [auth, setAuth] = React.useState(true);
2325
const [configuration, setConfiguration] = useState({})
26+
const [hasPermission, setHasPermission] = useState(true);
2427

2528
useEffect(() => {
2629
async function fetchData(){
2730
const user = await getUser();
2831
setAuth(user && user.verify() ? true : false);
2932
setConfiguration(await Configuration.getConfiguration());
33+
setHasPermission(await allSitesAccessApproved());
3034
}
3135
fetchData();
3236
}, []);
@@ -107,6 +111,28 @@ export default function TopAppBar() {
107111

108112
</div>
109113

114+
<Tooltip
115+
title={ hasPermission ? 'Advanced Scheduled Automations Enabled' : 'Enable the extension access to websites. Turning this feature on enables automations and streamlines data extraction processes.'}>
116+
<IconButton
117+
size="large"
118+
aria-label=""
119+
color="inherit"
120+
onClick={async() => {
121+
if(hasPermission) {
122+
alert('TODO: Find docs to remove permissions.');
123+
setHasPermission(false);
124+
}
125+
else {
126+
const isPermitted = await requestAllSitesAccess();
127+
setHasPermission(isPermitted);
128+
}
129+
}}
130+
>
131+
<SecurityIcon color={ hasPermission ? 'success' : 'error'}/>
132+
</IconButton>
133+
</Tooltip>
134+
135+
110136
{auth && configuration.syncBackgroundEnabled ? (
111137
<Tooltip title={'Local data sync is active'}>
112138
<IconButton
@@ -115,7 +141,7 @@ export default function TopAppBar() {
115141
color="inherit"
116142
onClick={() => createTab('https://github.com/yooper/your-rapport/wiki/Pro-features')}
117143
>
118-
<SyncIcon />
144+
<SyncIcon color={'success'} />
119145
</IconButton>
120146
</Tooltip>
121147
) : (
@@ -127,7 +153,7 @@ export default function TopAppBar() {
127153
color="inherit"
128154
onClick={() => createTab(`https://github.com/yooper/your-rapport/wiki/Pro-features`)}
129155
>
130-
<SyncDisabledIcon />
156+
<SyncDisabledIcon color={'info'} />
131157
</IconButton>
132158
</Tooltip>
133159
)
@@ -140,7 +166,7 @@ export default function TopAppBar() {
140166
color="inherit"
141167
onClick={() => createTab('https://github.com/yooper/your-rapport/wiki/Pro-features')}
142168
>
143-
<PersonIcon />
169+
<PersonIcon color={'success'}/>
144170
</IconButton>
145171
</Tooltip>
146172
) : (
@@ -151,7 +177,7 @@ export default function TopAppBar() {
151177
color="inherit"
152178
onClick={() => createTab(`chrome-extension://${chrome.runtime.id}/login.html`)}
153179
>
154-
<PersonOffIcon />
180+
<PersonOffIcon color={'info'} />
155181
</IconButton>
156182
</Tooltip>
157183
)}

src/components/tables/ScheduledAutomationDataTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,13 @@ export default function ScheduledAutomationDataTable(): JSX.Element {
336336
rowsPerPage: 50,
337337
rowsPerPageOptions: [20, 50],
338338
searchAlwaysOpen: false,
339-
onRowsDelete: async (deleteInfo: any) => {
339+
onRowsDelete: async (records: any, data: any) => {
340340
setIsLoading(true);
341341
showLoader();
342-
342+
for (const [idx, value] of Object.entries(records.lookup)) {
343+
await db.scheduledAutomation.delete(rows[idx].uuid);
344+
}
345+
setRows(await db.scheduledAutomation.toArray());
343346
setIsLoading(false);
344347
hideLoader();
345348
},

src/components/tables/SearchDataTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ export default function SearchDataTable(props) {
569569
customSearchRender: rapportDebounceSearchRender(800),
570570
textLabels: {
571571
toolbar: {
572-
downloadCsv: 'Export as JSON file',
572+
downloadCsv: 'Export all rapport records as a JSON file',
573573
},
574574
},
575575
onDownload: (buildHead, buildBody, columns, data) => {

src/datasources/browser_capture.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { FastDrawError } from '../errors/FastDrawError';
1212
import { getActiveTab, sleep } from '../utilities/loaders';
1313
import { NoChangeDetectedError } from '../errors/NoChangeDetectedError';
1414
import { DuplicateDetectedError } from '../errors/DuplicateDetectedError';
15+
import { initExtensionPage } from '../services/init_services';
1516

1617

1718
let _lastRapport: Rapport|null = null;
@@ -30,7 +31,10 @@ export async function capture(
3031

3132
ExtensionPin.setDefaultNotSaved(tab);
3233
// always force close the sidePanel upon save
33-
chrome.sidePanel.close({tabId: tab.id});
34+
35+
36+
// will close the sidePanel if its open
37+
initExtensionPage();
3438

3539
do {
3640
try {

src/manifest.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"default_title": "Your Rapport is a screenshot tool with auto scroll capabilities. Right click, select Collect or Alt+S to save. Alt+A for auto scrolling captures. Alt+X open the dashboard. Alt+Q for doing a quick scan.",
1010
"default_popup": "popup.html"
1111
},
12-
"version": "0.25.0",
12+
"version": "0.26.0",
1313
"icons": {
1414
"128": "icon-128.png",
1515
"48": "icon-48.png",
@@ -29,7 +29,7 @@
2929
"run_at": "document_idle"
3030
}
3131
],
32-
"host_permissions": ["<all_urls>"],
32+
"optional_host_permissions": ["<all_urls>"],
3333
"permissions": [
3434
"unlimitedStorage",
3535
"storage",
@@ -41,7 +41,8 @@
4141
"alarms",
4242
"commands",
4343
"downloads",
44-
"sidePanel"
44+
"sidePanel",
45+
"scripting"
4546
],
4647
"side_panel": {
4748
"default_path": "sidePanel.html"

src/pages/Background/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import {
1717
} from '../../services/constants';
1818

1919
import { debug } from '../../services/logger_services';
20-
21-
2220
import { JobQueue } from '../../models/schemas/JobQueue';
23-
2421
import { initializeAutomationRunner } from '../../backgrounds/automation-runner';
2522
import { fetchPackages } from '../../models/schemas/Package';
2623
import { db } from '../../models/db/dexieDb';
@@ -59,6 +56,18 @@ chrome.commands.onCommand.addListener(async(command) => {
5956
const activeTab = await getActiveTab()
6057
const response = await chrome.tabs.sendMessage(activeTab.id, { cmd: PAGE_INFO, requestId: crypto.randomUUID() });
6158
const { pageInfo } = response
59+
function getTitle() { return document.title; }
60+
61+
chrome.scripting
62+
.executeScript({
63+
target : {tabId : activeTab.id, allFrames : true},
64+
func : getTitle,
65+
})
66+
.then(injectionResults => {
67+
for (const {frameId, result} of injectionResults) {
68+
console.log(`Frame ${frameId} result:`, result);
69+
}
70+
});
6271

6372
switch (command) {
6473
case 'deepSave':
@@ -238,7 +247,14 @@ chrome.runtime.onMessageExternal.addListener((message, sender, sendResponse) =>
238247
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
239248
// when the tab changes, check if it changes to an extension page and close the side panel
240249
if(tab.url.startsWith(`chrome://extensions/?id=${chrome.runtime.id}`)){
241-
chrome.sidePanel.close({tabId})
250+
let gettingContextInfo = chrome.runtime.getContexts({ contextTypes: ['SIDE_PANEL']});
251+
gettingContextInfo.then(contexts => {
252+
contexts.forEach(c => {
253+
if(c.tagId == tabId){
254+
chrome.sidePanel.close({tabId})
255+
}
256+
})
257+
})
242258
}
243259

244260
if (changeInfo.status === 'complete') {

src/pages/Content/modules/autoScroller.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ import {
77
BULK_AUTOMATION,
88
CAPTURE_VISIBLE_TAB,
99
NO_VISIBLE_TEXT,
10-
UUID,
1110
} from "../../../services/constants";
1211
import { getPageInfo } from "../index";
1312
import { debug } from "../../../services/logger_services";
14-
import { updateRecord } from "../../../models/db/local";
15-
import { db } from '../../../models/db/dexieDb';
1613

1714
/** Local state machine */
1815
const STATE_STOPPED = "stopped" as const;

src/services/init_services.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
/**
2+
* Disabled because it is buggy
3+
*/
4+
import { debug } from './logger_services';
15

26
export const initExtensionPage = (): void => {
37
try{
48
chrome.tabs.query({ active: true, currentWindow: true }).then(tabs => {
5-
chrome.sidePanel.close({tabId: tabs[0].id})
9+
let gettingContextInfo = chrome.runtime.getContexts({ contextTypes: ['SIDE_PANEL']});
10+
gettingContextInfo.then(contexts => {
11+
contexts.forEach(c => {
12+
if(c.tagId == tabs[0].id){
13+
chrome.sidePanel.close({tabId: tabs[0].id})
14+
}
15+
})
16+
17+
});
618
})
719
}
820
catch(e){
9-
// ignore error
21+
debug('initExtensionPage:error', e)
1022
}
11-
};
23+
};
24+
25+

0 commit comments

Comments
 (0)