gabrielbull / react-desktop

React UI Components for macOS High Sierra and Windows 10
http://reactdesktop.js.org
MIT License
9.52k stars 462 forks source link

[Windows] Checkbox, defaultChecked issue? #90

Open codekidX opened 7 years ago

codekidX commented 7 years ago

Hi, I have successfully integrated other components into my electron app and it's working great, Thank you.

I think there is some issue with defaultChecked property of checkbox in Windows. Is it of type string ? as mentioned in docs

I checked the source, it checks if value and type is strictly boolean.

I'm totally new to react and electron development, if you could help me with issue it'd be great. Here is my full code: (Do read the comment below console.log(autostartBool);)

import React from 'react';
import styled from 'styled-components';
import { Checkbox } from 'react-desktop/windows';
// electron variables
const settings = require('electron-settings');

const PREF_BOOT = 'boot';

// Preferences
var autostartBool = false;

function checkIfPrefsAreInitialized() {
  if(!settings.has(PREF_BOOT)) {
    settings.set(PREF_BOOT, autostartBool);
  }
}

class Settings extends React.Component {

constructor(props) {
    super(props);

    // ====== PREF =============
    // At start (first time ever) if user will not have these prefs so ..
    // JUST SET IT !!
    checkIfPrefsAreInitialized();

    autostartBool= settings.get(PREF_BOOT);

    console.log(autostartBool); 
    // For some reason it prints "I got checked!" 
    // which is the defaultValue of Checkbox BUT the checkbox is not checked by default

}

  render() {
    return (
                 <Checkbox
        color={this.props.color}
        theme={this.props.theme}
        label="Automatically start Linkcue on boot"
        onChange={(e) => {
            settings.set(PREF_BOOT, e.target.value)
        }}
        defaultValue="I got checked!"
        defaultChecked={autostartBool}
      />
    );
  }
}

export default Settings;
gabrielbull commented 7 years ago

Please submit a PR and we will accept it.