Skip to content

Commit

Permalink
Auto add to applications on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
andersmmg committed Aug 31, 2021
1 parent 5452c2e commit 494452c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions Viewer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ func _on_files_dropped(files, _screen):
$Control/Label.text = path
$WorldEnvironment.environment.background_sky.panorama = texture
$TrackballCamera.reset_rotation()

4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ boot_splash/bg_color=Color( 0.298039, 0.529412, 0.866667, 1 )
config/icon="res://icon.png"
config/windows_native_icon="res://icon.ico"

[autoload]

ShortcutCreator="*res://shortcut_creator.gd"

[editor_plugins]

enabled=PoolStringArray( "res://addons/goutte.camera.trackball/plugin.cfg" )
Expand Down
50 changes: 50 additions & 0 deletions shortcut_creator.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
extends Node



# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if !OS.is_debug_build() and OS.get_name() == "X11":
print(Engine.editor_hint)
create_shortcut()
# get_tree().quit()

func create_shortcut() -> void:
# Get username
var output := []
var _error = OS.execute("whoami", [], true, output)
var username: String = output[0].substr(0, output[0].length() - 1) # Trim junk

# Get other useful data.
var project_name: String = ProjectSettings.get_setting("application/config/name")
var description: String = ProjectSettings.get_setting("application/config/description")

# Prepare paths.
var user_folder_path := "/home/" + username + "/.local/share/godot/app_userdata/" + project_name + "/"
var desktop_file_path := user_folder_path + project_name + ".desktop"
var exec_path := OS.get_executable_path()

# Save game icon to storage.
var icon: Texture = load("res://icon.png")
var icon_data := icon.get_data()
_error = icon_data.save_png("user://shortcut.png")

# Write out file with all the necessary info.
var file := File.new()
_error = file.open(desktop_file_path, File.WRITE)
file.store_string("[Desktop Entry]\n")
file.store_string("Encoding=UTF-8\n")
file.store_string("Name=" + project_name + "\n")
file.store_string("Comment=" + description + "\n")
file.store_string("Exec=\"" + exec_path + "\"\n")
file.store_string("Icon=" + user_folder_path + "shortcut.png\n")
file.store_string("Terminal=false\n")
file.store_string("Type=Application\n")
file.store_string("Categories=Game;")
file.close()

# Copies the desktop file to the right places and allows it to be registered.
_error = OS.execute("cp", [desktop_file_path, "/home/" + username + "/.local/share/applications"], true, output)
_error = OS.execute("cp", [desktop_file_path, "/usr/share/applications"], true, output)

_error = OS.execute("chmod", ["+x", desktop_file_path], true, output)

0 comments on commit 494452c

Please sign in to comment.