const React = require('react'); import { CSSProperties } from 'react'; const { connect } = require('react-redux'); const { clipboard } = require('electron'); import ExtensionBadge from './ExtensionBadge'; import { themeStyle } from '@joplin/lib/theme'; import { _ } from '@joplin/lib/locale'; import ClipperServer from '@joplin/lib/ClipperServer'; import Setting from '@joplin/lib/models/Setting'; import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService'; import { AppState } from '../app.reducer'; class ClipperConfigScreenComponent extends React.Component { public constructor() { super(); this.copyToken_click = this.copyToken_click.bind(this); } private disableClipperServer_click() { Setting.setValue('clipperServer.autoStart', false); void ClipperServer.instance().stop(); } private enableClipperServer_click() { Setting.setValue('clipperServer.autoStart', true); void ClipperServer.instance().start(); } private copyToken_click() { clipboard.writeText(this.props.apiToken); alert(_('Token has been copied to the clipboard!')); } private renewToken_click() { if (confirm(_('Are you sure you want to renew the authorisation token?'))) { void EncryptionService.instance() .generateApiToken() // eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied .then((token) => { Setting.setValue('api.token', token); }); } } public render() { const theme = themeStyle(this.props.themeId); const containerStyle: CSSProperties = { ...theme.containerStyle, overflowY: 'scroll', // padding: theme.configScreenPadding, backgroundColor: theme.backgroundColor3 }; const buttonStyle = { ...theme.buttonStyle, marginRight: 10 }; const stepBoxStyle = { border: '1px solid', borderColor: theme.dividerColor, padding: 15, paddingTop: 0, marginBottom: 15, backgroundColor: theme.backgroundColor, }; const tokenStyle = { fontFamily: 'monospace', }; const webClipperStatusComps = []; if (this.props.clipperServerAutoStart) { webClipperStatusComps.push(
{_('The web clipper service is enabled and set to auto-start.')}
, ); if (this.props.clipperServer.startState === 'started') { webClipperStatusComps.push({_('Status: Started on port %d', this.props.clipperServer.port)}
, ); } else { webClipperStatusComps.push({_('Status: %s', this.props.clipperServer.startState)}
, ); } webClipperStatusComps.push( , ); } else { webClipperStatusComps.push({_('The web clipper service is not enabled.')}
, ); webClipperStatusComps.push( , ); } const apiTokenStyle: CSSProperties = { ...theme.textStyle, color: theme.colorFaded, wordBreak: 'break-all', paddingTop: 10, paddingBottom: 10 }; return ({_('Joplin Web Clipper allows saving web pages and screenshots from your browser to Joplin.')}
{_('In order to use the web clipper, you need to do the following:')}
{_('Step 1: Enable the clipper service')}
{_('This service allows the browser extension to communicate with Joplin. When enabling it your firewall may ask you to give permission to Joplin to listen to a particular port.')}
{_('Step 2: Install the extension')}
{_('Download and install the relevant extension for your browser:')}
{_('Advanced options')}
{_('Authorisation token:')}
{this.props.apiToken}{' '} {_('Copy token')}
{_('This authorisation token is only needed to allow third-party applications to access Joplin.')}