fetchcord / FetchCord

FetchCord grabs your OS info and displays it as Discord Rich Presence
MIT License
326 stars 21 forks source link

Uptime in distro view keeps resetting #149

Closed SimPilotAdamT closed 2 years ago

SimPilotAdamT commented 3 years ago

Debug info


Type help for instructions on how to use fish
[22:36:07] adam@Adam-Arch /home/adam  
> fetchcord --debug
adam@Adam-Arch 
-------------- 
OS: Arch Linux x86_64 
Host: 20M50013UK ThinkPad L380 
Kernel: 5.12.2-arch1-1 
Uptime: 2 days, 37 mins 
Packages: 2047 (pacman) 
Shell: fish 3.2.1-5-gd79f86407 
Resolution: 1920x1080 
DE: xmonad 
WM: LG3D 
Theme: Breeze-Darker [GTK2/3] 
Icons: breeze-dark [GTK2/3] 
Terminal: konsole
CPU: Intel i5-8250U (8) @ 3.400GHz 
GPU: Intel UHD Graphics 620 
Memory: 2538MiB / 31866MiB 
Battery0: 73% [Charging] 
Disk (/): 75G / 259G (31%)
[KeyError]: 'Font:'[KeyError]: 'Font:'----run_rpc----

uptime in epoch: 1620853139.0
cpuid: 740476198437650473
cpuappid: 741099939198926920
termappid: 741286819676553258
hostappid: 744326223412461630
2047 (pacman) 
----out.py----

----DE/WM----
deid: xmonad
wmid: LG3D
wmline item 0: LG3D 

----TERMINAL----

[KeyError]: 'Font:'
fontline: Font: N/A
termid: 741286819676553258                // I ran the command thru konsole cos xterm doesn't allow copying from the terminal
termline item 0: konsole
themeline: Breeze-Darker [GTK2/3] 

----HOST INFO----

hostline: 20M50013UK ThinkPad L380 
batteryline:  73% [Charging] 
resline: 1920x1080 

----GPU INFO----

gpuinfo: Intel UHD Graphics 620
gpuvendor: intel

----CPU INFO----

cpuvendor: intel
cpumodel: Intel i5
cpuinfo: Intel i5-8250U (8) @ 3.400GHz
cpuline item 0: Intel i5-8250U (8) @ 3.400GHz
memline: 2538MiB / 31866MiB 

----OS INFO----

sysosline: Arch Linux x86_64 
sysosid: 740476198437650473
diskline: /): 75G / 259G (31%)
packagesline item 0: 2047 (pacman) 

----testing.py----
----DE/WM----

deid: xmonad
wmid: LG3D

----TERMINAL/SHELL----

termid: 741286819676553258
shellid: fish

----HOST INFO----

hostid: 742887089179197462

----GPU INFO----

gpuvendor: intel

----CPU INFO----

cpumodel: Intel i5

