flutter_i18n icon indicating copy to clipboard operation
flutter_i18n copied to clipboard

Exception: Write access is allowed from event dispatch thread only

Open hacker-cb opened this issue 5 years ago • 14 comments

There is Exception in 1.1.1.192:

Write access is allowed from event dispatch thread only

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@4499352e
Current thread: Thread[Timer-3,6,Idea Thread Group] 1535808483
SystemEventQueueThread: Thread[AWT-EventQueue-0 2019.2.3#IU-192.6817.14 IDEA, eap:false, os:Mac OS X 10.14.6, java-version:JetBrains s.r.o 11.0.4+10-b304.69 2019.2.3#IU-192.6817.14 IDEA, eap:false, os:Mac OS X 10.14.6, java-version:JetBrains s.r.o 11.0.4+10-b304.69,6,Idea Thread Group] 1266730927
	at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1068)
	at com.intellij.openapi.application.impl.ApplicationImpl.startWrite(ApplicationImpl.java:1150)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:992)
	at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:51)
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:67)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:74)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:922)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:150)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)

hacker-cb avatar Sep 30 '19 19:09 hacker-cb

I'm using IDEA with multi module layout and seems that plugin tries to create res/values folder in the root project and after fails with Exception.

My root project does not has pubspec.yaml file.

Folder structure:

./ - main project - NO pubspec.yaml
app - flutter app
packages/my_package_1 - dart package

Each folder added to IDEA as separate module.

hacker-cb avatar Sep 30 '19 19:09 hacker-cb

Plugin v1.1.2 has been published to JetBrains, awaiting approval. Could you install and check it and report back if the error still persists?

noordawod avatar Oct 02 '19 07:10 noordawod

Thank you. I will check as soon as it will be approved by Jetbrains.

What about plugin behavior with such directory structure, where root directory does not contains any flutter or dart project but plugin still tries to create res/values folder in it?

hacker-cb avatar Oct 02 '19 08:10 hacker-cb

This is yet unsupported, but I think I will add an option to select both the name of the generated folder and also where to find Arb files. Then you can easily point the plugin to the right directories.

noordawod avatar Oct 02 '19 08:10 noordawod

I think that It will be better if plugin will detect generated folder name relative to the pubspec.yaml.

hacker-cb avatar Oct 02 '19 08:10 hacker-cb

Yeah, by default it will follow where the pubspec file is located -- but it may be specified by the user as well (when this is implemented).

noordawod avatar Oct 02 '19 10:10 noordawod

Yeah, by default it will follow where the pubspec file is located

Is it current behavior or future behavior? In my project structure there is NO pubspec.yaml file in the root folder, but plugin still creates res/values folder in the root.

hacker-cb avatar Oct 02 '19 10:10 hacker-cb

Yeah, I understand that.

However, for the plugin to configure itself, it will try to load the pubspec.yaml file from the project's root folder, even if it just contains the following:

flutter_i18n:
  enable-flutter-i18n: false

Do you have a better idea on how the plugin can be configured otherwise? (without showing a dialog or a settings box.)

noordawod avatar Oct 02 '19 10:10 noordawod

In pseudo-code logic should be like this:

foreach (pubspec_file in ...){
   if (has(dependencies.flutter) && (has(dependencies.flutter_localizations))){
     plugin_enabled = true
   } else {
     plugin_enabled = false
   }
   if (has(flutter_i18n.enable-flutter-i18n)){
   	 plugin_enabled=${flutter_i18n.enable-flutter-i18n}
   }
   res_values_folder=dirname(pubspec_file)+'/res/values'
   src_folder=dirname(pubspec_file)+'/lib'
}

Don't forget that IDEA can have multi-module project.

hacker-cb avatar Oct 02 '19 11:10 hacker-cb

Multi-module is not yet supported, unsure what's the best approach right now. About the pseudo-code: that's how it works now ;)

noordawod avatar Oct 02 '19 12:10 noordawod

So, what about multi-module project support? Actually, in my case I moved flutter app to the app dir of the root project and plugin does not work :(

hacker-cb avatar Oct 02 '19 12:10 hacker-cb

As expected. Plugin searches for pubspec.yaml in the root folder only.

noordawod avatar Oct 02 '19 14:10 noordawod

Do you have any plans to add subfolder/submodule support?

hacker-cb avatar Oct 02 '19 17:10 hacker-cb

Multi-module is not yet supported, unsure what's the best approach right now. If you have an idea on how this can be accomplished, please share.

noordawod avatar Oct 02 '19 17:10 noordawod