-
Notifications
You must be signed in to change notification settings - Fork 324
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(mv3): Config Migration #1228
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4cbc14f
fix(mv3): Enabling debugs based on default values.
whizzzkid 333293d
feat: init debugger
whizzzkid 9405b94
feat: localStorage Migration Task
whizzzkid 9c32a6d
fix: :rotating_light: Linter Errors
whizzzkid 1119b59
Merge branch 'rc/3.0-mv3' into feat/config-migration
whizzzkid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
'use strict' | ||
/* eslint-env browser, webextensions */ | ||
|
||
import browser from 'webextension-polyfill' | ||
import createIpfsCompanion from '../lib/ipfs-companion.js' | ||
import { onInstalled } from '../lib/on-installed.js' | ||
import { getUninstallURL } from '../lib/on-uninstalled.js' | ||
import { debuggerInit } from '../lib/debugger/debugger.js' | ||
|
||
// register lifecycle hooks early, otherwise we miss first install event | ||
browser.runtime.onInstalled.addListener(onInstalled) | ||
browser.runtime.setUninstallURL(getUninstallURL(browser)) | ||
|
||
const init = async () => { | ||
await createIpfsCompanion() | ||
await debuggerInit() | ||
} | ||
|
||
init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import browser from 'webextension-polyfill' | ||
import debug from 'debug' | ||
import { optionDefaults } from '../options.js' | ||
|
||
export async function debuggerInit (): Promise<void> { | ||
await enableDebugger() | ||
await setupListeners() | ||
} | ||
|
||
function setupListeners (): void { | ||
browser.storage.onChanged.addListener((changes, areaName): void => { | ||
if (areaName === 'local' && ('logNamespaces' in changes)) { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
enableDebugger() | ||
} | ||
}) | ||
} | ||
|
||
async function enableDebugger (): Promise<void> { | ||
const debugNs = (await browser.storage.local.get({ logNamespaces: optionDefaults.logNamespaces })).logNamespaces | ||
debug.enable(debugNs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
import browser from 'webextension-polyfill' | ||
import debug from 'debug' | ||
import { welcomePage } from './constants.js' | ||
import { welcomePage, mv3updatePage } from './constants.js' | ||
import { brave, braveNodeType } from './ipfs-client/brave.js' | ||
|
||
const { version } = browser.runtime.getManifest() | ||
|
@@ -19,7 +19,7 @@ export async function onInstalled (details) { | |
} | ||
|
||
export async function runPendingOnInstallTasks () { | ||
const { onInstallTasks, displayReleaseNotes } = await browser.storage.local.get(['onInstallTasks', 'displayReleaseNotes']) | ||
const { onInstallTasks } = await browser.storage.local.get(['onInstallTasks', 'displayReleaseNotes']) | ||
await browser.storage.local.remove('onInstallTasks') | ||
switch (onInstallTasks) { | ||
case 'onFirstInstall': | ||
|
@@ -28,9 +28,23 @@ export async function runPendingOnInstallTasks () { | |
url: welcomePage | ||
}) | ||
case 'onVersionUpdate': | ||
if (!displayReleaseNotes) return | ||
// temporary disabled due to upgrade to MV3. | ||
// TODO(whizzzkid): revert this logic to it's previous state once v3.0.0 is released. | ||
// if (!displayReleaseNotes) return | ||
await browser.storage.local.set({ dismissedUpdate: version }) | ||
return browser.tabs.create({ url: updatePage + version }) | ||
// return browser.tabs.create({ url: updatePage + version }) | ||
browser.runtime.onMessage.addListener((message) => { | ||
if (message.type === 'ipfs-companion-migrate') { | ||
browser.runtime.onMessage.removeListener(this) | ||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
|
||
browser.storage.local.set({ | ||
logNamespaces: message.payload.localStorage.logNamespaces, | ||
countly: message.payload.localStorage.countly | ||
}) | ||
browser.tabs.remove(message.sender.tab.id) | ||
} | ||
}) | ||
return browser.tabs.create({ url: mv3updatePage }) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<head> | ||
<script src="/dist/bundles/mv3update.bundle.js"></script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import browser from 'webextension-polyfill' | ||
import debug from 'debug' | ||
|
||
const log = debug('ipfs-companion:mv3update') | ||
log.error = debug('ipfs-companion:mv3update:error') | ||
|
||
interface IResult { | ||
logNamespaces?: string | ||
countly?: { | ||
container: string | ||
[key: string]: string | ||
} | ||
} | ||
|
||
function parseLocalStorage (): IResult { | ||
const data = localStorage | ||
const result: IResult = {} | ||
Object.entries(data).forEach(([key, value]) => { | ||
if (key === 'debug') { | ||
result.logNamespaces = value | ||
return | ||
} | ||
if (key.includes('cly')) { | ||
const [container, clyKey] = key.split('/') | ||
if (!('countly' in result)) { | ||
result.countly = { | ||
container | ||
} | ||
} | ||
result.countly[clyKey] = value | ||
} | ||
}) | ||
return result | ||
} | ||
|
||
browser.runtime.sendMessage({ | ||
type: 'ipfs-companion-migrate', | ||
payload: { | ||
localStorage: parseLocalStorage() | ||
} | ||
}).catch(e => log.error(e)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to double check the version to ensure mv3 update is what's needed?