mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-22 04:25:06 +01:00
Disable push notification when not logged in (#19272)
This commit is contained in:
parent
37eaa7fc01
commit
216dbaedaf
@ -1,19 +1,5 @@
|
|||||||
import {
|
import { setAlerts } from './setter';
|
||||||
SET_BROWSER_SUPPORT,
|
import { saveSettings } from './registerer';
|
||||||
SET_SUBSCRIPTION,
|
|
||||||
CLEAR_SUBSCRIPTION,
|
|
||||||
SET_ALERTS,
|
|
||||||
setAlerts,
|
|
||||||
} from './setter';
|
|
||||||
import { register, saveSettings } from './registerer';
|
|
||||||
|
|
||||||
export {
|
|
||||||
SET_BROWSER_SUPPORT,
|
|
||||||
SET_SUBSCRIPTION,
|
|
||||||
CLEAR_SUBSCRIPTION,
|
|
||||||
SET_ALERTS,
|
|
||||||
register,
|
|
||||||
};
|
|
||||||
|
|
||||||
export function changeAlerts(path, value) {
|
export function changeAlerts(path, value) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
@ -21,3 +7,11 @@ export function changeAlerts(path, value) {
|
|||||||
dispatch(saveSettings());
|
dispatch(saveSettings());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
CLEAR_SUBSCRIPTION,
|
||||||
|
SET_BROWSER_SUPPORT,
|
||||||
|
SET_SUBSCRIPTION,
|
||||||
|
SET_ALERTS,
|
||||||
|
} from './setter';
|
||||||
|
export { register } from './registerer';
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import * as registerPushNotifications from 'mastodon/actions/push_notifications';
|
|
||||||
import { setupBrowserNotifications } from 'mastodon/actions/notifications';
|
import { setupBrowserNotifications } from 'mastodon/actions/notifications';
|
||||||
import Mastodon, { store } from 'mastodon/containers/mastodon';
|
import Mastodon, { store } from 'mastodon/containers/mastodon';
|
||||||
import ready from 'mastodon/ready';
|
import ready from 'mastodon/ready';
|
||||||
|
|
||||||
const perf = require('./performance');
|
const perf = require('mastodon/performance');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
perf.start('main()');
|
perf.start('main()');
|
||||||
|
|
||||||
@ -18,7 +20,7 @@ function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ready(() => {
|
return ready(async () => {
|
||||||
const mountNode = document.getElementById('mastodon');
|
const mountNode = document.getElementById('mastodon');
|
||||||
const props = JSON.parse(mountNode.getAttribute('data-props'));
|
const props = JSON.parse(mountNode.getAttribute('data-props'));
|
||||||
|
|
||||||
@ -26,19 +28,28 @@ function main() {
|
|||||||
store.dispatch(setupBrowserNotifications());
|
store.dispatch(setupBrowserNotifications());
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||||
import('workbox-window')
|
const [{ Workbox }, { me }] = await Promise.all([
|
||||||
.then(({ Workbox }) => {
|
import('workbox-window'),
|
||||||
const wb = new Workbox('/sw.js');
|
import('mastodon/initial_state'),
|
||||||
|
]);
|
||||||
|
|
||||||
return wb.register();
|
const wb = new Workbox('/sw.js');
|
||||||
})
|
|
||||||
.then(() => {
|
try {
|
||||||
store.dispatch(registerPushNotifications.register());
|
await wb.register();
|
||||||
})
|
} catch (err) {
|
||||||
.catch(err => {
|
console.error(err);
|
||||||
console.error(err);
|
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (me) {
|
||||||
|
const registerPushNotifications = await import('mastodon/actions/push_notifications');
|
||||||
|
|
||||||
|
store.dispatch(registerPushNotifications.register());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
perf.stop('main()');
|
perf.stop('main()');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,32 @@
|
|||||||
export default function ready(loaded) {
|
// @ts-check
|
||||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
|
||||||
loaded();
|
/**
|
||||||
} else {
|
* @param {(() => void) | (() => Promise<void>)} callback
|
||||||
document.addEventListener('DOMContentLoaded', loaded);
|
* @returns {Promise<void>}
|
||||||
}
|
*/
|
||||||
|
export default function ready(callback) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
function loaded() {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = callback();
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof result?.then === 'function') {
|
||||||
|
result.then(resolve).catch(reject);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||||
|
loaded();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', loaded);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ import { start } from '../mastodon/common';
|
|||||||
|
|
||||||
start();
|
start();
|
||||||
|
|
||||||
loadPolyfills().then(() => {
|
loadPolyfills().then(async () => {
|
||||||
require('../mastodon/main').default();
|
const { default: main } = import('mastodon/main');
|
||||||
|
|
||||||
|
return main();
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
13
yarn.lock
13
yarn.lock
@ -3211,15 +3211,10 @@ caniuse-api@^3.0.0:
|
|||||||
lodash.memoize "^4.1.2"
|
lodash.memoize "^4.1.2"
|
||||||
lodash.uniq "^4.5.0"
|
lodash.uniq "^4.5.0"
|
||||||
|
|
||||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219:
|
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001400:
|
||||||
version "1.0.30001310"
|
version "1.0.30001414"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001310.tgz#da02cd07432c9eece6992689d1b84ca18139eea8"
|
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001414.tgz"
|
||||||
integrity sha512-cb9xTV8k9HTIUA3GnPUJCk0meUnrHL5gy5QePfDjxHyNBcnzPzrHFv5GqfP7ue5b1ZyzZL0RJboD6hQlPXjhjg==
|
integrity sha512-t55jfSaWjCdocnFdKQoO+d2ct9C59UZg4dY3OnUlSZ447r8pUtIKdp0hpAzrGFultmTC+Us+KpKi4GZl/LXlFg==
|
||||||
|
|
||||||
caniuse-lite@^1.0.30001400:
|
|
||||||
version "1.0.30001406"
|
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001406.tgz#d0146e7919635479f873b4507517b627f66ab269"
|
|
||||||
integrity sha512-bWTlaXUy/rq0BBtYShc/jArYfBPjEV95euvZ8JVtO43oQExEN/WquoqpufFjNu4kSpi5cy5kMbNvzztWDfv1Jg==
|
|
||||||
|
|
||||||
chalk@^1.1.3:
|
chalk@^1.1.3:
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
|
Loading…
Reference in New Issue
Block a user