Skip to content

Commit

Permalink
feat(uninstall): Add extensionId parameter to uninstall URL
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar committed Nov 16, 2020
1 parent c24b94c commit 623d512
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env.proding
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BACKEND_ORIGIN=https://notices.bulles.fr/api/v3/
REFRESH_MC_INTERVAL=5
REFRESH_CONTRIBUTORS_INTERVAL=5

UNINSTALL_ORIGIN=https://www.bulles.fr/desinstallation
UNINSTALL_ORIGIN=https://www.dismoi.io/desinstallation

# Tracking
TRACKING_URL=https://stats.lmem.net/matomo.php
Expand Down
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BACKEND_ORIGIN=https://notices.bulles.fr/api/v3/
REFRESH_MC_INTERVAL=30
REFRESH_CONTRIBUTORS_INTERVAL=30

UNINSTALL_ORIGIN=https://www.bulles.fr/desinstallation
UNINSTALL_ORIGIN=https://www.dismoi.io/desinstallation

# Tracking
TRACKING_URL=https://stats.lmem.net/matomo.php
Expand Down
2 changes: 1 addition & 1 deletion .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BACKEND_ORIGIN=https://staging-notices.bulles.fr/api/v3/
REFRESH_MC_INTERVAL=5
REFRESH_CONTRIBUTORS_INTERVAL=5

UNINSTALL_ORIGIN=https://www.bulles.fr/desinstallation
UNINSTALL_ORIGIN=https://www.dismoi.io/desinstallation

# Tracking
TRACKING_URL=https://stats.lmem.net/matomo.php
Expand Down
29 changes: 29 additions & 0 deletions docs/UNINSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Uninstall

Uninstall is handle by the browser natively.

When the extension is **uninstall** we trigger a redirection to the `UNINSTALL_ORIGIN` URL via the `setUninstallURL` hook:
```js
// [...]
browser.runtime.setUninstallURL(
`${UNINSTALL_ORIGIN}${buildQueryString({ extensionId })}`
)
// [...]
```
Here we can add metrics to better understand the reason.

> The `UNINSTALL_ORIGIN` shall remain on the editor domain to better reflect content policy and manifest file.
At present time we use the following script on the uninstall page to forward parameters to our uninstall form URL:
```s
<script>
(function(){
var
u = new URL(window.location.href),
ru = new URL('https://form.jotformeu.com/92173584558367')
;
ru.search = u.search;
window.location = ru.toString();
})()
</script>
```
13 changes: 4 additions & 9 deletions src/app/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ configureSentryScope(scope => {
scope.setTag('context', 'background');
});

const { NODE_ENV, UNINSTALL_ORIGIN } = process.env;
const { NODE_ENV } = process.env;

if (NODE_ENV !== 'production') {
console.info('NODE_ENV', NODE_ENV);
}
console.info(`BACKEND_ORIGIN "${BACKEND_ORIGIN}"`);

onInstalled.then(installedDetails => {
if (typeof UNINSTALL_ORIGIN === 'string') {
browser.runtime.setUninstallURL(UNINSTALL_ORIGIN);
}

store.dispatch(installed(installedDetails));
});

onInstalled.then(installedDetails =>
store.dispatch(installed(installedDetails))
);
onStartup.then(() => store.dispatch(startup()));

const handleConnect = (port: Port) => store.dispatch(connect(port));
Expand Down
15 changes: 14 additions & 1 deletion src/app/background/sagas/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SagaIterator } from 'redux-saga';
import { takeLatest, select, put } from 'redux-saga/effects';
import { takeLatest, select, put, call } from 'redux-saga/effects';
import { captureException } from 'app/utils/sentry';
import { optionsRequested } from 'app/actions';
import {
Expand All @@ -10,11 +10,24 @@ import {
import { getInstallationDate } from 'app/background/selectors/installationDetails';
import { InstallationDetails } from 'app/lmem/installation';
import { version } from '../../../../package.json';
import { loginSaga } from './user.saga';
import { buildQueryString } from 'api/call';

const { UNINSTALL_ORIGIN } = process.env;

export function* installedSaga({
payload: { installedDetails }
}: InstalledAction): SagaIterator {
try {
const extensionId = yield call(loginSaga);
if (typeof UNINSTALL_ORIGIN === 'string') {
browser.runtime
.setUninstallURL(
`${UNINSTALL_ORIGIN}${buildQueryString({ extensionId })}`
)
.catch(e => e);
}

const datetime = yield select(getInstallationDate);

// @todo why not use this function to get the current version ?
Expand Down

0 comments on commit 623d512

Please sign in to comment.