Cleanup settings-web (#280)

This commit is contained in:
Alaric von Teplitz
2019-09-09 04:47:18 -07:00
committed by Bartosz Sosnowski
parent 5f5402aa0a
commit ffa1b1e6a3
10 changed files with 35 additions and 64 deletions

View File

@@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script>
window.output_from_webview = function(arg) {
if (typeof (window.external) !== 'undefined' && ('notify' in window.external)) {
window.external.notify(arg);
}
}
function receive_from_settings_app(arg) {
window.react_app_component.receive_config_msg(JSON.parse(arg));
return "";
}
function exit_settings_app() {
window.react_app_component.receive_exit_request();
return "";
}
</script>
<title>PowerToys Settings</title>
</head>
<body>
<div id="app"></div>
<script src="dist/bundle.js" charset="UTF-8"></script>
</body>
</html>

View File

@@ -2,21 +2,21 @@
<html>
<head>
<script>
window.output_from_webview = function(arg) {
if (typeof (window.external) !== 'undefined' && ('notify' in window.external)) {
window.external.notify(arg);
}
window.output_from_webview = function(arg) {
if (typeof (window.external) !== 'undefined' && ('notify' in window.external)) {
window.external.notify(arg);
}
function receive_from_settings_app(arg) {
window.react_app_component.receive_config_msg(JSON.parse(arg));
return "";
}
function exit_settings_app() {
window.react_app_component.receive_exit_request();
return "";
}
</script>
<title>PowerToys Settings</title>
}
function receive_from_settings_app(arg) {
window.react_app_component.receive_config_msg(JSON.parse(arg));
return '';
}
function exit_settings_app() {
window.react_app_component.receive_exit_request();
return '';
}
</script>
<title>PowerToys Settings</title>
</head>
<body>
<div id="app"></div>

View File

@@ -10,4 +10,3 @@ export class BaseSettingsControl extends React.Component <any, any> {
return null;
}
}

View File

@@ -17,7 +17,6 @@ export class BoolToggleSettingsControl extends BaseSettingsControl {
this.setState({ property_values: props.setting })
}
public get_value() : any {
return {value: this.toggleref.checked};
}
@@ -26,9 +25,9 @@ export class BoolToggleSettingsControl extends BaseSettingsControl {
return (
<Toggle
onChange={
(_event,_check) => {
(_event,_check) => {
this.setState( (prev_state:any) => ({
property_values: {
property_values: {
...(prev_state.property_values),
value: _check
}
@@ -45,5 +44,4 @@ export class BoolToggleSettingsControl extends BaseSettingsControl {
/>
);
}
}
}

View File

@@ -41,5 +41,4 @@ export class ColorPickerSettingsControl extends BaseSettingsControl {
</Stack>
);
}
}
}

View File

@@ -19,12 +19,13 @@ export class CustomSettingsScreen extends React.Component <any, any> {
powertoy: props.powertoy,
}
}
shouldComponentUpdate(nextProps:any, nextState:any)
{
shouldComponentUpdate(nextProps:any, nextState:any) {
// This component and its children manage their state.
// React only to state changes when forceUpdate is called by the App component.
return false;
}
componentWillReceiveProps(props: any) {
this.setState({ powertoy: props.powertoy })
}
@@ -99,7 +100,7 @@ export class CustomSettingsScreen extends React.Component <any, any> {
(power_toys_properties[b].order || 0)
)
}).
map( (key) => {
map((key) => {
switch(power_toys_properties[key].editor_type) {
case 'bool_toggle':
return <BoolToggleSettingsControl

View File

@@ -17,12 +17,13 @@ export class GeneralSettings extends React.Component <any, any> {
settings: props.settings,
}
}
shouldComponentUpdate(nextProps:any, nextState:any)
{
shouldComponentUpdate(nextProps:any, nextState:any) {
// This component and its children manage their state.
// React only to state changes when forceUpdate is called by the App component.
return false;
}
componentWillReceiveProps(props: any) {
this.setState({ settings: props.settings })
}

View File

@@ -47,7 +47,7 @@ export class IntSpinnerSettingsControl extends BaseSettingsControl {
value=String(this.spinbuttonref.props.max);
}
this.setState( (prev_state:any) => ({
property_values: {
property_values: {
...(prev_state.property_values),
value: parseInt(value)
}
@@ -62,7 +62,7 @@ export class IntSpinnerSettingsControl extends BaseSettingsControl {
value = String(+value + this.spinbuttonref.props.step) ;
}
this.setState( (prev_state:any) => ({
property_values: {
property_values: {
...(prev_state.property_values),
value: parseInt(value)
}
@@ -77,7 +77,7 @@ export class IntSpinnerSettingsControl extends BaseSettingsControl {
value = String(+value - this.spinbuttonref.props.step) ;
}
this.setState( (prev_state:any) => ({
property_values: {
property_values: {
...(prev_state.property_values),
value: parseInt(value)
}
@@ -95,5 +95,4 @@ export class IntSpinnerSettingsControl extends BaseSettingsControl {
/>
);
}
}
}

View File

@@ -12,7 +12,7 @@ export class StringTextSettingsControl extends BaseSettingsControl {
property_values: props.setting
}
}
componentWillReceiveProps(props: any) {
// Fully controlled component.
// Reacting to a property change so that the control is redrawn properly.
@@ -48,4 +48,4 @@ export class StringTextSettingsControl extends BaseSettingsControl {
/>
);
}
}
}

View File

@@ -16,14 +16,13 @@ mergeStyles({
const root = document.getElementById('app');
if (root && root.hasChildNodes()) {
ReactDOM.hydrate(<App
ReactDOM.hydrate(<App
ref={(app_component) => {(window as any).react_app_component=app_component;}} // in order to call the app from outside react.
/>,
/>,
root);
} else {
ReactDOM.render(<App
ReactDOM.render(<App
ref={(app_component) => {(window as any).react_app_component=app_component;}} // in order to call the app from outside react.
/>,
/>,
root);
}