Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability for background tasks and local storage #58

Merged
merged 3 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypertrons-crx",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"description": "Hypertrons",
"license": "Apache",
Expand Down
8 changes: 8 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"icons": {
"128": "128.png"
},
"background": {
"scripts": ["background.bundle.js"],
"persistent": true
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "128.png"
},
"content_scripts": [{
"matches": ["*://github.com/*"],
"js": ["contentScript.bundle.js"],
Expand Down
Empty file removed src/pages/Background/index.js
Empty file.
12 changes: 12 additions & 0 deletions src/pages/Background/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum BackgroundTasks {
update = 'check_for_updates'
}

chrome.alarms.create(BackgroundTasks.update,{periodInMinutes:10});

chrome.alarms.onAlarm.addListener((alarm) => {
const name=alarm.name;
if(name===BackgroundTasks.update){
console.log("check for updates");
}
});
1 change: 0 additions & 1 deletion src/pages/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import './index.css';
import {loadConfigFromGithub} from './common/ConfigService';
import {renderDashboard} from './common/DashboardService';


const config=loadConfigFromGithub();
renderDashboard(config);
17 changes: 0 additions & 17 deletions src/pages/Options/Options.css

This file was deleted.

Empty file removed src/pages/Options/Options.jsx
Empty file.
7 changes: 0 additions & 7 deletions src/pages/Options/index.jsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/pages/Options/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { render } from 'react-dom';

import './index.css';

render(<div />, window.document.querySelector('#app-container'));
Empty file removed src/pages/Popup/Popup.css
Empty file.
1 change: 0 additions & 1 deletion src/pages/Popup/Popup.jsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/pages/Popup/index.jsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/pages/Popup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { render } from 'react-dom';

import './index.css';

render(<div />, window.document.querySelector('#app-container'));
Empty file removed src/utils/services.js
Empty file.
18 changes: 18 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ export function isNull(object: any) {
}
return false;
}

export async function chrome_set(key:string,value:any){
const items: { [key: string] : any; } = {};
items[key]=value;
return new Promise<void>((resolve, reject) => {
chrome.storage.local.set(items, ()=>{
resolve();
})
});
}

export async function chrome_get(key:string){
return new Promise((resolve, reject) => {
chrome.storage.local.get(key, (result)=>{
resolve(result);
})
});
}
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ if (fileSystem.existsSync(secretsPath)) {
var options = {
mode: process.env.NODE_ENV || 'development',
entry: {
options: path.join(__dirname, 'src', 'pages', 'Options', 'index.jsx'),
popup: path.join(__dirname, 'src', 'pages', 'Popup', 'index.jsx'),
background: path.join(__dirname, 'src', 'pages', 'Background', 'index.js'),
options: path.join(__dirname, 'src', 'pages', 'Options', 'index.tsx'),
popup: path.join(__dirname, 'src', 'pages', 'Popup', 'index.tsx'),
background: path.join(__dirname, 'src', 'pages', 'Background', 'index.ts'),
contentScript: path.join(__dirname, 'src', 'pages', 'Content', 'index.ts'),
},
output: {
Expand Down