screengrab icon indicating copy to clipboard operation
screengrab copied to clipboard

Problem in the single-instance mode

Open tsujan opened this issue 6 years ago • 8 comments

Let me explain the problem by describing how it can be reproduced.

Steps to Reproduce (for bugs)
  1. Uncheck Options → Advanced → Allow multiple instances… and close screengrab.
  2. In a terminal, type screengrab --help or even screengrab --fgf and press Enter.
  3. After that, type screengrab and press Enter.

Then, screengrab won't start and this message will be shown: "QLocalSocket::connectToServer: Connection refused"

Context

The problem is caused by using QSharedMemory for creating a single-instance app. In 2, qipc_sharedmemory_blahblah and qipc_systemsem_blahblah are created in /tmp but aren't removed immediately. In 3, qipc_sharedmemory is removed at last but , because it existed in the first place, the app shows an error message and exits. Only after that, the app will start normally.

Possible Solution

In FeatherPad, I used a lock file instead of QSharedMemory because QSharedMemory proved to be unreliable and buggy. However, I didn't use QCommandLineParser in FeatherPad (I don't like such tools, in general) and the code structure is very different.

So, I don't know of a possible solution yet.

System Information

git LXQt.

tsujan avatar Oct 31 '19 20:10 tsujan

@tsujan Thinking loud: Maybe LXQt::SingleApplication can help.

luis-pereira avatar Oct 31 '19 21:10 luis-pereira

@luis-pereira That's a good idea but needs a total overhaul.

I'll think about it a little and tell you if I don't find a simple solution -- by "simple", I mean a few lines of code.

tsujan avatar Oct 31 '19 21:10 tsujan

@luis-pereira I couldn't find a short solution. The problem is that, with --help or a wrong option, the shared memory isn't released.

Would you implement a single-instance by using LXQt::SingleApplication? I don't think I'll find the time needed for code restructuring soon and even if I find it, your work will be cleaner.

tsujan avatar Oct 31 '19 22:10 tsujan

% LANG=C screengrab --help 
Usage: screengrab [options]
ScreenGrab is a crossplatform application for fast creating screenshots of your desktop.

Options:
  -h, --help        Displays this help.
  -v, --version     Displays version information.
  -f, --fullscreen  Take a fullscreen screenshot
  -a, --active      Take a screenshot of the active window
  -r, --region      Take a screenshot of a selection of the screen
  -m, --minimized   Run the application with a hidden main window

Hmm - if you don't like the current implementation, is it so hard to drop and use the method we use for other LXQt packages?

agaida avatar Oct 31 '19 22:10 agaida

if you don't like the current implementation

It's isn't about my disliking it. It's simply wrong because the shared memory will be released only if the app runs first.

is it so hard to drop and use the method we use for other LXQt packages?

It's quite possible and should be done but needs a lot of work because the core should be rewritten.

tsujan avatar Oct 31 '19 22:10 tsujan

ok, in that case i understood you right and agree wholehearted :slightly_smiling_face:

Edit: and to be honest - i would ignore it for now.

agaida avatar Oct 31 '19 22:10 agaida

Edit: and to be honest - i would ignore it for now.

It isn't a big issue -- try to run the app twice after --help or --blahblah and it'll run -- but shows a deep problem.

tsujan avatar Oct 31 '19 22:10 tsujan

It's a minor issue. Can wait.

luis-pereira avatar Nov 04 '19 19:11 luis-pereira