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

Incorrect Look and Feel After Initial Install #136

Closed
klabarge opened this issue Nov 15, 2016 · 11 comments
Closed

Incorrect Look and Feel After Initial Install #136

klabarge opened this issue Nov 15, 2016 · 11 comments
Milestone

Comments

@klabarge
Copy link
Member

klabarge commented Nov 15, 2016

Tested on Ubuntu 14.04 and 16.04

After an install, the tray menu defaults to the legacy version Metal Look and Feel.

image

Restart QZ Tray and the menu is correct (GTKLookAndFeel)

image

@tresf tresf changed the title Linux tray menu after install auto start Incorrect Look and Feel After Initial Install Nov 15, 2016
@tresf
Copy link
Contributor

tresf commented Nov 15, 2016

I've noticed this as well. I'm not sure what causes it but I have a feeling it has something to do with launching from sudo.

We may need to source the environment for the user before launching:

https://github.com/qzind/tray/blob/2.0/ant/linux/linux-installer.sh.in#L202

@tresf
Copy link
Contributor

tresf commented Nov 15, 2016

This seems to stem from the sudo command, and it may be two-fold.

  1. First, sudo is run against the installer package potentially dropping environmental variables
  2. Second, sudo is used to launch QZ Tray as $USER, potentially dropping environmental variables.

This article explains the exact cause which is the GNOME_DESKTOP_SESSION_ID but gets a bit more into modifying the system permanently which is overkill.

I'd like to see if someone can figure out a one-liner to circumvent this without making any assumptions about the desktop environment.

Edit: Posted a question on stackoverflow: http://stackoverflow.com/questions/40603418/have-script-detect-gnome-session

@tresf tresf added the bug label Nov 15, 2016
@tresf tresf added this to the 2.0.3 milestone Nov 15, 2016
@tresf tresf modified the milestones: 2.2, 2.0.3 Jan 30, 2017
@tresf tresf added the wontfix label Aug 17, 2017
@tresf
Copy link
Contributor

tresf commented Aug 17, 2017

Closing as wontfix. This is cosmetic and doesn't appear to have a solution. If someone finds a solution, please feel free to reopen.

@tresf tresf closed this as completed Aug 17, 2017
@tresf
Copy link
Contributor

tresf commented Sep 20, 2017

@dyorgio has provided a solution here: https://stackoverflow.com/a/46329597/3196753. Reopening until we have a chance to test and commit.

@tresf tresf reopened this Sep 20, 2017
@tresf tresf modified the milestones: 2.2, 2.0.5 Sep 20, 2017
tresf added a commit to tresf/tray that referenced this issue Sep 25, 2017
@tresf tresf modified the milestones: 2.0.5, 2.0.6 Nov 6, 2017
@tresf
Copy link
Contributor

tresf commented Jan 25, 2018

@dyorgio's solution helped understand the problem but only works if additional flags are provided at install time. Closing as won't fix for now. Will reopen if more information surfaces.

@tresf tresf closed this as completed Jan 25, 2018
@dyorgio
Copy link

dyorgio commented Jan 25, 2018

Hi @tresf! How are you? :)

My approach to run software after my installer run (installer was call with sudo) is working with SystemTray lib that uses GTK native Menus, not sure if works with Swing, checkout:

// Get user
String user = System.getenv("SUDO_USER");
if (user == null) {
    user = System.getProperty("user.name");
}
// Get dbus-daemon PID
Process process = Runtime.getRuntime().exec(new String[]{//
    "/bin/sh", "-c", //
    "ps aux | grep \"^" + user + " \" | grep \"dbus-daemon\" | grep \"unix:\" | awk '{print $2}'" //
});
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String pid = reader.readLine();
reader.close();

// Read DBUS process env values
Map dbusEnv = new HashMap();
// put some defaults
dbusEnv.put("XDG_CURRENT_DESKTOP", "Unity");// Ubuntu Rules!
dbusEnv.put("DISPLAY", ":0");// display default
process = Runtime.getRuntime().exec(new String[]{//
    "/bin/sh", "-c", //
    "cat /proc/" + pid + "/environ | tr '\\0' '\\n'" //
});
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
int splitIndex;
while ((line = reader.readLine()) != null) {
    splitIndex = line.indexOf('=');
    if (splitIndex != -1) {
        dbusEnv.put(line.substring(0, splitIndex), line.substring(splitIndex + 1));
    }
}
reader.close();

// Run
process = Runtime.getRuntime().exec(new String[]{//
    "runuser", //
    user,//
    "-c",//
    "/bin/sh -c \"DISPLAY=" + dbusEnv.get("DISPLAY") + " DBUS_SESSION_BUS_ADDRESS=" + dbusEnv.get("DBUS_SESSION_BUS_ADDRESS") + " XDG_CURRENT_DESKTOP=" + dbusEnv.get("XDG_CURRENT_DESKTOP") + " nohup YOUR_COMMAND_HERE\""//
    });

@tresf
Copy link
Contributor

tresf commented Jan 25, 2018

@dyorgio thanks. We're already inside Java when the theming issues occur. Could this technique be adopted to bash?

@dyorgio
Copy link

dyorgio commented Jan 25, 2018

I don't see why not :P

@tresf tresf reopened this Feb 9, 2018
@tresf tresf closed this as completed in d62ec8d Feb 9, 2018
@tresf
Copy link
Contributor

tresf commented Feb 9, 2018

@dyorgio thanks for your code, it helped a lot! I've documented the full solution here: https://stackoverflow.com/a/48712378/3196753.

In short, read the user's UPSTART_SESSION environmental variable from /proc/$pid/environ
and then export UPSTART_SESSION and call initctl --user get-env GNOME_DESKTOP_SESSION_ID.

@tresf
Copy link
Contributor

tresf commented Feb 3, 2019

@dyorgio, on Ubuntu 18.04, cat "/proc/$pid/environ" |tr '\0' '\n' no longer includes the GNOME_DESKTOP_SESSION_ID variable.

@tresf
Copy link
Contributor

tresf commented Feb 3, 2019

Workaround added e0900bb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants