[GH-ISSUE #85] Window closing itself and quitting app #53

Closed
opened 2026-05-05 11:32:50 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @mischnic on GitHub (Apr 27, 2018).
Original GitHub issue: https://github.com/kusti8/proton-native/issues/85

How can I close a window and quit the whole app programatically?

class Notepad extends Component {
  state = { running: true, text: 'Enter here!' };

  render() {
    return (
        <App>
          {this.state.running && <Window
            title="Notes"
            size={{ w: 500, h: 500 }}
          >
            <Box>
              <TextInput
                onChange={text => this.setState({ text })}
              >
                {this.state.text}
              </TextInput>
              <Button onClick={()=>this.setState({running: false})}>Test</Button>
            </Box>
          </Window>}
        </App>
    );
  }
}

Should this work? On macOS only the Window is closed (even though lastWindow is true by default).


Apart from that, a method to quit the app (similar to the current dialog functions) would make sense. (Why is it Dialog and not dialog?)

Originally created by @mischnic on GitHub (Apr 27, 2018). Original GitHub issue: https://github.com/kusti8/proton-native/issues/85 How can I close a window and quit the whole app programatically? ```jsx class Notepad extends Component { state = { running: true, text: 'Enter here!' }; render() { return ( <App> {this.state.running && <Window title="Notes" size={{ w: 500, h: 500 }} > <Box> <TextInput onChange={text => this.setState({ text })} > {this.state.text} </TextInput> <Button onClick={()=>this.setState({running: false})}>Test</Button> </Box> </Window>} </App> ); } } ``` Should this work? On macOS only the Window is closed (even though `lastWindow` is true by default). --- Apart from that, a method to quit the app (similar to the current dialog functions) would make sense. (Why is it `Dialog` and not `dialog`?)
Author
Owner

@kusti8 commented on GitHub (May 2, 2018):

You need to use the closed prop.

class Example extends Component {
  state = { running: true, text: 'Enter here!' };

  render() {
    return (
        <App>
          <Window
            title="Notes"
            size={{ w: 500, h: 500 }}
            closed={!this.state.running}
          >
            <Box>
              <TextInput
                onChange={text => this.setState({ text })}
              >
                {this.state.text}
              </TextInput>
              <Button onClick={()=>this.setState({running: false})}>Test</Button>
            </Box>
          </Window>
        </App>
    );
  }
}

I made it a prop instead of a method because if you want to use multiple windows, it gets really ugly to try and track what window you're using (which is how I did it for dialog since it doesn't matter too much what the origin window is). I pushed a fix to make this correctly quit.

<!-- gh-comment-id:386156509 --> @kusti8 commented on GitHub (May 2, 2018): You need to use the closed prop. ``` jsx class Example extends Component { state = { running: true, text: 'Enter here!' }; render() { return ( <App> <Window title="Notes" size={{ w: 500, h: 500 }} closed={!this.state.running} > <Box> <TextInput onChange={text => this.setState({ text })} > {this.state.text} </TextInput> <Button onClick={()=>this.setState({running: false})}>Test</Button> </Box> </Window> </App> ); } } ``` I made it a prop instead of a method because if you want to use multiple windows, it gets really ugly to try and track what window you're using (which is how I did it for dialog since it doesn't matter too much what the origin window is). I pushed a fix to make this correctly quit.
Author
Owner

@mischnic commented on GitHub (May 16, 2018):

It would make sense, however, if <Window closed={true}> wouldn't actually show that window.

<!-- gh-comment-id:389659478 --> @mischnic commented on GitHub (May 16, 2018): It would make sense, however, if `<Window closed={true}>` wouldn't actually show that window.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/proton-native#53
No description provided.