Skip to content

Commit

Permalink
fix init storage - support chrome modern
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Oct 14, 2021
1 parent 54302e0 commit d0ccf1b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
3 changes: 2 additions & 1 deletion bin/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const version = require('../package.json').version;

const config = require(process.cwd() + '/.localhostify.js');
const externalRedirects = Object.values(config).reduce((all, v) => [...all, ...v.externalRedirects], []);
Expand All @@ -23,4 +24,4 @@ fs.copyFileSync(__dirname + '/../chrome-ext/scripts/fetch.js', process.cwd() + '
fs.copyFileSync(__dirname + '/../chrome-ext/assets/green.png', process.cwd() + '/localhostify-ext/assets/green.png');
fs.copyFileSync(__dirname + '/../chrome-ext/assets/red.png', process.cwd() + '/localhostify-ext/assets/red.png');

console.log("Localhostify: Chrome Ext created in localhostify-ext folder.");
console.log(`Localhostify ${version}: Chrome Ext created in localhostify-ext folder.`);
2 changes: 1 addition & 1 deletion chrome-ext/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Localhostify",
"version": "0.1.0",
"version": "0.1.1",
"manifest_version": 2,
"description": "Localhostify: External redirects interceptor",
"author": "Salvatore Ravidà",
Expand Down
13 changes: 4 additions & 9 deletions chrome-ext/scripts/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ const { externalRedirects } = window.__LOCALHOSTIFY__;

let localhostifyEnabled = true;

chrome.runtime.onInstalled.addListener(function () {
chrome.storage.sync.set({ active: localhostifyEnabled }, function () {
console.log('Active :', localhostifyEnabled);
});
});

function onIconClick(toggle) {
chrome.storage.sync.get(['active'], function (data) {
const active = toggle ? !data.active : data.active;
console.log('StorageGet Active :', JSON.stringify(data));
const active = toggle ? !data.active : data.active === undefined ? localhostifyEnabled : data.active;
localhostifyEnabled = active;
chrome.browserAction.setIcon({ path: active ? 'assets/green.png' : 'assets/red.png' });
chrome.storage.sync.set({ active }, function () {
console.log('Active 1:', active);
console.log('StorageSet Active set:', active);
});
});
}
Expand Down Expand Up @@ -52,5 +47,5 @@ chrome.webRequest.onHeadersReceived.addListener(
return { responseHeaders: headers };
},
{ urls: ['<all_urls>'] },
['responseHeaders', 'blocking'],
['blocking', 'responseHeaders', chrome.webRequest.OnHeadersReceivedOptions.EXTRA_HEADERS].filter(Boolean),
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "localhostify",
"version": "0.1.0",
"version": "0.1.1",
"description": "Easy HTTP reverse proxy - localhost:3001 -> prod.domain.com",
"source": "src/index.js",
"main": "./dist/index.js",
Expand Down

0 comments on commit d0ccf1b

Please sign in to comment.