kaorahi / lizgoban

Leela Zero & KataGo visualizer
GNU General Public License v3.0
169 stars 28 forks source link

Retain the last go board display mode selected by the user #97

Closed qcgm1978 closed 10 months ago

qcgm1978 commented 10 months ago

When the user clicks the chessboard display mode in the view menu, the application will remember the user’s selection and use that mode as the initial display mode the next time it starts. But it seems conflict to board_type in config.json, so I don't know whether it is necessary. It's up to board_type should be decided by config or user action:

const stored_keys_spec = [
    ...
    ['stone_style', '3D'],
    ['layout', 'double_boards'],
    ...
]
function board_type_menu_item(label, type, win) {
    return {
        label, type: 'radio', checked: window_prop(win).board_type === type,
        click: (this_item, win) => {
            set_board_type(type, win);
            // save current board type
            set_stored('layout', type);
            return update_all()
        }
    }
}
const store = new ELECTRON_STORE({ name: 'lizgoban' })
if (store.get('layout')) {
    const windowData = store.get('window.id0');
    windowData.board_type = store.get('layout');
    store.set('window.id0', windowData);
}
...
kaorahi commented 10 months ago

The last board_type is already saved (in ~/.config/LizGoban.json on linux) when you close the window. It will be used in the next session unless "board_type" is explicitly set in config.json. If you'd like to see how this is implemented, search for the word 'store' in window.js.

qcgm1978 commented 10 months ago

I understand that the data will be saved if I close the application, because the program triggers this operation when app.on('quit', () => { store_session(true); kill_all_leelaz() }). However, in the past, when I restarted the application in debug mode in vscode, the quit event was not triggered (it is said that this is because the application window remains open when restarting, so it is not considered to be a complete application exit, and the quit event will not be triggered).