From faabd9e693bc4ce5146bb775b53d8ff76476c19c Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Fri, 1 Oct 2021 15:06:22 +0200 Subject: [PATCH 1/6] init senseBox connect features --- src/actions/generalActions.js | 22 ++-- src/actions/types.js | 1 + src/components/Home.js | 182 ++++++++++++++++++---------- src/components/Workspace/Compile.js | 60 +++++++-- src/reducers/generalReducer.js | 74 +++++++---- 5 files changed, 237 insertions(+), 102 deletions(-) diff --git a/src/actions/generalActions.js b/src/actions/generalActions.js index 754f438..f4dd22f 100644 --- a/src/actions/generalActions.js +++ b/src/actions/generalActions.js @@ -1,32 +1,38 @@ -import { VISIT, LANGUAGE, RENDERER, STATISTICS } from './types'; - +import { VISIT, LANGUAGE, RENDERER, STATISTICS, PLATFORM } from "./types"; export const visitPage = () => (dispatch) => { dispatch({ - type: VISIT + type: VISIT, + }); +}; + +export const setPlatform = (platform) => (dispatch) => { + dispatch({ + type: PLATFORM, + payload: platform, }); }; export const setLanguage = (language) => (dispatch, getState) => { - if(!getState().auth.progress && !getState().auth.isAuthenticated){ - window.localStorage.setItem('locale', language); + if (!getState().auth.progress && !getState().auth.isAuthenticated) { + window.localStorage.setItem("locale", language); } dispatch({ type: LANGUAGE, - payload: language + payload: language, }); }; export const setRenderer = (renderer) => (dispatch) => { dispatch({ type: RENDERER, - payload: renderer + payload: renderer, }); }; export const setStatistics = (showStatistics) => (dispatch) => { dispatch({ type: STATISTICS, - payload: showStatistics + payload: showStatistics, }); }; diff --git a/src/actions/types.js b/src/actions/types.js index 7b474d6..223154d 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -43,6 +43,7 @@ export const PROGRESS = "PROGRESS"; export const VISIT = "VISIT"; export const LANGUAGE = "LANGUAGE"; +export const PLATFORM = "PLATFORM"; export const RENDERER = "RENDERER"; export const STATISTICS = "STATISTICS"; diff --git a/src/components/Home.js b/src/components/Home.js index d169d24..8fd25d7 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -1,68 +1,72 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { clearStats, workspaceName } from '../actions/workspaceActions'; +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { connect } from "react-redux"; +import { clearStats, workspaceName } from "../actions/workspaceActions"; -import * as Blockly from 'blockly/core'; -import { createNameId } from 'mnemonic-id'; +import * as Blockly from "blockly/core"; +import { createNameId } from "mnemonic-id"; -import WorkspaceStats from './Workspace/WorkspaceStats'; -import WorkspaceFunc from './Workspace/WorkspaceFunc'; -import BlocklyWindow from './Blockly/BlocklyWindow'; -import CodeViewer from './CodeViewer'; -import TrashcanButtons from './Workspace/TrashcanButtons'; -import HintTutorialExists from './Tutorial/HintTutorialExists'; -import Snackbar from './Snackbar'; +import WorkspaceStats from "./Workspace/WorkspaceStats"; +import WorkspaceFunc from "./Workspace/WorkspaceFunc"; +import BlocklyWindow from "./Blockly/BlocklyWindow"; +import CodeViewer from "./CodeViewer"; +import TrashcanButtons from "./Workspace/TrashcanButtons"; +import HintTutorialExists from "./Tutorial/HintTutorialExists"; -import Grid from '@material-ui/core/Grid'; -import IconButton from '@material-ui/core/IconButton'; -import Tooltip from '@material-ui/core/Tooltip'; -import { withStyles } from '@material-ui/core/styles'; +import Grid from "@material-ui/core/Grid"; +import IconButton from "@material-ui/core/IconButton"; +import Tooltip from "@material-ui/core/Tooltip"; +import { withStyles } from "@material-ui/core/styles"; import { faCode } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import TooltipViewer from './TooltipViewer'; - +import TooltipViewer from "./TooltipViewer"; +import Dialog from "./Dialog"; const styles = (theme) => ({ codeOn: { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, - '&:hover': { + "&:hover": { backgroundColor: theme.palette.primary.contrastText, color: theme.palette.primary.main, - border: `1px solid ${theme.palette.secondary.main}` - } + border: `1px solid ${theme.palette.secondary.main}`, + }, }, codeOff: { backgroundColor: theme.palette.primary.contrastText, color: theme.palette.primary.main, border: `1px solid ${theme.palette.secondary.main}`, - '&:hover': { + "&:hover": { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, - } - } + }, + }, }); - class Home extends Component { - state = { codeOn: true, snackbar: false, - type: '', - key: '', - message: '' - } + type: "", + key: "", + message: "", + open: true, + }; componentDidMount() { - this.setState({ stats: window.localStorage.getItem('stats') }); + console.log(this.props.platform); + this.setState({ stats: window.localStorage.getItem("stats") }); if (!this.props.project) { this.props.workspaceName(createNameId()); } - if (this.props.message && this.props.message.id === 'GET_SHARE_FAIL') { - this.setState({ snackbar: true, key: Date.now(), message: `Das angefragte geteilte Projekt konnte nicht gefunden werden.`, type: 'error' }); + if (this.props.message && this.props.message.id === "GET_SHARE_FAIL") { + this.setState({ + snackbar: true, + key: Date.now(), + message: `Das angefragte geteilte Projekt konnte nicht gefunden werden.`, + type: "error", + }); } } @@ -80,6 +84,10 @@ class Home extends Component { this.props.workspaceName(null); } + toggleDialog = () => { + this.setState({ open: !this.state }); + }; + onChange = () => { this.setState({ codeOn: !this.state.codeOn }); const workspace = Blockly.getMainWorkspace(); @@ -87,67 +95,113 @@ class Home extends Component { if (workspace.trashcan && workspace.trashcan.flyout) { workspace.trashcan.flyout.hide(); // in case of resize, the trash flyout does not reposition } - } + }; render() { return (
- {this.props.statistics ? -
- : null - } -
- + {this.props.statistics ? ( +
+ +
+ ) : null} +
+
- - + + this.onChange()} > -
- {this.props.project ? - < BlocklyWindow blocklyCSS={{ height: '80vH' }} initialXml={this.props.project.xml} /> - : < BlocklyWindow blocklyCSS={{ height: '80vH' }} /> - } +
+ {this.props.project ? ( + + ) : ( + + )}
- {this.state.codeOn ? + {this.state.codeOn ? ( - : null} + ) : null} - + {this.props.platform ? ( + +
Du verwendest: {this.props.platform}
+
Lade die App hier herunter:
+
+ Testlink:{" "} + Öffne App +
+
+ ) : null}
); - }; + } } Home.propTypes = { clearStats: PropTypes.func.isRequired, workspaceName: PropTypes.func.isRequired, message: PropTypes.object.isRequired, - statistics: PropTypes.bool.isRequired + statistics: PropTypes.bool.isRequired, + platform: PropTypes.object.isRequired, }; -const mapStateToProps = state => ({ +const mapStateToProps = (state) => ({ message: state.message, - statistics: state.general.statistics + statistics: state.general.statistics, + platform: state.general.platform, }); - -export default connect(mapStateToProps, { clearStats, workspaceName })(withStyles(styles, { withTheme: true })(Home)); +export default connect(mapStateToProps, { clearStats, workspaceName })( + withStyles(styles, { withTheme: true })(Home) +); diff --git a/src/components/Workspace/Compile.js b/src/components/Workspace/Compile.js index cf8014b..07401f3 100644 --- a/src/components/Workspace/Compile.js +++ b/src/components/Workspace/Compile.js @@ -21,6 +21,7 @@ import "prismjs/themes/prism.css"; import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; import MuiDrawer from "@material-ui/core/Drawer"; +import Dialog from "../Dialog"; const styles = (theme) => ({ backdrop: { @@ -65,6 +66,8 @@ class Compile extends Component { content: "", name: props.name, error: "", + appLink: "", + appDialog: false, }; } @@ -126,21 +129,40 @@ class Compile extends Component { }; toggleDialog = () => { - this.setState({ open: !this.state, progress: false }); + this.setState({ open: !this.state, progress: false, appDialog: false }); }; createFileName = () => { - if (this.state.name) { - this.download(); - } else { + if (this.props.platform === "iOS") { this.setState({ - file: true, - open: true, - title: "Projekt kompilieren", - content: - "Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf 'Eingabe'.", + link: `blocklyconnect-app://${this.state.name}/${this.state.id}`, }); + this.setState({ appDialog: true }); + } else { + if (this.state.name) { + this.download(); + } else { + this.setState({ + file: true, + open: true, + title: "Projekt kompilieren", + content: + "Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf 'Eingabe'.", + }); + } } + + // if (this.state.name) { + // this.download(); + // } else { + // this.setState({ + // file: true, + // open: true, + // title: "Projekt kompilieren", + // content: + // "Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf 'Eingabe'.", + // }); + // } }; setFileName = (e) => { @@ -240,6 +262,24 @@ class Compile extends Component { {`${this.state.error}`}{" "}

+ +
Du verwendest: {this.props.platform}
+
Lade die App hier herunter:
+
+ Testlink: Öffne App +
+
+ {/* ({ arduino: state.workspace.code.arduino, name: state.workspace.name, + platform: state.general.platform, }); export default connect(mapStateToProps, { workspaceName })( diff --git a/src/reducers/generalReducer.js b/src/reducers/generalReducer.js index 1571d63..cb80536 100644 --- a/src/reducers/generalReducer.js +++ b/src/reducers/generalReducer.js @@ -1,60 +1,92 @@ -import { VISIT, LANGUAGE, RENDERER, STATISTICS } from '../actions/types'; +import { + VISIT, + LANGUAGE, + RENDERER, + STATISTICS, + PLATFORM, +} from "../actions/types"; const initialLanguage = () => { - if (window.localStorage.getItem('locale')) { - return window.localStorage.getItem('locale'); + if (window.localStorage.getItem("locale")) { + return window.localStorage.getItem("locale"); } - if (navigator.language === 'de-DE'){ - return 'de_DE'; + if (navigator.language === "de-DE") { + return "de_DE"; } - return 'en_US'; + return "en_US"; +}; + +const getPlatform = () => { + var userAgent = window.navigator.userAgent, + platform = window.navigator.platform, + macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"], + windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"], + iosPlatforms = ["iPhone", "iPad", "iPod"], + os = null; + if (macosPlatforms.indexOf(platform) !== -1) { + os = "Mac OS"; + } else if (iosPlatforms.indexOf(platform) !== -1) { + os = "iOS"; + } else if (windowsPlatforms.indexOf(userAgent) !== -1) { + os = "Windows"; + } else if (/Android/.test(userAgent)) { + os = "Android"; + } else if (!os && /Linux/.test(platform)) { + os = "Linux"; + } + return os; }; const initialRenderer = () => { - if (window.localStorage.getItem('renderer')) { - return window.localStorage.getItem('renderer'); + if (window.localStorage.getItem("renderer")) { + return window.localStorage.getItem("renderer"); } - return 'geras'; + return "geras"; }; const initialStatistics = () => { - if (window.localStorage.getItem('statistics')) { - return JSON.parse(window.localStorage.getItem('statistics')); + if (window.localStorage.getItem("statistics")) { + return JSON.parse(window.localStorage.getItem("statistics")); } return false; }; - const initialState = { pageVisits: 0, // detect if previous URL was language: initialLanguage(), renderer: initialRenderer(), - statistics: initialStatistics() + statistics: initialStatistics(), + platform: getPlatform(), }; -export default function foo(state = initialState, action){ - switch(action.type){ +export default function foo(state = initialState, action) { + switch (action.type) { case VISIT: return { ...state, - pageVisits: state.pageVisits += 1 + pageVisits: (state.pageVisits += 1), }; case LANGUAGE: return { ...state, - language: action.payload + language: action.payload, + }; + case PLATFORM: + return { + ...state, + platform: action.payload, }; case RENDERER: - window.localStorage.setItem('renderer', action.payload); + window.localStorage.setItem("renderer", action.payload); return { ...state, - renderer: action.payload + renderer: action.payload, }; case STATISTICS: - window.localStorage.setItem('statistics', action.payload); + window.localStorage.setItem("statistics", action.payload); return { ...state, - statistics: action.payload + statistics: action.payload, }; default: return state; From 508591f685e6a01cb037652d9bc9addea5261085 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Wed, 6 Oct 2021 10:33:04 +0200 Subject: [PATCH 2/6] Adjust link with correct filename --- src/components/Workspace/Compile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Workspace/Compile.js b/src/components/Workspace/Compile.js index 07401f3..dd81e49 100644 --- a/src/components/Workspace/Compile.js +++ b/src/components/Workspace/Compile.js @@ -134,8 +134,9 @@ class Compile extends Component { createFileName = () => { if (this.props.platform === "iOS") { + const filename = detectWhitespacesAndReturnReadableResult(this.state.name); this.setState({ - link: `blocklyconnect-app://${this.state.name}/${this.state.id}`, + link: `blocklyconnect-app://sketch/${filename}/${this.state.id}`, }); this.setState({ appDialog: true }); } else { From c60d2ddba69e3cce126cad07aeeb00e4ab31a763 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Thu, 7 Oct 2021 11:11:14 +0200 Subject: [PATCH 3/6] add ota settings --- src/components/Blockly/generator/generator.js | 2 + src/components/Home.js | 36 +++--- src/components/Settings/OtaSelector.js | 61 ++++++++++ src/components/Settings/Settings.js | 60 ++++++---- src/components/Workspace/Compile.js | 106 ++++++++++-------- src/reducers/generalReducer.js | 20 +++- 6 files changed, 196 insertions(+), 89 deletions(-) create mode 100644 src/components/Settings/OtaSelector.js diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index e1073c9..c779334 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -259,6 +259,8 @@ Blockly["Arduino"].finish = function (code) { code = devVariables + "\n" + + "#include " + + "\n" + libraryCode + "\n" + variablesCode + diff --git a/src/components/Home.js b/src/components/Home.js index 8fd25d7..ba1f44c 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -45,17 +45,23 @@ const styles = (theme) => ({ }); class Home extends Component { - state = { - codeOn: true, - snackbar: false, - type: "", - key: "", - message: "", - open: true, - }; + constructor(props) { + super(props); + this.state = { + codeOn: true, + snackbar: false, + type: "", + key: "", + message: "", + open: true, + }; + } componentDidMount() { console.log(this.props.platform); + if (this.props.platform === true) { + this.setState({ codeOn: false }); + } this.setState({ stats: window.localStorage.getItem("stats") }); if (!this.props.project) { this.props.workspaceName(createNameId()); @@ -88,6 +94,14 @@ class Home extends Component { this.setState({ open: !this.state }); }; + onChangeCheckbox = (e) => { + if (e.target.checked) { + window.localStorage.setItem("ota", e.target.checked); + } else { + window.localStorage.removeItem("ota"); + } + }; + onChange = () => { this.setState({ codeOn: !this.state.codeOn }); const workspace = Blockly.getMainWorkspace(); @@ -175,12 +189,8 @@ class Home extends Component { onClick={this.toggleDialog} button={Blockly.Msg.button_close} > -
Du verwendest: {this.props.platform}
+
OTA Modus aktiviert.
Lade die App hier herunter:
-
- Testlink:{" "} - Öffne App -
) : null}
diff --git a/src/components/Settings/OtaSelector.js b/src/components/Settings/OtaSelector.js new file mode 100644 index 0000000..a8d989c --- /dev/null +++ b/src/components/Settings/OtaSelector.js @@ -0,0 +1,61 @@ +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { connect } from "react-redux"; +import { setPlatform } from "../../actions/generalActions"; + +import * as Blockly from "blockly/core"; + +import InputLabel from "@material-ui/core/InputLabel"; +import MenuItem from "@material-ui/core/MenuItem"; +import FormControl from "@material-ui/core/FormControl"; +import Select from "@material-ui/core/Select"; +import Typography from "@material-ui/core/Typography"; +import FormHelperText from "@material-ui/core/FormHelperText"; + +class OtaSelector extends Component { + componentDidMount() { + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } + + render() { + return ( +
+ OTA + + Aktiviere OTA Modus{" "} + + + + {Blockly.Msg.settings_statistics} + + + +
+ ); + } +} + +OtaSelector.propTypes = { + setPlatform: PropTypes.func.isRequired, + language: PropTypes.string.isRequired, + platform: PropTypes.bool.isRequired, +}; + +const mapStateToProps = (state) => ({ + language: state.general.language, + platform: state.general.platform, +}); + +export default connect(mapStateToProps, { setPlatform })(OtaSelector); diff --git a/src/components/Settings/Settings.js b/src/components/Settings/Settings.js index 24b3bfa..ac1a538 100644 --- a/src/components/Settings/Settings.js +++ b/src/components/Settings/Settings.js @@ -1,22 +1,22 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { connect } from "react-redux"; -import { withRouter } from 'react-router-dom'; +import { withRouter } from "react-router-dom"; -import * as Blockly from 'blockly/core'; +import * as Blockly from "blockly/core"; -import Breadcrumbs from '../Breadcrumbs'; -import LanguageSelector from './LanguageSelector'; -import RenderSelector from './RenderSelector'; -import StatsSelector from './StatsSelector'; +import Breadcrumbs from "../Breadcrumbs"; +import LanguageSelector from "./LanguageSelector"; +import RenderSelector from "./RenderSelector"; +import StatsSelector from "./StatsSelector"; +import OtaSelector from "./OtaSelector"; -import Button from '@material-ui/core/Button'; -import Paper from '@material-ui/core/Paper'; +import Button from "@material-ui/core/Button"; +import Paper from "@material-ui/core/Paper"; class Settings extends Component { - - componentDidMount(){ + componentDidMount() { // Ensure that Blockly.setLocale is adopted in the component. // Otherwise, the text will not be displayed until the next update of the component. this.forceUpdate(); @@ -25,41 +25,55 @@ class Settings extends Component { render() { return (
- +

{Blockly.Msg.settings_head}

- + - + - + + + +
); - }; + } } Settings.propTypes = { language: PropTypes.string.isRequired, - pageVisits: PropTypes.number.isRequired + pageVisits: PropTypes.number.isRequired, }; -const mapStateToProps = state => ({ +const mapStateToProps = (state) => ({ language: state.general.language, - pageVisits: state.general.pageVisits + pageVisits: state.general.pageVisits, }); export default connect(mapStateToProps, null)(withRouter(Settings)); diff --git a/src/components/Workspace/Compile.js b/src/components/Workspace/Compile.js index dd81e49..fe8e772 100644 --- a/src/components/Workspace/Compile.js +++ b/src/components/Workspace/Compile.js @@ -22,6 +22,7 @@ import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; import MuiDrawer from "@material-ui/core/Drawer"; import Dialog from "../Dialog"; +import { Link } from "react-router-dom"; const styles = (theme) => ({ backdrop: { @@ -133,8 +134,10 @@ class Compile extends Component { }; createFileName = () => { - if (this.props.platform === "iOS") { - const filename = detectWhitespacesAndReturnReadableResult(this.state.name); + if (this.props.platform === true) { + const filename = detectWhitespacesAndReturnReadableResult( + this.state.name + ); this.setState({ link: `blocklyconnect-app://sketch/${filename}/${this.state.id}`, }); @@ -211,23 +214,44 @@ class Compile extends Component { Kompilieren )} - -
- copyimage -

{Blockly.Msg.compile_overlay_head}

-

{Blockly.Msg.compile_overlay_text}

-

- {Blockly.Msg.compile_overlay_help} - - FAQ - -

- -
-
+ + {this.props.platform === false ? ( + +
+ copyimage +

{Blockly.Msg.compile_overlay_head}

+

{Blockly.Msg.compile_overlay_text}

+

+ {Blockly.Msg.compile_overlay_help} + + FAQ + +

+ +
+
+ ) : ( + +
+ {/* copyimage */} +

Dein Code wird kompiliert!

+

übertrage ihn anschließend mithlfe der senseBoxConnect-App

+

+ {Blockly.Msg.compile_overlay_help} + + FAQ + +

+ +
+
+ )} -
Du verwendest: {this.props.platform}
-
Lade die App hier herunter:
- Testlink: Öffne App +

Dein Code wurde erfolgreich kompiliert

+ + +
- - {/* { this.toggleDialog(); this.setState({ name: this.props.name }) } : this.toggleDialog} - button={this.state.file ? Blockly.Msg.button_cancel : Blockly.Msg.button_close} - > - {this.state.file ? -
- - -
- : - -

-                {`${this.state.error}`}
-              
- - - - } -
*/}
); } @@ -313,7 +325,7 @@ Compile.propTypes = { arduino: PropTypes.string.isRequired, name: PropTypes.string, workspaceName: PropTypes.func.isRequired, - platform: PropTypes.object.isRequired, + platform: PropTypes.bool.isRequired, }; const mapStateToProps = (state) => ({ diff --git a/src/reducers/generalReducer.js b/src/reducers/generalReducer.js index cb80536..555d093 100644 --- a/src/reducers/generalReducer.js +++ b/src/reducers/generalReducer.js @@ -16,7 +16,14 @@ const initialLanguage = () => { return "en_US"; }; +const initialPlatform = () => { + return getPlatform(); +}; + const getPlatform = () => { + if (window.localStorage.getItem("platform")) { + return JSON.parse(window.localStorage.getItem("platform")); + } var userAgent = window.navigator.userAgent, platform = window.navigator.platform, macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"], @@ -24,15 +31,15 @@ const getPlatform = () => { iosPlatforms = ["iPhone", "iPad", "iPod"], os = null; if (macosPlatforms.indexOf(platform) !== -1) { - os = "Mac OS"; + os = false; } else if (iosPlatforms.indexOf(platform) !== -1) { - os = "iOS"; + os = true; } else if (windowsPlatforms.indexOf(userAgent) !== -1) { - os = "Windows"; + os = false; } else if (/Android/.test(userAgent)) { - os = "Android"; + os = true; } else if (!os && /Linux/.test(platform)) { - os = "Linux"; + os = false; } return os; }; @@ -56,7 +63,7 @@ const initialState = { language: initialLanguage(), renderer: initialRenderer(), statistics: initialStatistics(), - platform: getPlatform(), + platform: initialPlatform(), }; export default function foo(state = initialState, action) { @@ -72,6 +79,7 @@ export default function foo(state = initialState, action) { language: action.payload, }; case PLATFORM: + window.localStorage.setItem("platform", action.payload); return { ...state, platform: action.payload, From 0e33361ee8df6894b2c82779142fadf487b5ebf9 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Wed, 27 Oct 2021 15:27:27 +0200 Subject: [PATCH 4/6] added a new comment --- src/components/Blockly/blocks/variables.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Blockly/blocks/variables.js b/src/components/Blockly/blocks/variables.js index 8e19984..b04a4b2 100644 --- a/src/components/Blockly/blocks/variables.js +++ b/src/components/Blockly/blocks/variables.js @@ -44,3 +44,7 @@ Blockly.Blocks["variables_get_dynamic"] = { } }, }; + +/** + * new comment + */ From d67cb74401d3a064b1f1be8b4c08bfb42d53cc41 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Wed, 3 Nov 2021 12:22:51 +0100 Subject: [PATCH 5/6] add translations and informations --- src/components/Blockly/blocks/variables.js | 4 ---- src/components/Blockly/msg/de/ui.js | 15 +++++++++++++++ src/components/Blockly/msg/en/ui.js | 14 ++++++++++++++ src/components/Home.js | 15 ++++++++++++--- src/components/Settings/OtaSelector.js | 13 +++++++++---- src/components/Workspace/Compile.js | 1 - 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/components/Blockly/blocks/variables.js b/src/components/Blockly/blocks/variables.js index b04a4b2..8e19984 100644 --- a/src/components/Blockly/blocks/variables.js +++ b/src/components/Blockly/blocks/variables.js @@ -44,7 +44,3 @@ Blockly.Blocks["variables_get_dynamic"] = { } }, }; - -/** - * new comment - */ diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 917bb27..9772229 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -83,6 +83,16 @@ export const UI = { messages_LOGIN_FAIL: "Der Benutzername oder das Passwort ist nicht korrekt.", messages_copy_code: "Code wurde in die Zwischenablage kopiert", + /** + * Tablet Dialog + */ + + tabletDialog_headline: "Tablet Modus ist aktiviert!", + tabletDialog_text: + "Der Tablet Modus wurde aktiviert. Du kannst nun Programmcodes über die senseBox Connect App auf deine senseBox kopieren. Der Tablet Modus kann in den Einstellungen deaktiviert werden", + tabletDialog_more: + "Weitere Informationen und den Link zum Download der App findest du unter: ", + /** * Reset Dialog */ @@ -154,6 +164,11 @@ export const UI = { "Die Anzeige von Statistiken zur Nutzung der Blöcke oberhalb der Arbeitsfläche kann ein- oder ausgeblendet werden.", settings_statistics_on: "An", settings_statistics_off: "Aus", + settings_ota_head: "Tablet Modus", + settings_ota_text: + "Der Tablet Modus deaktiviert die Code anzeige und aktiviert die Möglichkeit den Programmcode über die senseBox Connect App zu übertragen. Weitere Informationen dazu findest du unter: ", + settings_ota_on: "Aktiviert", + settings_ota_off: "Deaktiviert", /** * 404 diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 3859ab3..2a4d038 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -80,6 +80,15 @@ export const UI = { messages_login_error: "Enter both a username and a password.", messages_copy_code: "Copy code to clipboard succesfull", + /** + * Tablet Dialog + */ + tabletDialog_headline: "Tablet mode is enabled!", + tabletDialog_text: + "Tablet mode has been activated. You can now copy program codes to your senseBox via the senseBox Connect app. Tablet mode can be deactivated in the settings", + tabletDialog_more: + "For more information and the link to download the app, please visit: ", + /** * Reset Dialog */ @@ -149,6 +158,11 @@ export const UI = { "The display of statistics on the usage of the blocks above the workspace can be shown or hidden.", settings_statistics_on: "On", settings_statistics_off: "Off", + settings_ota_head: "tablet mode", + settings_ota_text: + "Tablet mode disables the code display and enables the possibility to transfer the program code via the senseBox Connect app. You can find more information on: ", + settings_ota_on: "Activated", + settings_ota_off: "Deactivated", /** * 404 diff --git a/src/components/Home.js b/src/components/Home.js index ba1f44c..9ac7ec9 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -183,14 +183,23 @@ class Home extends Component { fullWidth maxWidth={"sm"} open={this.state.open} - title="" + title={Blockly.Msg.tabletDialog_headline} content={""} onClose={this.toggleDialog} onClick={this.toggleDialog} button={Blockly.Msg.button_close} > -
OTA Modus aktiviert.
-
Lade die App hier herunter:
+
{Blockly.Msg.tabletDialog_text}
+
+ {Blockly.Msg.tabletDialog_more}{" "} + + https://sensebox.de/app + +
) : null} diff --git a/src/components/Settings/OtaSelector.js b/src/components/Settings/OtaSelector.js index a8d989c..8a55b82 100644 --- a/src/components/Settings/OtaSelector.js +++ b/src/components/Settings/OtaSelector.js @@ -22,11 +22,16 @@ class OtaSelector extends Component { render() { return (
- OTA + + {Blockly.Msg.settings_ota_head} + - Aktiviere OTA Modus{" "} + {Blockly.Msg.settings_ota_text} + + https://sensebox.de/app + @@ -38,8 +43,8 @@ class OtaSelector extends Component { value={this.props.platform} onChange={(e) => this.props.setPlatform(e.target.value)} > - true - false + {Blockly.Msg.settings_ota_on} + {Blockly.Msg.settings_ota_off}
diff --git a/src/components/Workspace/Compile.js b/src/components/Workspace/Compile.js index fe8e772..1bea26c 100644 --- a/src/components/Workspace/Compile.js +++ b/src/components/Workspace/Compile.js @@ -22,7 +22,6 @@ import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; import MuiDrawer from "@material-ui/core/Drawer"; import Dialog from "../Dialog"; -import { Link } from "react-router-dom"; const styles = (theme) => ({ backdrop: { From faaabf907ba5cb136dd63d12bce3769722e67abc Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Wed, 3 Nov 2021 12:31:30 +0100 Subject: [PATCH 6/6] update code generator --- src/components/Blockly/generator/generator.js | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index c779334..29b77a1 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -26,6 +26,17 @@ import * as Blockly from "blockly/core"; +import store from "../../../store"; + +var ota = store.getState().general.platform + ? store.getState().general.platform + : null; +store.subscribe(() => { + ota = store.getState().general.platform + ? store.getState().general.platform + : null; +}); + /** * Arduino code generator. * @type !Blockly.Generator @@ -254,28 +265,49 @@ Blockly["Arduino"].finish = function (code) { "\n}\n"; let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n"; - - // Convert the definitions dictionary into a list. - code = - devVariables + - "\n" + - "#include " + - "\n" + - libraryCode + - "\n" + - variablesCode + - "\n" + - definitionsCode + - "\n" + - codeFunctions + - "\n" + - Blockly["Arduino"].variablesInitCode_ + - "\n" + - functionsCode + - "\n" + - setupCode + - "\n" + - loopCode; + // only add OTA code if tablet mode is enabled + if (ota === true) { + code = + devVariables + + "\n" + + "#include " + + "\n" + + libraryCode + + "\n" + + variablesCode + + "\n" + + definitionsCode + + "\n" + + codeFunctions + + "\n" + + Blockly["Arduino"].variablesInitCode_ + + "\n" + + functionsCode + + "\n" + + setupCode + + "\n" + + loopCode; + } else { + // Convert the definitions dictionary into a list. + code = + devVariables + + "\n" + + libraryCode + + "\n" + + variablesCode + + "\n" + + definitionsCode + + "\n" + + codeFunctions + + "\n" + + Blockly["Arduino"].variablesInitCode_ + + "\n" + + functionsCode + + "\n" + + setupCode + + "\n" + + loopCode; + } // Clean up temporary data. delete Blockly["Arduino"].definitions_;