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

Add warning when trying to run Fabric API as an executable #1196

Closed
wants to merge 10 commits into from

Conversation

IMS212
Copy link

@IMS212 IMS212 commented Dec 2, 2020

This PR shows this when the jar is run as an executable. This would fix a lot of the confusion around the API, and the current code does not seem to have problems with anything else in the API.
fabricapi

@i509VCB i509VCB added enhancement New feature or request small change labels Dec 2, 2020
@i509VCB i509VCB requested review from a team December 2, 2020 05:39
@modmuss50
Copy link
Member

I don’t believe we are allowed to release this onto curseforge. I’m 99% sure that executable jars are against the TOS. Please correct me if I’m wrong.

@IMS212
Copy link
Author

IMS212 commented Dec 2, 2020

I have asked around, and it seems it is in the clear. BetterFPS does this as well and is allowed on curseforge.


public final class APIWarning {
public static void main(String[] args) {
String st = "Fabric API is not meant to be run.\nPlease place this file in your mods folder.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably this should be handled by a resource bundle

build.gradle Outdated
attributes 'Implementation-Title': 'FabricAPI',
'Implementation-Version': project.version,
'Main-Class': 'net.fabricmc.fabric.impl.launch.APIWarning'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move this block into tasks.withType(Jar) so this implementation info and main class is available for any jar produced

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've fixed both these, you mind reviewing again?

Signed-off-by: IMS <31803019+IMS212@users.noreply.github.com>
@IMS212 IMS212 requested review from liach and removed request for a team January 12, 2021 01:21
@IMS212
Copy link
Author

IMS212 commented Jan 12, 2021

Wait, what? I didn't remove the request for API developers

@i509VCB i509VCB requested review from a team January 12, 2021 01:27
public static void main(String[] args) {
Locale defaultLocale = Locale.getDefault();
ResourceBundle WarningAPI = ResourceBundle.getBundle("lang/WarningAPI", defaultLocale);
JOptionPane.showMessageDialog(null, WarningAPI.getString("api.warning"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if fabric api is run in a headless environment. Just check GraphicsEnvironment to validate that otherwise print the message in sys out.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would system error be better? Since it's already an error, and this way it will be highlighted red (in consoles/terminals that treat error differently to out).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been fixed with Alex's PR

String st = "Fabric API is not meant to be run.\nPlease place this file in your mods folder.";
JOptionPane.showMessageDialog(null, st);
Locale defaultLocale = Locale.getDefault();
ResourceBundle WarningAPI = ResourceBundle.getBundle("lang/WarningAPI", defaultLocale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope we can have a bundle setup like https://github.com/FabricMC/fabric-installer/blob/e76d587e22ae9767c0f97fc782c991e461881b1c/src/main/java/net/fabricmc/installer/util/Utils.java#L36-L50 so that we don't need to use iso encoding and ugly unicode escapes for the translation properties

AlexIIL and others added 2 commits January 11, 2021 19:19
* Fix headless exception. (This seems to work for me locally?)

* Spaces -> Tabs.

* msg -> message.

* Fix uppercase variable name (by inlining it).
…hanks to @AlexIIL

Signed-off-by: IMS <31803019+IMS212@users.noreply.github.com>
@IMS212
Copy link
Author

IMS212 commented Jan 12, 2021

It's been updated with both ResourceBundles and headless support, you mind re-reviewing?

@OroArmor
Copy link

I would also add something to link to the fabric installer, so that people can install the loader if they don't have it yet

Signed-off-by: IMS <31803019+IMS212@users.noreply.github.com>
@IMS212
Copy link
Author

IMS212 commented Jan 12, 2021

Done.


public final class APIWarning {
public static void main(String[] args) {
final ResourceBundle WarningAPI = ResourceBundle.getBundle("lang/WarningAPI", Locale.getDefault(), new ResourceBundle.Control() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we prefer name the local var in lower camel like warningApi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@i509VCB i509VCB added the priority:low Low priority PRs that don't immediately need to be resolved label Jan 19, 2021
e.printStackTrace();
}

return super.newBundle(baseName, locale, format, loader, reload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super.newBundle(baseName, locale, format, loader, reload);
return super.newBundle(baseName, locale, format, loader, reload);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good? Unless you mean a different area

Co-authored-by: liach <7806504+liach@users.noreply.github.com>
@LambdAurora LambdAurora requested a review from a team April 10, 2021 10:47
@IMS212 IMS212 changed the base branch from 1.16 to 1.17 July 12, 2021 21:36
@IMS212 IMS212 changed the base branch from 1.17 to 1.16 July 12, 2021 21:36
@IMS212 IMS212 changed the base branch from 1.16 to 1.17 October 7, 2021 14:13
@IMS212 IMS212 changed the base branch from 1.17 to 1.16 October 7, 2021 14:14
@teddyxlandlee
Copy link
Contributor

Buddy, this made me laugh 😆

Is this really necessary? I believe 95%+ of players know this should be dragged into mods directory. Other mod APIs, including Forge, Quilt & LiteLoader haven't shown up a warning like this.

If players don't know Fabric API is a mod instead of an executable library, you can add a tip in the installer, noticing them download Fabric API in CurseForge/Modrinth and put it into mods directory. Besides, can't those players who download Fabric API in CurseForge/Modrinth realize such a thing from such a website should be treated as a mod? I think it's not our duty to add a dumb Swing app & make Fabric API fatter and fatter.

@LambdAurora
Copy link
Contributor

@teddyxlandlee

Accessibility features make you laugh? sad

While, yes, a large user base should know this should be put into the mods directory, there's also the question of new users.
In one of my most recent user support I've encountered an user who seemed to be a computer novice, which made the user support quite more intense. I don't think being hostile to new users and features facilitating support is a good approach.

This comment honestly comes off as a rather elitist take and hostile towards new users. I would rather not have the same issue as Linux here in Fabric or its alternatives.

@apple502j
Copy link
Contributor

This feature looks good, but I believe it should belong in Loom so that everyone can use it (with optout ofc). Also the branch is 1.16, which is way outdated.

@teddyxlandlee
Copy link
Contributor

This feature looks good, but I believe it should belong in Loom so that everyone can use it (with optout ofc). Also the branch is 1.16, which is way outdated.

Great idea!

However, I think the class should be shrunk as small as possible. Using proguard and package-less class name can shrink it in a specific way.

Also, add a boolean toggle in remapJar. If it is set to true, the already-shrunk class binary will be dumped into the jar along with Main-Class manifest (if not set).

To make it short:

  1. The class may be mod-insensitive, which means Fabric API uses the same class & the same warning text as other mods.
  2. No resource bundles, if possible. Texts are stored inside the class directly. Also, it's a bad idea to let the class trying to understand fabric.mod.json.
  3. Loom copies the already-configured class binary into your remapped jar. This means you don't need to compile it again, because the binary has been stored in Loom.

@IMS212
Copy link
Author

IMS212 commented Aug 22, 2022

This was made as my first PR ever. I am now a developer for many mods, and can likely recreate this much better, so as such, I'll close this.

@IMS212 IMS212 closed this Aug 22, 2022
@IMS212
Copy link
Author

IMS212 commented Aug 22, 2022

This feature looks good, but I believe it should belong in Loom so that everyone can use it (with optout ofc). Also the branch is 1.16, which is way outdated.

How would it be included in Loom? Would it just embed itself into the jar?

@teddyxlandlee
Copy link
Contributor

teddyxlandlee commented Aug 23, 2022

How would it be included in Loom? Would it just embed itself into the jar?

To store the class file in Loom, and dumps it into remapJar along with Main-Class manifest attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority:low Low priority PRs that don't immediately need to be resolved small change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet