Skip to content

Commit 0dd3bac

Browse files
committed
Merge branch 'main' of github.com:getlantern/broflake
2 parents f2860f6 + d0f1b02 commit 0dd3bac

File tree

22 files changed

+728
-3632
lines changed

22 files changed

+728
-3632
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ ui/yarn-error.log*
1818
ui/.env
1919
ui/extension/dist
2020
ui/extension/packages
21-
ui/extension/node_modules
2221
ui/extension/.env

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ Links:
162162

163163
3. Install the dependencies: `yarn`
164164

165-
4. To start in developer mode with hot-refresh server (degraded performance): run `yarn start` and visit [http://localhost:3000](http://localhost:3000)
165+
4. To start in developer mode with hot-refresh server (degraded performance): run `yarn dev:web` and visit [http://localhost:3000](http://localhost:3000)
166166

167-
5. To build optimized for best performance run: `yarn build`
167+
5. To build optimized for best performance run: `yarn build:web`
168168

169169
6. To serve a build:
170170
1. Install a simple server e.g. `npm install -g serve` (or your lightweight http server of choice)
@@ -176,19 +176,18 @@ Links:
176176

177177
#### Browser extension quickstart for devs
178178

179-
1. Work from the ui/extension dir: `cd ui/extension`
179+
1. Work from the ui dir: `cd ui`
180180

181181
2. Install the dependencies: `yarn`
182182

183-
3. Configure your .env file: `cp .env.example .env`
184-
1. Set `POPUP_URL` to your intended hosted popup page. If you are serving it from `ui` in [step #6](#ui-quickstart-for-devs), use [http://localhost:3000/popup](http://localhost:3000/popup). To use prod, set to [https://embed.lantern.io/popup](https://embed.lantern.io/popup).
185-
2. Set `OFFSCREEN_URL` to your intended hosted offscreen page. If you are serving it from `ui` in [step #6](#ui-quickstart-for-devs), use [http://localhost:3000/offscreen](http://localhost:3000/offscreen). To use prod, set to [https://embed.lantern.io/offscreen](https://embed.lantern.io/offscreen).
183+
3. Configure your .env file: `cd extension && cp .env.example .env`
184+
1. Set `EXTENSION_POPUP_URL` to your intended hosted popup page. If you are serving it from `ui` in [step #6](#ui-quickstart-for-devs), use [http://localhost:3000/popup](http://localhost:3000/popup). To use prod, set to [https://embed.lantern.io/popup](https://embed.lantern.io/popup).
185+
2. Set `EXTENSION_OFFSCREEN_URL` to your intended hosted offscreen page. If you are serving it from `ui` in [step #6](#ui-quickstart-for-devs), use [http://localhost:3000/offscreen](http://localhost:3000/offscreen). To use prod, set to [https://embed.lantern.io/offscreen](https://embed.lantern.io/offscreen).
186186

187187
3. To start in developer mode with hot-refresh server:
188188
```
189-
yarn dev chrome
190-
yarn dev firefox
191-
yarn dev edge
189+
yarn dev:ext chrome
190+
yarn dev:ext firefox
192191
```
193192

194193
This will compile the extension and output to the `ui/extension/dist` dir. You can then load the unpacked extension in your browser of choice.
@@ -198,9 +197,8 @@ This will compile the extension and output to the `ui/extension/dist` dir. You c
198197

199198
4. To build for production:
200199
```
201-
yarn build chrome
202-
yarn build firefox
203-
yarn build edge
200+
yarn build:ext chrome
201+
yarn build:ext firefox
204202
```
205203

206204
This will compile the extension and output a compressed build to the `ui/extension/packages` dir.

ui/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ REACT_APP_GEO_LOOKUP_URL=https://geo.getiantem.org/lookup
2020
# use https://embed.lantern.io/storage.html for github pages production builds
2121
# use /storage.html for local for devel
2222
# use /storage.html for local production builds
23-
REACT_APP_STORAGE_URL=https://embed.lantern.io/storage.html
23+
REACT_APP_STORAGE_URL=https://embed.lantern.io/storage.html

ui/extension/.env.example

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# POPUP_URL=https://embed.lantern.io/popup
2-
POPUP_URL=http://localhost:3000/popup
3-
# OFFSCREEN_URL=https://embed.lantern.io/offscreen
4-
OFFSCREEN_URL=http://localhost:3000/offscreen
1+
# set `EXTENSION_POPUP_URL` to your intended hosted popup page
2+
# if you are serving it from `ui` use http://localhost:3000/popup
3+
# to use prod, set to https://embed.lantern.io/popup
4+
EXTENSION_POPUP_URL=https://embed.lantern.io/popup
5+
6+
# set `EXTENSION_OFFSCREEN_URL` to your intended hosted offscreen page
7+
# if you are serving it from `ui` use http://localhost:3000/offscreen
8+
# to use prod, set to https://embed.lantern.io/offscreen
9+
EXTENSION_OFFSCREEN_URL=https://embed.lantern.io/offscreen
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {POPUP, SIGNATURE} from '../../../src/constants'
2-
// @todo fixup webpack config to use es6 imports
3-
const messageCheck = (message: MessageEvent['data']) => (typeof message === 'object' && message !== null && message.hasOwnProperty(SIGNATURE))
4-
const app = () => {
1+
import {POPUP} from '../../../src/constants'
2+
import {messageCheck} from '../../../src/utils/messages'
3+
4+
const offscreenApp = () => {
55
const state = {
66
popupOpen: false // maintain state of popup open/close to prevent sending messages to closed popup
77
}
88
const iframe = document.createElement('iframe')
9-
iframe.src = process.env.OFFSCREEN_URL
9+
iframe.src = process.env.EXTENSION_OFFSCREEN_URL!
1010
document.body.appendChild(iframe)
1111
bindOffscreen(iframe, state)
1212
}
1313

14-
const bindOffscreen = (iframe, state) => {
14+
const bindOffscreen = (iframe: HTMLIFrameElement, state: {popupOpen: boolean }) => {
1515
// subscribe to close events from popup to update state
1616
chrome.runtime.onConnect.addListener((port) => {
1717
if (port.name === POPUP) port.onDisconnect.addListener(() => {
@@ -21,12 +21,12 @@ const bindOffscreen = (iframe, state) => {
2121
})
2222

2323
// subscribe to messages from popup to forward to offscreen iframe
24-
chrome.runtime.onMessage.addListener((message) => {
24+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2525
if (messageCheck(message)) {
2626
// if message is that popupOpened, update state
2727
if (message.type === 'popupOpened') return state.popupOpen = true
2828
// console.log('message from chrome, forwarding to iframe: ', message)
29-
iframe.contentWindow.postMessage(message, '*')
29+
iframe.contentWindow!.postMessage(message, '*')
3030
return false
3131
}
3232
})
@@ -41,4 +41,4 @@ const bindOffscreen = (iframe, state) => {
4141
})
4242
}
4343

44-
window.addEventListener('load', app)
44+
window.addEventListener('load', offscreenApp)

ui/extension/app/scripts/popup.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {MessageTypes, SIGNATURE, Themes, POPUP} from '../../../src/constants'
2-
// @todo fixup webpack config to use es6 imports
3-
const _messageCheck = (message: MessageEvent['data']) => (typeof message === 'object' && message !== null && message.hasOwnProperty(SIGNATURE))
4-
const app = () => {
2+
import {messageCheck} from '../../../src/utils/messages'
3+
4+
const popupApp = async () => {
55
const theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? Themes.DARK : Themes.LIGHT
66
const backgroundColor = theme === Themes.DARK ? '#1B1C1D' : '#F8FAFB'
77
// set body styles based on user theme
@@ -10,25 +10,25 @@ const app = () => {
1010
`background-color: ${backgroundColor}; margin: 0; padding: 0; width: 320px; height: 584px; overflow: hidden;` // hide scrollbar on popup, inherit iframe scroll only
1111
)
1212
const iframe = document.createElement('iframe')
13-
iframe.src = process.env.POPUP_URL
13+
iframe.src = process.env.EXTENSION_POPUP_URL!
1414
// set iframe styles based on user theme
1515
iframe.setAttribute(
1616
'style',
1717
`background-color: ${backgroundColor}; width: 320px; height: 584px; border: none; margin: 0; padding: 0;`
1818
)
1919
document.body.appendChild(iframe)
20-
bindPopup(iframe)
20+
await bindPopup(iframe)
2121
}
2222

23-
const bindPopup = (iframe) => {
23+
const bindPopup = async (iframe: HTMLIFrameElement) => {
2424
// connect to port so that offscreen can subscribe to close events
2525
chrome.runtime.connect({'name': POPUP})
2626

2727
// subscribe to messages from offscreen to forward to popup iframe
2828
chrome.runtime.onMessage.addListener((message) => {
29-
if (_messageCheck(message)) {
29+
if (messageCheck(message)) {
3030
// console.log('message from chrome, forwarding to iframe: ', message)
31-
iframe.contentWindow.postMessage(message, '*')
31+
iframe.contentWindow!.postMessage(message, '*')
3232
iconToggleSubscribe(message) // @todo maybe move to service worker
3333
return false
3434
}
@@ -44,15 +44,15 @@ const bindPopup = (iframe) => {
4444
// subscribe to messages from popup iframe to forward to offscreen
4545
window.addEventListener('message', event => {
4646
const message = event.data
47-
if (_messageCheck(message)) {
47+
if (messageCheck(message)) {
4848
// console.log('message from iframe, forwarding to chrome: ', message)
4949
chrome.runtime.sendMessage(message)
5050
}
5151
})
5252
}
5353

5454
// toggle icon based on sharing status messages from offscreen
55-
const iconToggleSubscribe = (message) => {
55+
const iconToggleSubscribe = (message: MessageEvent) => {
5656
if (message.type === MessageTypes.STATE_UPDATE && message.data.emitter === 'sharingEmitter') {
5757
const state = message.data.value ? 'on' : 'off'
5858
// @ts-ignore
@@ -68,4 +68,4 @@ const iconToggleSubscribe = (message) => {
6868
}
6969
}
7070

71-
window.addEventListener('load', app)
71+
window.addEventListener('load', popupApp)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
try {
1+
const launchOffscreen = () => {
22
chrome.offscreen.createDocument({
33
url: chrome.runtime.getURL('pages/offscreen.html'),
44
// @ts-ignore
@@ -7,6 +7,7 @@ try {
77
},
88
() => null
99
)
10-
} catch (e) {
11-
console.error(e)
12-
}
10+
}
11+
12+
chrome.runtime.onInstalled.addListener(launchOffscreen)
13+
chrome.runtime.onStartup.addListener(launchOffscreen)

ui/extension/package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,5 @@
66
"scripts": {
77
"dev": "webextension-toolbox dev",
88
"build": "webextension-toolbox build"
9-
},
10-
"dependencies": {
11-
"@types/chrome": "^0.0.216",
12-
"@webextension-toolbox/webextension-toolbox": "^5.2.2",
13-
"dotenv": "^16.0.3",
14-
"ts-loader": "^9.4.2",
15-
"typescript": "^4.9.5",
16-
"webpack": "^5.75.0",
17-
"webpack-watched-glob-entries-plugin": "^2.2.6"
189
}
19-
}
10+
}

ui/extension/tsconfig.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

ui/extension/webextension-toolbox.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ module.exports = {
1010
const entries = [
1111
resolve(src, "*.{js,mjs,jsx,ts,tsx}"),
1212
resolve(src, "?(scripts)/*.{js,mjs,jsx,ts,tsx}"),
13-
];
13+
]
1414
return ({
1515
...config,
1616
entry: GlobEntriesPlugin.getEntries(entries),
1717
resolve: {
1818
...config.resolve,
19-
extensions: [...config.resolve.extensions, ".ts", ".tsx"],
19+
extensions: [...config.resolve.extensions, ".ts"],
2020
},
2121
module: {
2222
...config.module,
23-
rules: [...config.module.rules, {test: /\.tsx?$/, loader: "ts-loader"}]
23+
rules: [...config.module.rules, {test: /\.ts?$/, loader: "ts-loader"}]
2424
},
2525
plugins: [
2626
...config.plugins,
2727
new webpack.DefinePlugin({
2828
'process.env': JSON.stringify(dotenv.parsed),
2929
'process.env.NODE_ENV': JSON.stringify(isDevelopment ? 'development' : 'production'),
3030
}),
31-
].filter(Boolean)
31+
]
3232
})
3333
},
3434
}

0 commit comments

Comments
 (0)