Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localstorage was cleared, when i restart my sketch #78

Open
zobor opened this issue Dec 6, 2018 · 7 comments
Open

localstorage was cleared, when i restart my sketch #78

zobor opened this issue Dec 6, 2018 · 7 comments

Comments

@zobor
Copy link

zobor commented Dec 6, 2018

Any help would be appreciated! Thanks

@happylinks
Copy link

Same. What I did to "solve" it, is persist it to the sketch plugin settings.
https://developer.sketchapp.com/reference/api/#set-a-plugin-setting

In the sketch "backend" code I used:

 const storedActiveProjectID = sketch.Settings.settingForKey(
        'storedActiveProjectID'
      );
      if (storedActiveProjectID) {
        browserWindow.webContents.executeJavaScript(
          `localStorage.setItem('storedActiveProjectID', "${storedActiveProjectID}")`
        );
      }

And in the frontend I used a pluginCall to pass it to the backend on change.

Not the greatest solution, but maybe it helps you!

@mathieudutour
Copy link
Member

Yeah I don’t think there is another solution. That’s also what I’m doing in the Sketch DevTools.

What we could do perhaps is automate this by monkey-patching localStorage automatically so that when you can localStorage, it would actually call the plugin’s “backend”

@happylinks
Copy link

That would be nice! Maybe with a special prefix so it’ll never conflict.

@mathieudutour
Copy link
Member

Yes exactly. Do you want to have a go at it? There is already an example of monkey patching window.postMessage, it should probably be similar

@happylinks
Copy link

Sure, I can probably have a go at it this weekend or next week👌

@mathieudutour
Copy link
Member

Perfect! Give me a shout if you need something

@zobor
Copy link
Author

zobor commented Dec 10, 2018

Same. What I did to "solve" it, is persist it to the sketch plugin settings.
https://developer.sketchapp.com/reference/api/#set-a-plugin-setting

In the sketch "backend" code I used:

 const storedActiveProjectID = sketch.Settings.settingForKey(
        'storedActiveProjectID'
      );
      if (storedActiveProjectID) {
        browserWindow.webContents.executeJavaScript(
          `localStorage.setItem('storedActiveProjectID', "${storedActiveProjectID}")`
        );
      }

And in the frontend I used a pluginCall to pass it to the backend on change.

Not the greatest solution, but maybe it helps you!

thanks, although it can't solve all the problems, but helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants