puter icon indicating copy to clipboard operation
puter copied to clipboard

Custom file templates

Open Zac0511 opened this issue 1 year ago β€’ 1 comments

By default, when you right-click in file explorer, then click new, you only have folder, but for files you have text file, HTML file and JPEG image (i suppose this one is here for... drawing ?). It should be like on Linux, where the home directory contains a Templates folder, and any file you put in it will show up in the new file menu. This would allow to easily create other files, like JS files, or any ! And because its templates, you could put thing inside a template file, like the default "bug report" thing on this GitHub, and just create a filled file from a right-click ! AND, apps could even set a custom adanced templates, that opens the app and starts it in the folder you were, with a new file with the name you chosen ! This would be perfect for files that are not readable by an human (like the JPEG image), and could instead open it with the appropriate app to allow editing !

Zac0511 avatar May 25 '24 18:05 Zac0511

This is a good idea. It's also good for a start issue.

jelveh avatar May 26 '24 02:05 jelveh

I would like to work on this issue @jelveh.

Koppeks avatar Jul 17 '24 02:07 Koppeks

Great! Assigned πŸ˜‡

Let me know if you need help with anything.

jelveh avatar Jul 17 '24 02:07 jelveh

Well indeed I would need some guidance to get the project up and running on my machine.

Koppeks avatar Jul 17 '24 02:07 Koppeks

Could you give this a try and let me know if it doesn't work? https://github.com/HeyPuter/puter?tab=readme-ov-file#-local-development

jelveh avatar Jul 17 '24 02:07 jelveh

@jelveh I am able to run npm install and have all the packages but when I enter the command npm start The console does this:

[INFO::__dev-watcher] (10.578s) [puter.js:webpack-watch:out]
[INFO::__dev-watcher] (10.579s) [puter.js:webpack-watch:out] webpack 5.93.0 compiled with 1 warning in 2150 ms [TICK::server-health] (10.872s) service checks [TICK::server-health] (30.884s) service checks [TICK::app-info] (31.389s) refresh app cache [TICK::refresh_apps_cache] (46.417s) refresh associations cache [TICK::server-health] (50.898s) service checks ... [TICK::server-health] (291.089s) service checks

And keeps going for ever without starting the project

Koppeks avatar Jul 17 '24 04:07 Koppeks

Are you using Windows? We're having some issues with Windows as non of the maintainers use Windows. I'd like to solve this though, let me loop in @KernelDeimos

jelveh avatar Jul 17 '24 04:07 jelveh

Yes i am indeed using windows. Well let me know if I can be of any help solving this too.

Koppeks avatar Jul 17 '24 04:07 Koppeks

If you find the issue/solution before we do please submit a PR. We're going to be discussing this issue more here as well ✌️

jelveh avatar Jul 17 '24 04:07 jelveh

@Koppeks

And keeps going for ever without starting the project

The repetition of "service checks" and cache message is typical of a post-boot state. Try https://localhost:4100 - is it working? If not, check for alarms, which are sticky at the bottom of the console output.

Edit: If you can post a screenshot of the backend console that might help

KernelDeimos avatar Jul 17 '24 16:07 KernelDeimos

@KernelDeimos

After the command npm start this is the sequence I get

This [INFO::__dev-watcher] throws some of the first errors Captura de pantalla 2024-07-17 152427

More [INFO::__dev-watcher] errors Captura de pantalla 2024-07-17 153330

The project runs, but the https://localhost:4100 just prints a white screen and the api request all return 304 on the first get /? and 404 on the rest of the requests. Captura de pantalla 2024-07-17 152356

This is the screenshot of the sticky dev console Captura de pantalla 2024-07-17 152314 No alarms to be seen

Koppeks avatar Jul 17 '24 18:07 Koppeks

Thanks for the screenshots! We're working on a fix right now. Should have a patch very soon ✌️

jelveh avatar Jul 17 '24 18:07 jelveh

The [INFO::__dev-watcher] logs are known to be a bit misleading right now. When the log is prefixed "err" it really means "came from the stderr stream". I plan to fix this.

Most of the issues so far are because we get C:\'s everywhere because node:path is "helping" (i.e. we're using it wrong in several places).

KernelDeimos avatar Jul 17 '24 19:07 KernelDeimos

I think I fixed everything with this commit (had to commit on nj's spare laptop, it's the only Windows we have here)

@Koppeks see if it runs properly now. Also, let me know if you end up with a directory called C:\var\puter (ideally you won't but /var/puter kind of just keeps happening)

KernelDeimos avatar Jul 17 '24 20:07 KernelDeimos

Amazing @KernelDeimos now it works like a charm! Now Puter for developers is up and running for windows too. And yes there are multiple files been created at C:\var\puter

image

Koppeks avatar Jul 17 '24 21:07 Koppeks

Good to know. If you set the environment variable NO_VAR_RUNTIME=1 Puter will use the database in volatile/runtime of the puter repository. Otherwise it will use C:\var\puter (or /var/puter on other OSes). I currently have no idea how or why the var alternative gets created automatically - I didn't actually write any code to have it do that... so it's quite a mystery. It's meant to be for production installations and Docker instances.

KernelDeimos avatar Jul 17 '24 21:07 KernelDeimos

Feel free to report back about anything that's under-documented btw. I also plan to start recording more videos soon so that would also help me come up with good topics to cover.

KernelDeimos avatar Jul 17 '24 21:07 KernelDeimos

Feel free to report back about anything that's under-documented btw.

Will do, I will start with the issue now.

Koppeks avatar Jul 17 '24 22:07 Koppeks

I have started the issue yesterday and encounter some problems.

I have found that I need to use puter.fs.readdir() to manage folder and files, and all are async functions. In my case I should use the puter.fs.readdir() to search the template file of the user, but the UIContextMenu() and new_context_menu_item.js are not asynchronous functions.

Should I change the behavior of the functions to handle async await? Or there are other ways to search for directories I didn't see?

Sorry if this is a beginner question guys :smiling_face_with_tear:

Koppeks avatar Jul 19 '24 02:07 Koppeks

Valid question. Here's one way to do it: every time the desktop is loaded you use puter.fs.readdir() to list template files and you put them in a global variable called window.file_templates and when the context menu is loaded you populate the New submenu with the values inside window.file_templates.

window.file_templates need to also be updated every time there is a change made to the templates directory's contents. For example, when a new file is added there or a file has been edited. But you could start with the previous paragraph and work your way to the more advanced stuff such as this paragraph.

Let me know if this helps.

jelveh avatar Jul 19 '24 03:07 jelveh

The feature now its almost done, on service start I save all the custom template files and then on new_context_menu_item show them to the user.

I have encounter the following issues: Dev Console warning alert Captura desde 2024-07-19 18-14-46

Also I cannot save any file at any place GrabaciΓ³n de pantalla desde 2024-07-19 18-16-55.webm

And just in case I am on Ubuntu 24.04 lts now, I know you guys fix windows for me to work on this issue, but I wanted to try Ubuntu :laughing: I don't know if the issues are related to Ubuntu now.

Koppeks avatar Jul 19 '24 21:07 Koppeks

This is coming along nicely! I'm going to look into the dev console warning in a bit but as for saving the file, could you get a screenshot of your browser's dev console output? I suspect there should be an error printed there.

jelveh avatar Jul 19 '24 21:07 jelveh

This is my browser's dev console after clicking the save button on the text editor

Captura desde 2024-07-19 19-21-32

Uncaught in promise was the output after clicking save file on the text editor

Captura desde 2024-07-19 19-23-08

Koppeks avatar Jul 19 '24 22:07 Koppeks

Interesting, I need to see the code. Could you open a PR with your changes/branch?

jelveh avatar Jul 19 '24 22:07 jelveh

@jelveh Its done let me know If I did something wrong or if I can help you with anything

Koppeks avatar Jul 19 '24 22:07 Koppeks

Hey @Koppeks I saw that you closed the PR. Let me know if you need help with anything. I think that PR was pretty much ready to be merged πŸ”₯

jelveh avatar Jul 21 '24 16:07 jelveh

I though the feature had to have more things πŸ˜… . I feel like its missing a watcher when the files are added or deleted from the folder templates and the guy that send the idea sait the templates that had content should be used in the new created files from said template.

Also, I am taking extra long because I move back to windows 😩 , its all setup now

Koppeks avatar Jul 21 '24 18:07 Koppeks

closed via #627 πŸŽ‰

jelveh avatar Jul 22 '24 18:07 jelveh