-
Notifications
You must be signed in to change notification settings - Fork 259
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
Send File functionality adds a " (1)" after the file type on duplicate file #1851
Comments
Oh yeah. So it does, right there: gnome-shell-extension-gsconnect/src/service/plugins/share.js Lines 112 to 119 in 57c270c
I didn't even write that code, but "whoops". That's a pretty silly mistake. ...Of course, since Gio seems to be the only file-access API in creation without any sort of convenience functions for splitting extensions off of filenames and things like that (no doubt with some ivory-tower nonsense about how their APIs are "above" trivial things like using three- and four-letter codes to identify file types), I guess we get to write that logic ourselves. |
(Mind you, I'm sympathetic to the argument that parsing filenames is an impossible proposition, when people regularly use names like |
Maybe, just, at the front? (1_...) 🤔 from my limit understanding of js this should then be quite easy to change in the code, no? :D If that is the case i have a question: i'm not too familiar with Github yet, but i always wanted to be. Is this realy just a rearrangement of the code in line 119 above? If so, could someone maybe give me some outline on what i have to do do submit the solution myself? (If i am allowed to do it myself in the first place of course :D) That would be awesome! |
If you're interested in tackling this, please don't hold back! GitHub has pretty good docs about the basics of the contributing process, and I'll be happy to answer whatever questions I can. I wouldn't get too hung up on the "GitHub process" aspect of things, though. The first thing is writing the code, all the rest of it can come after. I'll add some suggestions/thoughts about tackling this issue, though you're free to disregard any or all if you prefer to do things differently, and that's fine. The only person I have the right to impose coding rules on is myself. |
What to fix whereThe replacement code is likely to be more complex than that one-liner, it's probably better to write a JS function to transform the name (plus, it may also be useful elsewhere), and replace the current line with a call to that. So, line 119 doesn't grow any longer than one line,
How to fix itEditing strings in JavaScript is definitely easy, it's only the logic that might become complex. Some thoughts there, too:
Testing the fixTesting GSConnect code is notoriously hard due to the way GNOME Shell extensions are managed by the Shell, but luckily in this case you don't need to test your code with GSConnect at all. Its entire job is changing one string into a different string, which doesn't involve any of the rest of GSConnect. So it's probably easiest to work on a function to do what you need in a new file, and test it by running it in For example, I wrote a quick function that emulates the current (bad) logic, and only works for filenames up to function makeUniqueFilename(name) {
if (name.endsWith(' (1)')) {
return name.replace(' (1)', ' (2)');
}
return `${name} (1)`;
}
console.log(makeUniqueFilename('My Document.doc'));
console.log(makeUniqueFilename('My Archive.tar.gz (1)')); When I run it in $ gjs file.js
Gjs-Console-Message: 13:42:02.284: My Document.doc (1)
Gjs-Console-Message: 13:42:02.285: My Archive.tar.gz (2) So, "yay!" my terrible function does exactly what it's supposed to do. Once you have a function that works the way you want it to (meaning: better than mine), then you'd add it into the GSConnect code, and change line 119 to something like: filepath = Filename.makeUniqueFilename(filepath); (On second thought, if the import is going to be called |
Oh, yes, one last note: Since it's been in the news a lot lately, and GitHub is pushing Copilot hard, it's worth addressing the AI coding/assistance issue. It can tend to get a negative reaction from a lot of people, with many sites banning AI-assisted contributions entirely. My personal'position is, if you can convince an AI to write some or all of the code for this, more power to ya. I only ask that you clearly disclose that fact whenever submitting AI-involved code. Not because it's a problem or it makes it more likely to be rejected, but because it affects how, and how much, we review the code before accepting it. (When a human submits code, if there's some part of it I don't really understand, or it's written in a way that seems totally confused or broken, I'll usually work extra hard to try and see the logic in their approach, or try to find some reasons they may have had to write it the way they did. But if I know that the code came from an AI, I can skip all that and just decide that the code seems like nonsense because it IS_. Saves a ton of time!) |
Describe the bug
If in my PC's downloads i already have a file "hello.png" and i send a second file "hello.png" from my phone to my PC, it saves the second file as "hello.png (1)", which changes the file type and not the file's name, as it should
Steps to reproduce
see above
Expected behavior
The second file is renamed to "hello_1.png" or "hello (1).png)" (first solution preferred.
GSConnect version
57
Installed from
Extension Manager
GNOME Shell version
46
Linux distribution/release
Fedora Linux 40 (Workstation Edition)
Paired device(s)
Motorola edge 30 ultra, Samsung Tab S9 FE +
KDE Connect app version
1.31.1 / 1.29.0
Plugin(s)
No response
Support log
No response
Screenshots
No response
Notes
No response
The text was updated successfully, but these errors were encountered: