Get and set persistant states

I am getting state using:

let state = global.get_persistent_state('n', 'align_windows_state');

    if (state === null) {
        state = 0;
    }

I am setting state using:

global.set_persistent_state('align_windows_state', new GLib.Variant.new_int16(state + 1));

however, state always return 0.

Why is this happening?

try {
    const v = new GLib.Variant.new_int16(0);
} catch (e) {
    // TypeError: GLib.Variant.new_int16 is not a constructor
    console.log(e.message);
}

Either use new GLib.Variant('n', 0) or GLib.Variant.new_int16(0).

2 Likes

For future reference, the code that is working:

let state = global.get_persistent_state('n', 'align_windows_state').get_int16();

if ( state === null ) {
    state = 0;
}

log(`state: ${state}`);

global.set_persistent_state('align_windows_state', GLib.Variant.new_int16(state+1));
2 Likes

@andyholmes Thank you very much.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.