<commit_before>/**
 * TagSpaces - universal file and folder organizer
 * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License (version 3) as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @flow
 */

import React, { useState } from 'react';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import withMobileDialog from '@material-ui/core/withMobileDialog';
import semver from 'semver';
import GenericDialog from './GenericDialog';
import LogoIcon from '../../assets/images/icon100x100.svg';
import i18n from '../../services/i18n';
import versionMeta from '../../version.json';
import PlatformIO from '../../services/platform-io';
import { Pro } from '../../pro';
import { getLastVersionPromise } from '../../reducers/settings';
import AppConfig from '../../config';

type Props = {
  open: boolean,
  fullScreen: boolean,
  toggleLicenseDialog: () => void,
  toggleThirdPartyLibsDialog: () => void,
  onClose: () => void
};

let buildID = versionMeta.commitId;
if (buildID && buildID.length >= 11) {
  buildID = buildID.slice(0, 11);
}

const productName = versionMeta.name + (Pro ? ' Pro' : '');
document.title = productName + ' ' + versionMeta.version;

const AboutDialog = (props: Props) => {
  const [updateAvailable, setUpdateAvailable] = useState(false);
  const [newVersion, setNewVersion] = useState('');

  function checkForUpdates() {
    if (updateAvailable) {
      PlatformIO.openUrl(AppConfig.links.downloadURL);
    } else {
      getLastVersionPromise()
        .then(lastVersion => {
          console.log('Last version on server: ' + lastVersion);
          const cleanedLastVersion = semver.coerce(lastVersion);
          // const cleanedCurrentVersion = '3.0.2'
          const cleanedCurrentVersion = semver.coerce(versionMeta.version);
          if (
            semver.valid(cleanedLastVersion) &&
            semver.gt(cleanedLastVersion, cleanedCurrentVersion)
          ) {
            setUpdateAvailable(true);
            setNewVersion(cleanedLastVersion.version);
          } else {
            setNewVersion(versionMeta.version);
          }
          return true;
        })
        .catch(error => {
          console.warn('Error while checking for update: ' + error);
        });
    }
  }

  function renderTitle() {
    return (
      <DialogTitle>{productName}</DialogTitle>
    );
  }

  function renderContent() {
    return (
      <DialogContent>
        <img
          alt="TagSpaces logo"
          src={LogoIcon}
          style={{ float: 'left', marginRight: 10, width: 120, height: 120 }}
        />
        <Typography
          variant="subtitle1"
          title={'Build on: ' + versionMeta.buildTime}
        >
          Version: {versionMeta.version} / BuildID: {buildID}
        </Typography>
        <br />
        <Typography id="aboutContent" variant="body1">
          <strong>{productName}</strong> is made possible by the
          TagSpaces(github.com/tagspaces) open source project and other{' '}
          <Button onClick={props.toggleThirdPartyLibsDialog}>
            open source software
          </Button>
          .
          <br />
          {!Pro && (
            <span>
              This program is free software: you can redistribute it and/or modify
              it under the terms of the GNU Affero General Public License (version
              3) as published by the Free Software Foundation.
            </span>
          )}
          <br />
          This program is distributed in the hope that it will be useful, but
          WITHOUT ANY WARRANTY; without even the implied warranty of
          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for
          more details.
          <br />
          <br /><commit_msg>adding platform information in about box<commit_after>/**
 * TagSpaces - universal file and folder organizer
 * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License (version 3) as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @flow
 */

import React, { useState } from 'react';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import withMobileDialog from '@material-ui/core/withMobileDialog';
import semver from 'semver';
import GenericDialog from './GenericDialog';
import LogoIcon from '../../assets/images/icon100x100.svg';
import i18n from '../../services/i18n';
import versionMeta from '../../version.json';
import PlatformIO from '../../services/platform-io';
import { Pro } from '../../pro';
import { getLastVersionPromise } from '../../reducers/settings';
import AppConfig from '../../config';

type Props = {
  open: boolean,
  fullScreen: boolean,
  toggleLicenseDialog: () => void,
  toggleThirdPartyLibsDialog: () => void,
  onClose: () => void
};

let buildID = versionMeta.commitId;
if (buildID && buildID.length >= 11) {
  buildID = buildID.slice(0, 11);
}

const productName = versionMeta.name + (Pro ? ' Pro' : '');
document.title = productName + ' ' + versionMeta.version;

const AboutDialog = (props: Props) => {
  const [updateAvailable, setUpdateAvailable] = useState(false);
  const [newVersion, setNewVersion] = useState('');

  function checkForUpdates() {
    if (updateAvailable) {
      PlatformIO.openUrl(AppConfig.links.downloadURL);
    } else {
      getLastVersionPromise()
        .then(lastVersion => {
          console.log('Last version on server: ' + lastVersion);
          const cleanedLastVersion = semver.coerce(lastVersion);
          // const cleanedCurrentVersion = '3.0.2'
          const cleanedCurrentVersion = semver.coerce(versionMeta.version);
          if (
            semver.valid(cleanedLastVersion) &&
            semver.gt(cleanedLastVersion, cleanedCurrentVersion)
          ) {
            setUpdateAvailable(true);
            setNewVersion(cleanedLastVersion.version);
          } else {
            setNewVersion(versionMeta.version);
          }
          return true;
        })
        .catch(error => {
          console.warn('Error while checking for update: ' + error);
        });
    }
  }

  function renderTitle() {
    return (
      <DialogTitle>{productName}</DialogTitle>
    );
  }

  function renderContent() {
    return (
      <DialogContent>
        <img
          alt="TagSpaces logo"
          src={LogoIcon}
          style={{ float: 'left', marginRight: 10, width: 120, height: 120 }}
        />
        <Typography
          variant="subtitle1"
          title={'Build on: ' + versionMeta.buildTime + '\nPlatform: ' + navigator.appVersion}
        >
          Version: {versionMeta.version} / BuildID: {buildID}
        </Typography>
        <br />
        <Typography id="aboutContent" variant="body1">
          <strong>{productName}</strong> is made possible by the
          TagSpaces(github.com/tagspaces) open source project and other{' '}
          <Button onClick={props.toggleThirdPartyLibsDialog}>
            open source software
          </Button>
          .
          <br />
          {!Pro && (
            <span>
              This program is free software: you can redistribute it and/or modify
              it under the terms of the GNU Affero General Public License (version
              3) as published by the Free Software Foundation.
            </span>
          )}
          <br />
          This program is distributed in the hope that it will be useful, but
          WITHOUT ANY WARRANTY; without even the implied warranty of
          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for
          more details.
          <br />
          <br />
{'fraction_non_alphanumeric': 0.11059755694948828, 'fraction_numerical': 0.007483217783646968, 'mean_word_length': 2.6192751891676624, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 55, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1671859', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2392, 'n_words': 761}