Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / [SOLVED] Html5 Clipboard and File access

Author
Message
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 2nd Aug 2022 17:03 Edited at: 8th Oct 2022 15:30
This post has been marked by the post author as the answer.
Here is a demo of some of the things you can do with an Html5 build https://godling.itch.io/sv?secret=AGKForum including writing to the clipboard, downloading text, image, or other binary files, reading text, image or other binary files and getting the url including passed parameters of your app. This patch also includes localStorage access. You can find the source for the demo here https://github.com/charlesgriffiths/agk-modules/tree/main/other/SV

These functions are made possible by patching AGKPlayer.js after exporting your app to Html5 but before renaming the entry to index.html and packaging in a zip file. Nobody wants to patch that file by hand, so I wrote a simple patcher. https://godling.itch.io/agkplayer-patcher?secret=AGKForum If you ever want to write your own, or just prefer patching your app with code you control (who could blame you), here is the source and the patch.txt attached to this post is the source for the SetPatchString() function in the patcher. The patcher will read either minified or unminified AGKPlayer.js, apply the patch, and immediately download the new version. You can run the patcher as a windows app and it will read and write files in its usual media folder.




Examples in SV.agc include reading and writing images in .png, .jpg, and a raw format as produced by CreateMemblockFromImage(). Reading from the clipboard requires permission, and I'm no javascript expert but my reading is that there's no way to request permission and if your app runs in an iframe that the iframe must explicitly grant your app permission to paste from the clipboard. I've included a clipboard paste function that will probably work if your app has permission, but as with all of this there are no guarantees.

As noted in the demo source, getNoiseImage() and the functions it calls are from https://forum.thegamecreators.com/thread/228529#msg2670935. Thanks to VirtualNomad and Mike/Orvillian for providing this example and allowing it to be included here.


Edited August 7, 2022 to include fullscreen and detect last key functions
SaveSharedVariable( "_fullscreen", "" ) will make your html5 app go fullscreen, even with a studio build
LoadSharedVariable( "_kbkeydown", "" ) will return a string version of the last key pressed if a key was pressed since the last time this function was called so there's a way to distinguish between numpad and arrow keys

Update October 8, 2022
Trying to open a file picker while in full screen mode causes problems.
The size of an image that can be read or written is quite limited, so exercise caution.

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 2nd Aug 2022 17:35
very nice, Prime and thanks for sharing.

looking forward to adding some export customization/automation with your work.
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 2nd Aug 2022 20:26 Edited at: 2nd Aug 2022 20:30
A new version.




If third party cookies are disabled in the browser and your app is running in an iframe (as is the case on itch) then access to Web Storage is denied. I was storing temporary data in sessionStorage (only lasts for the session) but now I store the same data in a global variable called "storage". Added a call to read from a shared variable called "_init" to initialize the storage variable and return a message if access to localStorage is not allowed.

Attachments

Login to view attachments
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 4th Aug 2022 16:30
Responding to popular demand, see the demo for a fullscreen button (agk studio html5 export). Latest patch attached also includes the SameSite=None; Secure change to allow cookie changes, but you should be able to use localStorage instead.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-19 23:10:03
Your offset time is: 2024-04-19 23:10:03