('DEFAULT', <Section: DEFAULT>)
('cycle_0', <Section: cycle_0>)
('cycle_1', <Section: cycle_1>)
('cycle_2', <Section: cycle_2>)
('cycle_3', <Section: cycle_3>)
{}
cycle0 not in : True
try_connect(key="cycle0") on <pypresence.presence.Presence object at 0x7f0f5cfb6460>
Unknown DE/WM, contact us on github to resolve this.                // This is because I have Xmonad set to rename itself as a WM to LG3D so Java apps & and Java IDE (Intellij Idea) can run on Xmonad. This is not an issue I want resolved.
cycle 0
try_update(key="cycle0") on <pypresence.presence.Presence object at 0x7f0f5cfb6460>
appid: 740476198437650473
^CClosing connection.
[22:36:19] adam@Adam-Arch /home/adam  
> ```
SimPilotAdamT commented 3 years ago

(Posting here cos the debug info gitched out the original message)

Operating system & way of installation

OS: Arch Linux Method of installing fetchcord: AUR

Error/issue

The uptime as shown in the actual rich presence resets itself roughly every 24 hours, since it runs on UNIX Epoch time.

Other notes(optional)

I am uncure of how this could be fixed.... Maybe see if the time can be stored in some C datetime format instead?

luni-moon commented 2 years ago

(Posting here cos the debug info gitched out the original message)

Operating system & way of installation

OS: Arch Linux Method of installing fetchcord: AUR

Error/issue

The uptime as shown in the actual rich presence resets itself roughly every 24 hours, since it runs on UNIX Epoch time.

Other notes(optional)

I am uncure of how this could be fixed.... Maybe see if the time can be stored in some C datetime format instead?

Mine does too on iMac, isn't it supposed to?

SimPilotAdamT commented 2 years ago

Mine does too on iMac, isn't it supposed to?

No, it isn't... I started to think it was an issue with Discord's RPC API but I saw it working with a custom RPC script I was using (with NodeJS as the backend). The script I was using stored the bootup time as a UNIX Epoch value, correct to the second (in seconds after the First of January 1970).

luni-moon commented 2 years ago

Mine does too on iMac, isn't it supposed to?

No, it isn't... I started to think it was an issue with Discord's RPC API but I saw it working with a custom RPC script I was using (with NodeJS as the backend). The script I was using stored the bootup time as a UNIX Epoch value, correct to the second (in seconds after the First of January 1970).

I do feel like I saw something in the code a week or so ago, but when looking for it again today, I could not find it. I'll look into this soon.

luni-moon commented 2 years ago

The only instance of a uptime (that I can find), being mentioned is found in this file: fetch_cord/computer/Computer.py, on lines 39 and 303. Has something to do with the psutil.boot_time (found in line 303 of this repository), so I would check that file if possible.

SimPilotAdamT commented 2 years ago

I think that will have to be it... I'm 90% certain that psutil boot time should be given in Unix Epoch anyways so idk what could be causing the issue... I'll check the file myself and see.

luni-moon commented 2 years ago

Just checked, and it looks like it does, _pslinux.py (I think it is line 1574?).

Here is the code block:

def boot_time():
    """Return the system boot time expressed in seconds since the epoch."""
    global BOOT_TIME
    path = '%s/stat' % get_procfs_path()
    with open_binary(path) as f:
        for line in f:
            if line.startswith(b'btime'):
                ret = float(line.strip().split()[1])
                BOOT_TIME = ret
                return ret
        raise RuntimeError(
            "line 'btime' not found in %s" % path)
SimPilotAdamT commented 2 years ago

Yep that does return it correctly according to the comment and the output of when I ran it...

Though I got thinking, that could be rduced to less lines of code, using the os module.

def boot_time():
    """Return the system boot time expressed in seconds since the epoch."""
    from os import popen
    return popen('stat -c %Z /proc/').read().strip()

Could that work?

luni-moon commented 2 years ago

Yep that does return it correctly according to the comment and the output of when I ran it...

Though I got thinking, that could be rduced to less lines of code, using the os module.


def boot_time():

    """Return the system boot time expressed in seconds since the epoch."""

    from os import popen

    stream = popen('stat -c %Z /proc/')        

    return stream.read()

Could that work?

I could try it, but that'd be tomorrow probably. I have to open up my raspberry pi now 😀

SimPilotAdamT commented 2 years ago

Just tested it, it works on all of my machines and virtual machines.

SimPilotAdamT commented 2 years ago

Just tested it, it works on all of my machines and virtual machines.

Edited the code to remove all whitespace outputted by that command.

luni-moon commented 2 years ago

Just tested it, it works on all of my machines and virtual machines.

Edited the code to remove all whitespace outputted by that command.

So did it fix FetchCord timing, or just psutil?

SimPilotAdamT commented 2 years ago

So did it fix FetchCord timing, or just psutil?

Seems like it did fix fetchcord as well on my machine yeah.

luni-moon commented 2 years ago

So did it fix FetchCord timing, or just psutil?

Seems like it did fix fetchcord as well on my machine yeah.

Nice! Any PR is accepted, especially ones that fix bugs :) (Although I would change the function name slightly, to avoid confusion between psutil and this)

SimPilotAdamT commented 2 years ago

Nice! Any PR is accepted, especially ones that fix bugs :) (Although I would change the function name slightly, to avoid confusion between psutil and this)

If I make a PR there in the linked file it tried to make the PR for PSUTIL and not here on Fetchcord...

EDIT: Found a way to make it work on here (https://github.com/MrPotatoBobx/FetchCord/blob/master/fetch_cord/computer/Computer.py#L303), but it will only work on UNIX-Based OS's... Trying to edit my function accordingly now.

SimPilotAdamT commented 2 years ago

186