Need help with JNA on Kotlin Multiplatform

Hi guys.

Im trying to set messaging between two instances of my kotlin desktop (windows) project.
The app is a music player and the idea is that once an instance of the app is already running, new instances will message that instance with file to play instead of opening new instances, then close them.

I tried using a local file to read and write but its not reliable enough, so now im trying to use JNA to send and receive messages between the two instances.

this is my function to listen and receive messages:

private fun setupMessagesListener(){ val user32 = User32.INSTANCE val messagePump = Thread { val msg = MSG() val window = user32.FindWindow(null, "MyAppName") User32.INSTANCE.PostMessage(window, WinUser.WM_USER, WinDef.WPARAM(0), WinDef.LPARAM(0)) while (user32.GetMessage(msg, window, 0, 0) > 0){ if (msg.message == WinUser.WM_COPYDATA){ val copyData = COPYDATASTRUCT(msg.pointer) val chars = copyData.lpData.getCharArray(0, copyData.cbData / 2) val filePath = String(chars) val file = File(filePath) if (file.exists()){ handleFileArgument(filePath) } } } user32.TranslateMessage(msg) user32.DispatchMessage(msg) } messagePump.start()} 

and this is the function to send messages:

private fun sendFilePathMessage(filePath: String){ val user32 = User32.INSTANCE val activeInstance = user32.FindWindow(null, "MyAppName") activeInstance?.let { val wideString = filePath.toCharArray() val size = (wideString.size * Char.SIZE_BYTES) + Char.SIZE_BYTES val buffer = Memory(size.toLong()) buffer.setWideString(0, filePath) val copyData = COPYDATASTRUCT().apply { dwData = ULONG_PTR(0) cbData = size lpData = buffer } val pointer = copyData.pointer copyData.write() user32.SendMessage(activeInstance, WinUser.WM_COPYDATA, null, WinDef.LPARAM(Pointer.nativeValue(pointer))) } } 

when i debug my listener function, it always stop at while condition and never gets inside the loop, nor it comes back.
when i try to evaluate
user32.GetMessage(msg, window, 0, 0)
the debugger never finishes its just stuck.

submitted by /u/iParki
[link] [comments]

Continue ReadingNeed help with JNA on Kotlin Multiplatform

How to launch app/activity from a library?

I have rudimentary Android knowledge and limited Kotlin knowledge

Trying to use startActivity says it requires Context, but I have no idea how to create or give a Context from a library that’s separate from an app

Edit: startActivity isn’t a make or break, its just where i got stuck. Any solution to using a library code base to launch an app is what im looking for

submitted by /u/DedicatedBathToaster
[link] [comments]

Continue ReadingHow to launch app/activity from a library?

Become a better Java developer: Learn Kotlin/ Ktor The 2nd tip for becoming a better Java developer is to learn Kotlin..lol ” Learn Kotlin: it might give you some interesting perspective (and the ability to shift jobs if the need arises, etc.).”

submitted by /u/observability_geek
[link] [comments]

Continue ReadingBecome a better Java developer: Learn Kotlin/ Ktor The 2nd tip for becoming a better Java developer is to learn Kotlin..lol ” Learn Kotlin: it might give you some interesting perspective (and the ability to shift jobs if the need arises, etc.).”

Ktor: SSLHandshake exception when trying to connect websocket with wss only in browsers

I have written a server code with KTOR & hosted it in AWS EC2 instance, it is working fine with android and desktop but our client wanted a web app so we developed it in KMP, compose multiplatform, everything was going great but as our webapps runs using HTTPS we have to use WSS so we followed the official docs to configure SSL using this link and while testing it in postman WSS sockets are also getting connected so we deployed it in our test server and tried it in chrome which resulted in this SSLHandshakeException

https://preview.redd.it/dlga2jtp140d1.png?width=2256&format=png&auto=webp&s=a4bab006ff1cf875170ec5bbafc859f900695d47

here is how we create a Keystore and application.conf is as follows

application.conf

ktor { deployment { port = 3456 port = ${?PORT} sslPort = 3457 sslPort = ${?SSL_PORT} } security { ssl { keyStore = keystore.jks keyAlias = sampleAlias keyStorePassword = 123456 privateKeyPassword = 123456 } } application { modules = [ my.Package.module ] } } 

to generate Keystore:

val keyStoreFile = File("build/libs/./keystore.jks") val keyStore = buildKeyStore { certificate("sampleAlias") { password = "123456" domains = listOf("127.0.0.1", "0.0.0.0", "localhost") } } keyStore.saveToFile(keyStoreFile, "123456") 

as I have already mentioned web sockets are working in postman but they are failing when testing in browsers, even in android & desktop we started using WSS instead of Websockets they are working fine so any solutions or any hints would be very very helpful

I have been trying to get a solution for this in stackoverflow too if I get any answer I will update it here

submitted by /u/trinadh_crazy
[link] [comments]

Continue ReadingKtor: SSLHandshake exception when trying to connect websocket with wss only in browsers

Which backend framework supporting Kotlin has the best job placement rate?

Im a mobile dev , and moving to backend world now. As a result, Which backend framework supporting Kotlin has the best job placement rate?

Additionally, which good courses for that backend framework? Because I see many courses out there which have outstanding reviews, but I can not pay all of courses :(.

Many thanks.

submitted by /u/Standard-Assistance4
[link] [comments]

Continue ReadingWhich backend framework supporting Kotlin has the best job placement rate?

Can’t figure out why Intent is being shown as an error

https://preview.redd.it/0lduvvozfzzc1.png?width=1125&format=png&auto=webp&s=9adb00685de87d54140377d2e582f759608d3e79

<html>None of the following functions can be called with the arguments supplied:<br/>public constructor Intent(packageContext: Context!, cls: Class&lt;*&gt;!) defined in android.content.Intent<br/>public constructor Intent(action: String!, uri: Uri!) defined in android.content.Intent

this is the error message im getting

submitted by /u/ZealousidealOwl1318
[link] [comments]

Continue ReadingCan’t figure out why Intent is being shown as an error

How do I run a Kotlin gradle project created in IntelliJ using the command line?

Considering the fact that I’ve found nothing on this from Googling I’m sure this is somehow a bad question but I’ve spent around 15 minutes looking everywhere lol

I’ve got a Kotlin project that uses gradle and have been working on it in IntelliJ but I’m looking toward moving it off IntelliJ onto my VPS and want to know how to run the project via command line before I do so.

Every time I try to just use the kotlin command to run the main function it says it couldn’t find the Main class. Are there special arguments I need to add or should I be somehow running it using the gradle daemon (and how would I do so)?

submitted by /u/Add1ctedToGames
[link] [comments]

Continue ReadingHow do I run a Kotlin gradle project created in IntelliJ using the command line?

How can I store and retrieve an AnnotatedString with formatting from Firebase Firestore?

I’m currently storing and retrieving an `AnnotatedString` with formatting from Firebase. However, my current approach saves the string, but upon retrieval, I receive a JSON string. I’m unsure how to convert this string back into a formatted `AnnotatedString`. Can someone assist me with this? Alternatively, is there a simpler method to achieve this?

override suspend fun createNote(createNote: CreateNote): Flow<Result<Boolean>> { return flow { try { val documentReference = firestore.collection("notes").document() val jsonText = Gson().toJson(createNote.text) val noteMap = hashMapOf( "text" to jsonText, "title" to createNote.title, "link" to createNote.link, "image" to createNote.image, "userID" to firebaseAuth.currentUser?.uid, "date" to createNote.date, ) documentReference.set(noteMap).await() emit(Result.Success(true)) } catch (e: Exception) { val errorMessage = when (e) { is FirebaseFirestoreException -> e.localizedMessage ?: "Unknown Firebase Auth Error" else -> e.localizedMessage ?: "Unknown Error" } emit(Result.Error(errorMessage)) } } } 

submitted by /u/dumb_bot281
[link] [comments]

Continue ReadingHow can I store and retrieve an AnnotatedString with formatting from Firebase Firestore?

Server side rendering with Kotlin react?

I’m working on an LLM chat application that makes it easy to share and learn about data. If you’re curious you check it out here. It works similar to chat gpt in that it gives users a chat interface. Where I’m hoping to differentiate is

  1. Data ingestion, making it easy to ingest large amounts of data from various sources into what I call “collections”

  2. The sharing side of things. Make it easy to put your chat on the public internet so other people can interact with your data. I know Chatgpt has a share feature but this would take a things a step further and enable others to pick up where you left off and further ask questions about your collection. In addition I want to make it so these chats are indexed by Google so that they appear when people search relevant keywords.

That brings me to my question. I’ve built this app using Kotlin react and am now trying to think of how I can render a chat server side. The goal would be to create a static version of the page with the relevant content already in place so it can be indexed by Google. I know with JavaScript this is what nextjs is for but I don’t know how to accomplish this with Kotlin.

Also the goal of server side rendering is seo. If there’s another way of accomplishing the same thing please lmk!

submitted by /u/spline_reticulator
[link] [comments]

Continue ReadingServer side rendering with Kotlin react?

End of content

No more pages to load