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

Linux Support? #35

Closed
nwvh opened this issue Aug 28, 2022 · 31 comments · Fixed by #216
Closed

Linux Support? #35

nwvh opened this issue Aug 28, 2022 · 31 comments · Fixed by #216
Labels
Enhancement New feature or request Solved This issue has been resolved

Comments

@nwvh
Copy link
Contributor

nwvh commented Aug 28, 2022

Hey, would it be possible to make Linux support as it's a python file? Thanks

@DevilXD
Copy link
Owner

DevilXD commented Aug 28, 2022

Yes, the thing is, the GUI suite I'm using should work properly on Linux as well, and all cases where a Windows-only code is used, already have some extra conditions to avoid throwing an error. This code just never been tested on a Linux - you can try running it there from source, and report back any errors or issues that'd appear.

If everything would work, I can think about adding a release packaging flow for Linux as well.

@DevilXD DevilXD added the Enhancement New feature or request label Sep 3, 2022
@nwvh
Copy link
Contributor Author

nwvh commented Sep 10, 2022

So I tried it and I have a problem with pywin32 library, which is only available for windows, I tried workarounds but was unsuccessful...

@DevilXD
Copy link
Owner

DevilXD commented Sep 11, 2022

Traceback please. I know this library won't work on Linux, but all places where it's used, already have a condition in place that makes it work without the library. At least in theory - in practice, I'd need the traceback to see where the issue is.

@DevilXD DevilXD added the Feedback Wanted Extra feedback is needed label Sep 20, 2022
@bricep
Copy link

bricep commented Nov 13, 2022

image

@bricep
Copy link

bricep commented Nov 13, 2022

And when attempting to not import pywin32 within main.py:
image

@DevilXD
Copy link
Owner

DevilXD commented Nov 13, 2022

@bricep I see, thank you for taking interest! Because the Linux support was never really planned when I was making this application, we can both expect some heavy steps (and hopefully not impassable walls) along the way, hence why I've created a new branch for testing this: https://github.com/DevilXD/TwitchDropsMiner/tree/linux

Please give it a try and let me know how far it gets you this time.

Also, just a cursory question - are you trying to run this on a headless machine? Because this application comes with a GUI that currently cannot handle headless in any capacity, mostly due to the non-headless Chrome login flow that's required for authentication.

@bricep
Copy link

bricep commented Nov 15, 2022

I completely understand and if your time is limited, don't feel obligated or that you have to troubleshoot or work on this at all. I was just happy to send a traceback and not leave you hanging!

I did a fresh pull from the new linux branch and get to the same place as before:
image

To answer your question, this isn't a headless machine.

@DevilXD
Copy link
Owner

DevilXD commented Nov 16, 2022

Eh, I thought this one was protected already. How is it now?

@bricep
Copy link

bricep commented Nov 16, 2022

First
image
Then after installing seleniumwire, I get this error and have to install undetected_chromium:
image
I got an error about importing PIL and ended up having to upgrade to the latest version.
Then, I got this:
image

@DevilXD
Copy link
Owner

DevilXD commented Nov 16, 2022

All required libraries can be installed via pip install -r requirements.txt, and they normally do so if you'd run the setup_env.bat file. Although, Linux cannot run it, so there's that. The winreg module is used for autostart handling, not sure how I'd be able to achieve this on Linux yet.

It took me a while to figure out how to handle this import, as I only intend to proceed with the loading and disable the functionality wherever needed. Proper care would need to be taken later on when actually handling all of these cases, for now we're trying to get this thing to load at all. Try again please?

@bricep
Copy link

bricep commented Nov 16, 2022

Awesome! The requirements error out at pywin32... pip won't install it. After that, I get this error now when I run main.py:
image

I have confirmed the icon file is present and isn't corrupted. I found this old thread and attempted to use an xbm version but that threw the same error.

@DevilXD
Copy link
Owner

DevilXD commented Nov 16, 2022

I could split the requirements into windows and linux ones easily, that should solve that.

The probable cause is that the ICO file format is windows-specific. I've ran out of time today, but I'll get back to this tomorrow and over the weekend, see what I can do.

@sanjuant
Copy link

Hi, I managed to launch the program under Linux by modifying the lines that refer to the icon.

First of all, I converted the icon to GIF.

# handle input parameters
    # NOTE: parser output is shown via message box
    # we also need a dummy invisible window for the parser
    root = tk.Tk()
    root.overrideredirect(True)
    root.withdraw()
    icon = tk.PhotoImage(file='pickaxe.gif')
    root.iconphoto(True, icon)
    root.update()
            self.icon = pystray.Icon(
                "twitch_miner",
                Image_module.open(resource_path("pickaxe.gif")),
                self.get_title(drop),
                menu,
            )
        # withdraw immediately to prevent the window from flashing
        self._root.withdraw()
        # root.resizable(False, True)
        icon = tk.PhotoImage(file='pickaxe.gif')
        root.iconphoto(True, icon)
        root.title(WINDOW_TITLE)  # window title
        root.bind_all("<KeyPress-Escape>", self.unfocus)  # pressing ESC unfocuses selection

image

It's possible to run in headless mode to dockerize app ?

@DevilXD
Copy link
Owner

DevilXD commented Nov 29, 2022

It's possible to run in headless mode to dockerize app ?

This belongs more to #17 rather than here, but the short answer is no, because the miner is currently strictly tied with the GUI framework, which you can't control from headless. And even if I would want to make it headless, then I can't because of the non-headless Chrome backup login flow. If you'd still want to say something about this topic, please do so under #17.

Regarding the rest, yeah, the icon format was being the culprit here, and I just had not enough free time to really get to it. I was also wondering which file format I could use for this, that'd support and make sense on both windows and linux. Your GIF solution may seem like it's working, but not really (pic from windows for comparison):

linux
win

It could be just a result of local vars being garbage-collected, and the icon variable's contents ceasing from existence - had that happen to me before. Just a matter of keeping a reference to the photo image somewhere. I was gonna use PNG as a more system-independent format, but it looks like the GIF is the only option: https://stackoverflow.com/a/27980230/8576445

Even with all of this being "solved", there's still a matter of the functionality that had to be "disabled" to make this thing run on Linux, specifically:

  • Chrome backup login flow possibly starting with an extra console window (could be possibly remedied with some documentation)
  • Autostart support (no windows registry here, not sure how that's even done on linux)
  • No duplicated instance protection
  • Questionable support for graceful exit during system shutdown (there's code for this already, but it was never tested)

Not sure what to do with these cases.

@sanjuant Have you done any additional usage tests (using the gui, logging in and trying to mine) besides launching it?

@sanjuant
Copy link

Thanks for your answer, I think the icon didn't show up because I'm running it under WSL2.

The browser doesn't seem to be compatible, and as I wanted a docker solution, I didn't investigate further. Can I insert a cookie somewhere to bypass the login part?

image
image

@DevilXD
Copy link
Owner

DevilXD commented Nov 30, 2022

The backup Chrome login currently ceased to work due to Kasada (Twitch's anti-bot protection) updating against the undetected_chromedriver. I've opened an issue regarding that here: ultrafunkamsterdam/undetected-chromedriver#897

There's a different, old way of logging in available in the latest master, which I've just merged into the linux branch. Please try using that instead. If the chrome browser would open again, see which login error code you've got, it should be printed out in the output window.

@sanjuant
Copy link

I forgot to mention that I had to do without an import to run the program.

❯ python main.py
Traceback (most recent call last):
  File "main.py", line 41, in <module>
    from twitch import Twitch
  File "/home/sorrow/TwitchDropsMiner/twitch.py", line 12, in <module>
    from subprocess import CREATE_NO_WINDOW
ImportError: cannot import name 'CREATE_NO_WINDOW' from 'subprocess' (/usr/lib/python3.8/subprocess.py)
❯ python main.py
Traceback (most recent call last):
  File "main.py", line 108, in <module>
    root.iconbitmap(resource_path("pickaxe.ico"))
  File "/usr/lib/python3.8/tkinter/__init__.py", line 2080, in wm_iconbitmap
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "/home/sorrow/TwitchDropsMiner/pickaxe.ico" not defined
❯ python main.py

image

image

image

image

image

image

As you can see the icon works in the taskbar.
image

After that I can connect, the points seem to recover well but it seems that this is the only thing that works. I clicked on "Load Points" but nothing happened.
image

In inventory, Refresh not work.
image

In settings, i can add or exclude games.
image

Reload button seem to trigger campains.
image

The language works but I think I don't have the Chinese characters installed on my linux system.
image
image

Some Twitch campaigns listed on my profile.
image

@DevilXD
Copy link
Owner

DevilXD commented Nov 30, 2022

ImportError: cannot import name 'CREATE_NO_WINDOW' from 'subprocess'

That's my fault, it was already handled previously (3fdeb73), but I messed up the merge commit (b86dd3c) and it got overwritten by the master branch. I've fixed it yet again now: c80bccd

_tkinter.TclError: bitmap "/home/sorrow/TwitchDropsMiner/pickaxe.ico" not defined

Pretty sure that one is from one of the icon changes you made. I just pushed out the icon change of my own, see if it works for you with no further changes required or not please. Additional changes included gating pywin32 behind a windows check, so that requirements.txt can be used for library installation with no modifications.

"Load points" won't do anything if there's no channels on the channel list. On the inventory tab, to see all campaigns, you have to check all filters, uncheck "Linked only", and only then press the "Refresh" button. To mine a campaign, ensure it's state is "Active" and it shows your account is "Linked" - if it's not, click on the "Not linked" text to proceed to linking. Links can also be handled from the campaigns page: https://www.twitch.tv/drops/campaigns With a linked campaign, ensure it's on the Priority list, or uncheck the "Priority only" option, then hit "Reload" to see if everything works.

I haven't considered the Chinese characters not being visible on some systems. I might change the language names to be strictly English names (Chinese, German, Chech) to avoid this.

@sanjuant
Copy link

_tkinter.TclError: bitmap "/home/sorrow/TwitchDropsMiner/pickaxe.ico" not defined

Pretty sure that one is from one of the icon changes you made. I just pushed out the icon change of my own, see if it works for you with no further changes required or not please. Additional changes included gating pywin32 behind a windows check, so that requirements.txt can be used for library installation with no modifications.

This error occurs before I have changed anything on my end. With new version, icon work.

"Load points" won't do anything if there's no channels on the channel list. On the inventory tab, to see all campaigns, you have to check all filters, uncheck "Linked only", and only then press the "Refresh" button. To mine a campaign, ensure it's state is "Active" and it shows your account is "Linked" - if it's not, click on the "Not linked" text to proceed to linking. Links can also be handled from the campaigns page: https://www.twitch.tv/drops/campaigns With a linked campaign, ensure it's on the Priority list, or uncheck the "Priority only" option, then hit "Reload" to see if everything works.

If in channel you only see the current campaigns then everything is ok :) I thought I would see the channels I follow that are online there.

image

The only error I could see is the characters that are not displayed.

image

@DevilXD
Copy link
Owner

DevilXD commented Nov 30, 2022

Glad it works =) Can replace the Chinese characters, but there's no good replacement for emojis. In the last pic, I could theoretically just use a capital X, but that's an eh solution.

I think it's safe to merge the linux branch into the master branch now.

@WrayOfSunshine
Copy link

Can someone write a condensed "how-to" and add it to the wiki? I'm trying to follow along in this issue's comments but it'd be much easier if we had a page that directly explained how to run it.

@DevilXD
Copy link
Owner

DevilXD commented Dec 7, 2022

@dethmourne I just did so today though, here's a link: https://github.com/DevilXD/TwitchDropsMiner/wiki/Setting-up-the-environment,-building-and-running

It's as condensed as it can get, really couldn't make it simpler. Can't auto-install Python and Git with proper configuration, but at least once you do so, it's all just a matter of running some batch scripts that do all the thinking and calls for you. The only thing that's still missing is maintenance section AKA what to do when a new version of source code becomes available, but I'll add it soon / at some point in the future.

That's for running this project from the Github's master branch, which always has the latest changes implemented. Normally, the newest stable version is available in releases: https://github.com/DevilXD/TwitchDropsMiner/releases, although the current v14 still uses a broken login system, and I'm still fixing things for the v15's release.

@WrayOfSunshine
Copy link

@DevilXD To the best of my knowledge you can't run .bat files in linux, though.

@WrayOfSunshine
Copy link

Okay, apparently I was wrong on that front. I do get output from the build.bat but it says:

./build.bat: line 1: @echo: command not found
./build.bat: line 2: cls: command not found
./build.bat: line 9: unexpected EOF while looking for matching `"'
./build.bat: line 10: syntax error: unexpected end of file

@WrayOfSunshine
Copy link

WrayOfSunshine commented Dec 7, 2022

I was able to get it running by just running pip install -r requirements.txt and then running python main.py and it works :)

@DevilXD
Copy link
Owner

DevilXD commented Dec 8, 2022

you can't run .bat files in linux, though.

Right. Sorry, I'm not a linux user >.>

I should make a set of .sh files for linux then. Never did so, so idk how hard it'd be.

In terms of installation, what you did was install all required libraries and run it from your global Python installation. This is barely okay for a new Python installation, and only gets worse from there. If you'd ever consider using another project and install it's libraries too, PyInstaller would bundle them when building an executable for this project. I've ran into this at v7 where a built executable was 48 MB (vs current 11 MB) big and took 10+ seconds (1-2 seconds now) to open on my machine. For this reason, there's all of this virtual environment (venv for short) creation process in the env folder and running it from there. I should add some manual instructions to that page too, it seems.

There's no good way for you to undo it for your global installation, but you can still go through the venv process to separate the libraries. A venv is like a separate space for libraries to be installed into, with it's own separate python, pythonw and pip executables. In order to create one, install libraries to it and run the application from there:

  • From the project's directory as cwd: python -m venv env, to create a venv in the env folder.
  • ./env/Scripts/activate.sh to activate the venv. This should add an (env) ... prefix to your command prompt.
  • pip install -r requirements.txt to install required libraries into the venv.
  • pythonw main.py to run the application.

Instead of the venv activation step, you can use ./env/Scripts/python, ./env/Scripts/pythonw and ./env/Scripts/pip executables directly, to install the requirements and later on, run the application.

@sanjuant
Copy link

sanjuant commented Dec 8, 2022

Hi @DevilXD ,

This is command i have typed to execute on WSL2

pip install --user virtualenv
git pull
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
python3 main.py

I don't think pythonw works on Linux. But I may be wrong.

@DevilXD
Copy link
Owner

DevilXD commented Dec 8, 2022

@sanjuant You don't need to pip install a 3rd party library for this, Python 3 comes with a venv module in it's standard library: https://docs.python.org/3/library/venv.html

All you need to do is run python -m venv <path> to create a new venv in the specified <path>. Rest of the commands looks okay.

@Juice805
Copy link

Juice805 commented Dec 9, 2022

Been using https://github.com/Zaarrg/TTVDropBot for some time now, but it has fallen into disarray. A lightweight docker image release (dependent on #17 and linux support) would instantly take its place on my server.

I'll be messing around with it for fun in the meantime

@DevilXD
Copy link
Owner

DevilXD commented Dec 9, 2022

@Juice805 The headless mode is still on the table, but not the docker image - you'd have to create that one yourself. Also please note that this project is more or less a personal miner rather than something you're supposed to run 24/7 on some kind of server.

I'm still wondering how I could tackle the headless mode, as all effort put into the project since v4 was to try and convert this thing from an "ugly" console application, into something that has a nice user interface. UI code is now strictly tied to virtually every step the miner makes, and there's no easy way of "decoupling" it from the code, short of writing a separate client with no UI interaction at all.

@DevilXD
Copy link
Owner

DevilXD commented Dec 25, 2022

Linux support is now a part of v15 release. If you'd like to see anything more to it, like building a Linux executable (no idea how one can do that, but worth considering), then please open another issue.

@DevilXD DevilXD closed this as completed Dec 25, 2022
@DevilXD DevilXD added Solved This issue has been resolved and removed Feedback Wanted Extra feedback is needed labels Dec 25, 2022
@Pr0mises Pr0mises mentioned this issue Jan 5, 2023
@guihkx guihkx linked a pull request Jun 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Solved This issue has been resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants