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

BrowserWindow.getAllWindows() won't work #2262

Open
tokuhirom opened this issue May 30, 2024 · 2 comments
Open

BrowserWindow.getAllWindows() won't work #2262

tokuhirom opened this issue May 30, 2024 · 2 comments
Assignees

Comments

@tokuhirom
Copy link

in kotlin-electron, following code won't work.

import electron.core.BrowserWindow

fun main() {
    BrowserWindow.getAllWindows()
}
./gradlew jsRun
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

> Task :kotlinNpmInstall
(node:66351) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
warning workspace-aggregator-3a59d6ae-e958-456f-a59b-4d43e363c8fc > main-test > mocha > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-3a59d6ae-e958-456f-a59b-4d43e363c8fc > main-test > mocha > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning Ignored scripts due to flag.

> Task :jsNodeDevelopmentRun FAILED
Error: Cannot find package 'INTERNAL_ENTITY' imported from /Users/tokuhirom/work/kotlin-electron-getAllWindows-issue/build/js/packages/main/kotlin/main.mjs
    at packageResolve (node:internal/modules/esm/resolve:845:9)
    at moduleResolve (node:internal/modules/esm/resolve:918:18)
    at defaultResolve (node:internal/modules/esm/resolve:1148:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:528:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:497:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:231:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:97:39)
    at link (node:internal/modules/esm/module_job:96:36)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jsNodeDevelopmentRun'.
> Process 'command '/Users/tokuhirom/.gradle/nodejs/node-v22.0.0-darwin-arm64/bin/node'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 16s
14 actionable tasks: 14 executed

with electron.BrowserWindow, i got other compilation error.

import electron.BrowserWindow

fun main() {
    BrowserWindow.getAllWindows()
}
./gradlew jsRun

> Task :compileKotlinJs FAILED
e: file:///Users/tokuhirom/work/kotlin-electron-getAllWindows-issue/src/jsMain/kotlin/Main.kt:4:19 Unresolved reference 'getAllWindows'.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlinJs'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 753ms
2 actionable tasks: 1 executed, 1 up-to-date

The API is used in the Electron's official tutorial.
https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app

Is there any solution?

Here's a code I tested:
https://github.com/tokuhirom/kotlin-electron-getAllWindows-issu

@sgrishchenko
Copy link
Collaborator

Yea, I see the problem, static members of electron.core.BrowserWindow was not copied to electron.BrowserWindow. I will try to fix it soon. As fast workaround I propose you to use something like this:

electron.BrowserWindow::class.js.asDynamic().getAllWindows()

Be careful, because entities from electron.core package are not exits. They are virtual and declared only for code reusage between other packages.

@tokuhirom
Copy link
Author

thanks, i'll try the workaround.

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

No branches or pull requests

2 participants