-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First work of #27. In this PR I created the infrastructure for controlling the state of the extension from its popup. See the review comments for specific implementation details. ![tinywow_Recording 2023-04-03 200726_18612307](https://user-images.githubusercontent.com/17686879/229579780-e3326381-9db4-440c-bbed-9a5036070a1b.gif) --------- Co-authored-by: Jossef Harush Kadouri <[email protected]>
- Loading branch information
Showing
19 changed files
with
224 additions
and
29 deletions.
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
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
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 @@ | ||
export default globalThis.browser || globalThis.chrome; |
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
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 |
---|---|---|
@@ -1,23 +1,42 @@ | ||
import { reactive } from 'vue'; | ||
import { computed, reactive } from 'vue'; | ||
|
||
const settings = reactive({}); | ||
const store = reactive({ packages: {} }); | ||
window.__overlay_global_store = store; | ||
|
||
export const updatePackageInfo = ({ type, name }, part, info) => { | ||
if (!store.packages[type]) { | ||
store.packages[type] = {}; | ||
} | ||
if (!store.packages[type][name]) { | ||
store.packages[type][name] = { | ||
const packageStoreID = ({ type, name }) => `${type}:${name}`; | ||
|
||
export const updatePackageInfo = (packageID, part, data) => { | ||
const packagePointer = packageStoreID(packageID); | ||
|
||
if (!store.packages[packagePointer]) { | ||
store.packages[packagePointer] = { | ||
sources: {}, | ||
}; | ||
} | ||
|
||
if (part === 'info') { | ||
store.packages[type][name] = { ...store.packages[type][name], ...info }; | ||
store.packages[packagePointer] = { ...store.packages[packagePointer], ...data }; | ||
return; | ||
} | ||
store.packages[type][name].sources[part] = info; | ||
store.packages[packagePointer].sources[part] = data; | ||
}; | ||
|
||
export default store; | ||
export const updateSettings = (newSettings) => { | ||
Object.assign(settings, newSettings); | ||
}; | ||
|
||
export const usePackageInfo = (type, name) => | ||
computed(() => { | ||
const packageInfo = store.packages[packageStoreID({ type, name })]; | ||
if (!packageInfo) return null; | ||
|
||
const filteredSources = Object.entries(packageInfo.sources).reduce((acc, [key, value]) => { | ||
if (settings[key] !== false && value) { | ||
acc[key] = value; | ||
} | ||
return acc; | ||
}, {}); | ||
|
||
return { ...packageInfo, sources: filteredSources }; | ||
}); |
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
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
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,33 @@ | ||
<template> | ||
<main> | ||
<div v-for="(_, key) in advisories">Show {{ key }} <input type="checkbox" v-model="advisories[key]" /></div> | ||
</main> | ||
</template> | ||
|
||
<script> | ||
import { defineComponent, toRaw } from 'vue'; | ||
import * as storage from '../storage'; | ||
import { sendEventSettingsChanged } from './popup-events'; | ||
export default defineComponent({ | ||
data() { | ||
return { | ||
advisories: {}, | ||
}; | ||
}, | ||
mounted() { | ||
storage.getAllAdvisoriesSettings().then((settings) => (this.advisories = settings)); | ||
}, | ||
watch: { | ||
advisories: { | ||
handler(advisories) { | ||
storage.setAllAdvisoriesSettings(toRaw(advisories)).then(sendEventSettingsChanged); | ||
}, | ||
deep: true, | ||
immediate: false, | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped></style> |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/main.js"></script> | ||
</body> | ||
</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,4 @@ | ||
import { createApp } from 'vue'; | ||
import Popup from './Popup.vue'; | ||
|
||
createApp(Popup).mount('#app'); |
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 @@ | ||
import { EVENT_SETTINGS_CHANGED, sendMessageToAllTabs } from '../events-shared'; | ||
|
||
export const sendEventSettingsChanged = () => { | ||
sendMessageToAllTabs(EVENT_SETTINGS_CHANGED); | ||
}; |
Oops, something went wrong.