Serialization problem in electron js

193 views
Skip to first unread message

Ebru İnanlı

unread,
Jun 8, 2022, 6:55:57 AM6/8/22
to blo...@googlegroups.com
I want to develop a desktop application in electron using the Blockly library. But I'm having a problem with saving blocks and opening saved blocks. I looked everywhere but couldn't find the solution. I created my blocks with json and used 'Serialization' but I get an error like this:
image.png

My codes are like this:


I handled the saving process in index.html within the script. I saved the blocks to localstorage. This place works fine.
image.png

the problem is here(index.js) - for electronjs:
image.png
image.png

it works right here too:
image.png

Beka Westberg

unread,
Jun 13, 2022, 12:21:15 PM6/13/22
to Blockly
Hello!

Where you call `Blockly.workspaces.load` could you add a `console.log(Blockly.getMainWorkspace())` to make sure that it is defined before the code attempts to load blocks into it?

Based on what you provided, it looks like you're calling the correct functions, so `Blockly.getMainWorkspace()` being undefined is the only explanation I could think of =)

Best wishes,
--Beka

Ebru İnanlı

unread,
Jun 22, 2022, 10:28:19 AM6/22/22
to Blockly
I saw your reply late. I am sorry.

Yes, when I write the code `console.log(Blockly.getMainWorkspace())` I get the answer 'undefined'.

I solved my problem using localstorage, but it's making my job a little longer and tiring the program. If I can use the Blockly library on Electron's home page index.js, everything will be more comfortable :)

My English is not very good. Maybe I can't explain my problem easily. Thanks for your interest anyway.

13 Haziran 2022 Pazartesi tarihinde saat 19:21:15 UTC+3 itibarıyla bwes...@google.com şunları yazdı:

Maribeth Bottorff

unread,
Jun 22, 2022, 8:04:17 PM6/22/22
to Blockly
The problem is that the workspace you are trying to load blocks into is undefined. Do you know why that might be? Has Blockly already been injected at the time you are trying to call this? If not, then there is no workspace to load the blocks into. If so, then we need more information to find out why there is no mainWorkspace. If you provide additional code snippets, maybe around where you are injecting Blockly and when you are trying to load the blocks, that would help.

Maribeth

Ebru İnanlı

unread,
Jun 23, 2022, 12:18:58 PM6/23/22
to Blockly
I injected Blockly index.html page. But I can't reach it in index.js.
Ekran Alıntısı.PNGI injected it in Blockly index.html page.
23 Haziran 2022 Perşembe tarihinde saat 03:04:17 UTC+3 itibarıyla Maribeth Bottorff şunları yazdı:

Maribeth Bottorff

unread,
Jun 23, 2022, 5:22:59 PM6/23/22
to Blockly
I'm not sure why that wouldn't work and why Blockly.mainWorkspace would be undefined from index.js but it's hard to say without seeing the rest of your code. Are you sure index.js is being run *after* the injection here?

What if you moved this injection call to index.js and then tried to serialize directly into this workspace instead of using Blockly.mainworkspace?

Ebru İnanlı

unread,
Jun 24, 2022, 5:29:22 AM6/24/22
to blo...@googlegroups.com
I think the problem is caused by electronjs. But as you said, probably 'index.js' is running before injection. Since the main settings of Electron.js are made in index.js, it works first and therefore cannot see the workspace. I will try to move the serialization to "index.js" file. I even thought of other ideas. I'll post the results after I try. Thank you for your ideas.

24 Haz 2022 Cum 00:23 tarihinde 'Maribeth Bottorff' via Blockly <blo...@googlegroups.com> şunu yazdı:
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/IgUgad3vk1k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/c229e8ee-6936-4497-99ab-9a9828a92805n%40googlegroups.com.

Noah May

unread,
Jun 24, 2022, 11:58:11 PM6/24/22
to Blockly
I've not used Electron.js myself, but looking at the documentation, you might need to wait for the app to fully load the HTML page: https://www.electronjs.org/docs/latest/api/browser-window#winloadurlurl-options

browserWindow.loadURL("index.html").then(() => console.log(Blockly.getMainWorkspace()))

or with a global-level await

await win.loadURL("index.html")
console.log(Blockly.getMainWorkspace())
Reply all
Reply to author
Forward
0 new messages