From 39a5bab285b0dfd73eca15e617fbbc1c3dcfaa62 Mon Sep 17 00:00:00 2001 From: stsdc Date: Wed, 14 Jul 2021 23:36:49 +0200 Subject: [PATCH 01/36] create initial flatpak manifest file --- com.github.stsdc.monitor.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 com.github.stsdc.monitor.yml diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml new file mode 100644 index 00000000..8c56938e --- /dev/null +++ b/com.github.stsdc.monitor.yml @@ -0,0 +1,22 @@ +app-id: com.github.stsdc.monitor +runtime: io.elementary.Platform +runtime-version: 'daily' +sdk: io.elementary.Sdk +command: com.github.stsdc.monitor +finish-args: + - '--share=ipc' + - '--socket=fallback-x11' + - '--device=dri' + - '--socket=wayland' + - '--filesystem' + - '--socket=system-bus' + +# This section is where you list all the source code required to build your app. +# If we had external dependencies that weren't included in our SDK, we would list +# them here. +modules: + - name: yourrepositoryname + buildsystem: meson + sources: + - type: dir + path: . \ No newline at end of file From 883434fd4d9eaf4e251ebd9aae817fff2f1977a7 Mon Sep 17 00:00:00 2001 From: stsdc Date: Tue, 27 Jul 2021 00:24:25 +0200 Subject: [PATCH 02/36] starts building; fails on libbamf3 --- .gitignore | 3 ++- com.github.stsdc.monitor.yml | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 80e4f362..d3ad88f6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ builddir .vscode *~ .goutputstream-* -# subprojects/*/ \ No newline at end of file +# subprojects/*/ +.flatpak-builder \ No newline at end of file diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml index 8c56938e..b3eca498 100644 --- a/com.github.stsdc.monitor.yml +++ b/com.github.stsdc.monitor.yml @@ -1,6 +1,6 @@ app-id: com.github.stsdc.monitor runtime: io.elementary.Platform -runtime-version: 'daily' +runtime-version: '6' sdk: io.elementary.Sdk command: com.github.stsdc.monitor finish-args: @@ -8,14 +8,18 @@ finish-args: - '--socket=fallback-x11' - '--device=dri' - '--socket=wayland' - - '--filesystem' + - '--filesystem=/sys:ro' - '--socket=system-bus' + - '--device=all' + + # needed for prefers-color-scheme + - '--system-talk-name=org.freedesktop.Accounts' # This section is where you list all the source code required to build your app. # If we had external dependencies that weren't included in our SDK, we would list # them here. modules: - - name: yourrepositoryname + - name: com.github.stsdc.monitor buildsystem: meson sources: - type: dir From 327849a4b8c462ecb133680a80899e5789e3f528 Mon Sep 17 00:00:00 2001 From: Darshak Parikh Date: Sun, 1 Aug 2021 02:49:04 +0530 Subject: [PATCH 03/36] Add Flatpak build dependencies (#234) --- com.github.stsdc.monitor.yml | 50 +++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml index b3eca498..d17fc4ab 100644 --- a/com.github.stsdc.monitor.yml +++ b/com.github.stsdc.monitor.yml @@ -19,8 +19,56 @@ finish-args: # If we had external dependencies that weren't included in our SDK, we would list # them here. modules: + - name: libstartup-notification + sources: + - type: archive + url: http://www.freedesktop.org/software/startup-notification/releases/startup-notification-0.12.tar.gz + sha256: 3c391f7e930c583095045cd2d10eb73a64f085c7fde9d260f2652c7cb3cfbe4a + + - name: libwnck + buildsystem: meson + config-opts: + - '-Dstartup_notification=enabled' + cleanup: + - /include + - /lib/pkgconfig + - /bin + sources: + - type: archive + url: https://download.gnome.org/sources/libwnck/3.36/libwnck-3.36.0.tar.xz + sha256: bc508150b3ed5d22354b0e6774ad4eee465381ebc0ace45eb0e2d3a4186c925f + + - name: libgtop + sources: + - type: archive + url: https://download.gnome.org/sources/libgtop/2.40/libgtop-2.40.0.tar.xz + sha256: 78f3274c0c79c434c03655c1b35edf7b95ec0421430897fb1345a98a265ed2d4 + + - name: gnome-common + sources: + - type: archive + url: https://download.gnome.org/sources/gnome-common/3.18/gnome-common-3.18.0.tar.xz + sha256: 22569e370ae755e04527b76328befc4c73b62bfd4a572499fde116b8318af8cf + cleanup: + - '*' + + - name: python3-lxml + buildsystem: simple + sources: + - type: file + url: https://files.pythonhosted.org/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz + sha256: 39b78571b3b30645ac77b95f7c69d1bffc4cf8c3b157c435a34da72e78c82468 + build-commands: + - pip3 install --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} lxml + + - name: bamf + sources: + - type: archive + url: https://launchpad.net/bamf/0.5/0.5.5/+download/bamf-0.5.5.tar.xz + md5: 682269ccdde6f6842cceb3cd636d087e + - name: com.github.stsdc.monitor buildsystem: meson sources: - type: dir - path: . \ No newline at end of file + path: . From ff75c62b566e1e513e057aa1a10d3cd2bfc9b97b Mon Sep 17 00:00:00 2001 From: stsdc Date: Wed, 4 Aug 2021 18:56:51 +0200 Subject: [PATCH 04/36] rm libbamf as dependency --- com.github.stsdc.monitor.yml | 26 ++++++++-------- meson.build | 60 ++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml index d17fc4ab..84bdefc0 100644 --- a/com.github.stsdc.monitor.yml +++ b/com.github.stsdc.monitor.yml @@ -52,20 +52,20 @@ modules: cleanup: - '*' - - name: python3-lxml - buildsystem: simple - sources: - - type: file - url: https://files.pythonhosted.org/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz - sha256: 39b78571b3b30645ac77b95f7c69d1bffc4cf8c3b157c435a34da72e78c82468 - build-commands: - - pip3 install --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} lxml + # - name: python3-lxml + # buildsystem: simple + # sources: + # - type: file + # url: https://files.pythonhosted.org/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz + # sha256: 39b78571b3b30645ac77b95f7c69d1bffc4cf8c3b157c435a34da72e78c82468 + # build-commands: + # - pip3 install --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} lxml - - name: bamf - sources: - - type: archive - url: https://launchpad.net/bamf/0.5/0.5.5/+download/bamf-0.5.5.tar.xz - md5: 682269ccdde6f6842cceb3cd636d087e + # - name: bamf + # sources: + # - type: archive + # url: https://launchpad.net/bamf/0.5/0.5.5/+download/bamf-0.5.5.tar.xz + # md5: 682269ccdde6f6842cceb3cd636d087e - name: com.github.stsdc.monitor buildsystem: meson diff --git a/meson.build b/meson.build index ea8c4828..c9e33487 100644 --- a/meson.build +++ b/meson.build @@ -21,10 +21,10 @@ gtk = dependency('gtk+-3.0') gee = dependency('gee-0.8') gio = dependency('gio-2.0') gobject = dependency('gobject-2.0') -bamf = dependency('libbamf3') # to remove +# bamf = dependency('libbamf3') # to remove gtop = dependency('libgtop-2.0') wnck = dependency('libwnck-3.0') -wingpanel = dependency('wingpanel-2.0') +# wingpanel = dependency('wingpanel-2.0') gdk_x11 = dependency('gdk-x11-3.0') config_data = configuration_data() @@ -93,7 +93,7 @@ executable( 'src/Models/TreeViewModel.vala', # Other - 'src/Managers/AppManager.vala', + # 'src/Managers/AppManager.vala', 'src/Managers/ProcessManager.vala', 'src/Managers/Process.vala', 'src/Managers/ProcessStructs.vala', @@ -120,7 +120,7 @@ executable( gee, gio, gobject, - bamf, # to remove + # bamf, # to remove gtop, wnck, gdk_x11, @@ -134,32 +134,32 @@ executable( install: true ) -shared_module( - 'monitor', - 'src/Indicator/Indicator.vala', - 'src/Utils.vala', - 'src/Resources/ResourcesSerialized.vala', - - 'src/Indicator/Widgets/DisplayWidget.vala', - 'src/Indicator/Widgets/PopoverWidget.vala', - 'src/Indicator/Widgets/IndicatorWidget.vala', - 'src/Indicator/Widgets/TemperatureWidget.vala', - 'src/Indicator/Widgets/NetworkWidget.vala', - - 'src/Indicator/Services/DBusClient.vala', - # 'src/Widgets/RevealerSwitch.vala', - icons_gresource, - c_args: c_args, - dependencies: [ - glib, - granite, - gobject, - gtk, - wingpanel - ], - install: true, - install_dir : wingpanel.get_pkgconfig_variable('indicatorsdir', define_variable: ['libdir', libdir]), -) +# shared_module( +# 'monitor', +# 'src/Indicator/Indicator.vala', +# 'src/Utils.vala', +# 'src/Resources/ResourcesSerialized.vala', + +# 'src/Indicator/Widgets/DisplayWidget.vala', +# 'src/Indicator/Widgets/PopoverWidget.vala', +# 'src/Indicator/Widgets/IndicatorWidget.vala', +# 'src/Indicator/Widgets/TemperatureWidget.vala', +# 'src/Indicator/Widgets/NetworkWidget.vala', + +# 'src/Indicator/Services/DBusClient.vala', +# # 'src/Widgets/RevealerSwitch.vala', +# icons_gresource, +# c_args: c_args, +# dependencies: [ +# glib, +# granite, +# gobject, +# gtk, +# wingpanel +# ], +# install: true, +# install_dir : wingpanel.get_pkgconfig_variable('indicatorsdir', define_variable: ['libdir', libdir]), +# ) # Add in a post install script meson.add_install_script('meson/post_install.py') From e8ab7ffdde73cb96d5a2bcf265da7ad774460f37 Mon Sep 17 00:00:00 2001 From: stsdc Date: Thu, 12 Aug 2021 15:49:52 +0200 Subject: [PATCH 05/36] fixed appdata; hope so --- data/com.github.stsdc.monitor.appdata.xml.in | 328 +++++++++---------- 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/data/com.github.stsdc.monitor.appdata.xml.in b/data/com.github.stsdc.monitor.appdata.xml.in index def54c25..f4f2759c 100644 --- a/data/com.github.stsdc.monitor.appdata.xml.in +++ b/data/com.github.stsdc.monitor.appdata.xml.in @@ -9,12 +9,12 @@

Display usage of system resources, filter and manage processes.

- - #d7f4d7 - #242d40 - 0 + + #d7f4d7 + #242d40 + 0 - + https://github.com/stsdc/monitor/raw/master/data/screenshots/monitor-processes.png @@ -25,183 +25,183 @@ StanisΕ‚aw Dac https://github.com/stsdc/monitor https://github.com/stsdc/monitor/issues -https://github.com/stsdc/monitor/issues - - - -​ -​

πŸ› Should fix empty Indicator. Please reboot after installation ⚑️

-​
-​
- -​ -​
    -
  • πŸ› Try to fix frequent GUI hangs πŸ₯Ά
  • -
  • πŸ‡³πŸ‡± Update Dutch translation (@Vistaus)
  • -
  • πŸ‡΅πŸ‡Ή Update Portuguese translation (@hugok79)
  • -
  • πŸ‡·πŸ‡΄ Add Romanian translation (@tiberiufrat)
  • -
-​
-​
- -​ -​
    -
  • Display Storage usage
  • -
  • Update Russian translation (@camellan)
  • -
  • Update Portuguese translation (@hugok79)
  • -
  • Different colours for Upload and Download
  • -
-​
-​
- -​ -​
    -
  • Update Portuguese translation (@rottenpants466)
  • -
  • Update Dutch translation (@Vistaus)
  • -
  • Smoother animations (@DevAlien)
  • -
  • Preselect first entry so that the info panel is always open (@DevAlien)
  • -
  • Show CPU temperature in the Indicator
  • -
-​
-​
+ https://github.com/stsdc/monitor/issues + + + +

Should fix empty Indicator. Please reboot after installation ⚑️

+
+
+ + +
    +
  • 🐛 Try to fix frequent GUI hangs 🥶
  • +
  • 🇳🇱 Update Dutch translation (@Vistaus)
  • +
  • 🇵🇹 Update Portuguese translation (@hugok79)
  • +
  • 🇷🇴 Add Romanian translation (@tiberiufrat)
  • +
+
+
+ + +
    +
  • Display Storage usage
  • +
  • Update Russian translation (@camellan)
  • +
  • Update Portuguese translation (@hugok79)
  • +
  • Different colours for Upload and Download
  • +
+
+
+ + +
    +
  • Update Portuguese translation (@rottenpants466)
  • +
  • Update Dutch translation (@Vistaus)
  • +
  • Smoother animations (@DevAlien)
  • +
  • Preselect first entry so that the info panel is always open (@DevAlien)
  • +
  • Show CPU temperature in the Indicator
  • +
+
+
-​ -​
    -
  • Better System Tab
  • -
  • Update Portuguese translation (@rottenpants466)
  • -
  • Save last opened view (@ryonakano)
  • -
-​
-​
+ +
    +
  • Better System Tab
  • +
  • Update Portuguese translation (@rottenpants466)
  • +
  • Save last opened view (@ryonakano)
  • +
+
+ -​ -​
    -
  • Update Japanese translation (Ryo Nakano)
  • -
  • Disable search entry, when System tab is active
  • -
  • Add screenshots
  • -
-​
-​
+ +
    +
  • Update Japanese translation (Ryo Nakano)
  • +
  • Disable search entry, when System tab is active
  • +
  • Add screenshots
  • +
+
+ -​ -​
    -
  • Add System resources tab
  • + +
      +
    • Add System resources tab
    -​
    -​ + + -​ -​
      -
    • Added tooltips to process state label (Ryo Nakano)
    • -
    • Small bugfix
    • + +
        +
      • Added tooltips to process state label (Ryo Nakano)
      • +
      • Small bugfix
      -​
      -​ + + -​ -​
        -
      • Fix sorting arrows
      • -
      • Update Russian translation (camellan)
      • -
      • Add Turkish translation (Harun Yasar)
      • -
      • Use newest version of live-chart (Laurent Callarec) ← Check his lib for creating charts, it's amazing!
      • -
      -​
      -​
      + +
        +
      • Fix sorting arrows
      • +
      • Update Russian translation (camellan)
      • +
      • Add Turkish translation (Harun Yasar)
      • +
      • Use newest version of live-chart (Laurent Callarec) ← Check his lib for creating charts, it's amazing!
      • +
      ​ +
      + -​ -​
        -
      • Detailed process info in sidebar
      • -
      • CPU frequency in tooltip (Ryo Nakano)
      • + +
          +
        • Detailed process info in sidebar
        • +
        • CPU frequency in tooltip (Ryo Nakano)
        -​
        -​ + + -​ -​
          -
        • Bugfix (potential) of crushes and high CPU usage
        • -
        • Update German translation (Carsten Dietrich)
        • + +
            +
          • Bugfix (potential) of crushes and high CPU usage
          • +
          • Update German translation (Carsten Dietrich)
          -​
          -​ + + -​ -​
            -
          • Update Portuguese translation (Hugo Carvalho)
          • -
          • Update French translation (Nathan Bonnemains and Skeudwenn)
          • -
          • Fix: Don't show swap percentage when it's not available (Ryo Nakano)
          • -
          -​
          -​
          + +
            +
          • Update Portuguese translation (Hugo Carvalho)
          • +
          • Update French translation (Nathan Bonnemains and Skeudwenn)
          • +
          • Fix: Don't show swap percentage when it's not available (Ryo Nakano)
          • +
          +
          + -​ -​
            -
          • Update Italian translation (Mirko Brombin)
          • -
          • Show swap usage (Ryo Nakano)
          • -
          • Update Russian translation (camellan)
          • -
          • Code refactoring (Ryo Nakano)
          • -
          • Update Japanese translation (Ryo Nakano)
          • -
          -​
          -​
          + +
            +
          • Update Italian translation (Mirko Brombin)
          • +
          • Show swap usage (Ryo Nakano)
          • +
          • Update Russian translation (camellan)
          • +
          • Code refactoring (Ryo Nakano)
          • +
          • Update Japanese translation (Ryo Nakano)
          • +
          +
          + -​ -​
            -
          • Fix contents of the window are not shown (Ryo Nakano)
          • -
          • ix no row is still selected when indicator options are enabled (Ryo Nakano)
          • -
          • Fix the app crashes by clicking the "End/Kill Process" buttons when no process is selected (Ryo Nakano)
          • -
          • Added buttons to either "kill" or "end" a process. (Evan Buss)
          • -
          • Change screenshot to English (Christopher Crouse)
          • -
          • Update Russian translation (camellan)
          • -
          • Check if the default display is a X11 display (Hannes Schulze)
          • -
          • Update Spanish translation (Mario Rodrigo)
          • -
          -​
          -​
          + +
            +
          • Fix contents of the window are not shown (Ryo Nakano)
          • +
          • ix no row is still selected when indicator options are enabled (Ryo Nakano)
          • +
          • Fix the app crashes by clicking the "End/Kill Process" buttons when no process is selected (Ryo Nakano)
          • +
          • Added buttons to either "kill" or "end" a process. (Evan Buss)
          • +
          • Change screenshot to English (Christopher Crouse)
          • +
          • Update Russian translation (camellan)
          • +
          • Check if the default display is a X11 display (Hannes Schulze)
          • +
          • Update Spanish translation (Mario Rodrigo)
          • +
          +
          + -​ -​
            -
          • Add start-in-background option to UI
          • + +
              +
            • Add start-in-background option to UI
            -​
            -​ + + -​ -​
              -
            • Add start-in-background command line option
            • -
            • Add Italian and Portuguese translations
            • -
            • Update Dutch, French and Spanish translations
            • -
            • Fix Japanese translation
            • -
            -​
            -​
            + +
              +
            • Add start-in-background command line option
            • +
            • Add Italian and Portuguese translations
            • +
            • Update Dutch, French and Spanish translations
            • +
            • Fix Japanese translation
            • +
            +
            + -​ -​
              -
            • Minor bug fix
            • -
            • Make End process button red
            • -
            • Add Japanese translation
            • -
            -​
            -​
            + + ​ +
              +
            • Minor bug fix
            • +
            • Make End process button red
            • +
            • Add Japanese translation
            • +
            +
            + -​ -​
              -
            • Add CPU and RAM icons
            • -
            • Fix bug, that caused hanging
            • -
            • Update Polish and Russian translation
            • -
            -​
            -​
            + +
              +
            • Add CPU and RAM icons
            • +
            • Fix bug, that caused hanging
            • +
            • Update Polish and Russian translation
            • +
            +
            + -​ -​
              -
            • Add Monitor indicator
            • -
            • Add missing extra French translations
            • -
            • Fix: if icon missing for the process, icon is taken from previous process
            • -
            • Fix: search erases my input while I'm typing
            • -
            • Fix POTFILES
            • -
            -​
            -​
            -​ + +
              +
            • Add Monitor indicator
            • +
            • Add missing extra French translations
            • +
            • Fix: if icon missing for the process, icon is taken from previous process
            • +
            • Fix: search erases my input while I'm typing
            • +
            • Fix POTFILES
            • +
            +
            + + From 7be22ab73a074a3f4352385300c0d2c8efc952d8 Mon Sep 17 00:00:00 2001 From: stsdc Date: Thu, 12 Aug 2021 15:56:05 +0200 Subject: [PATCH 06/36] system tab works --- README.md | 9 +++++++++ com.github.stsdc.monitor.yml | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8733f264..24850de9 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,18 @@ cd build sudo ninja install +#### Build Flatpak + + flatpak-builder build com.github.stsdc.monitor.yml --user --install --force-clean + ### Debug `G_MESSAGES_DEBUG=all ./com.github.stsdc.monitor` +#### Debug Flatpak + + flatpak run --command=sh --devel com.github.stsdc.monitor + + ## Other distributions (unofficial) ### Arch Linux diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml index 84bdefc0..2579e85a 100644 --- a/com.github.stsdc.monitor.yml +++ b/com.github.stsdc.monitor.yml @@ -9,8 +9,10 @@ finish-args: - '--device=dri' - '--socket=wayland' - '--filesystem=/sys:ro' + - '--filesystem=/proc:ro' - '--socket=system-bus' - '--device=all' + - '--share=network' # needed for prefers-color-scheme - '--system-talk-name=org.freedesktop.Accounts' @@ -44,13 +46,13 @@ modules: url: https://download.gnome.org/sources/libgtop/2.40/libgtop-2.40.0.tar.xz sha256: 78f3274c0c79c434c03655c1b35edf7b95ec0421430897fb1345a98a265ed2d4 - - name: gnome-common - sources: - - type: archive - url: https://download.gnome.org/sources/gnome-common/3.18/gnome-common-3.18.0.tar.xz - sha256: 22569e370ae755e04527b76328befc4c73b62bfd4a572499fde116b8318af8cf - cleanup: - - '*' + # - name: gnome-common + # sources: + # - type: archive + # url: https://download.gnome.org/sources/gnome-common/3.18/gnome-common-3.18.0.tar.xz + # sha256: 22569e370ae755e04527b76328befc4c73b62bfd4a572499fde116b8318af8cf + # cleanup: + # - '*' # - name: python3-lxml # buildsystem: simple From f974e20bb9879b2ef3137543ac2662f10c9db286 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 19 May 2022 18:52:18 +0200 Subject: [PATCH 07/36] try to break out from sandbox --- com.github.stsdc.monitor.yml | 6 +++--- subprojects/stylesheet | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 160000 subprojects/stylesheet diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml index 2579e85a..185b8910 100644 --- a/com.github.stsdc.monitor.yml +++ b/com.github.stsdc.monitor.yml @@ -1,18 +1,18 @@ app-id: com.github.stsdc.monitor runtime: io.elementary.Platform -runtime-version: '6' +runtime-version: '6.1' sdk: io.elementary.Sdk command: com.github.stsdc.monitor finish-args: + - '--allow=devel' - '--share=ipc' - '--socket=fallback-x11' - '--device=dri' - '--socket=wayland' - - '--filesystem=/sys:ro' - - '--filesystem=/proc:ro' - '--socket=system-bus' - '--device=all' - '--share=network' + - '--talk-name=org.freedesktop.Flatpak' # needed for prefers-color-scheme - '--system-talk-name=org.freedesktop.Accounts' diff --git a/subprojects/stylesheet b/subprojects/stylesheet new file mode 160000 index 00000000..983b83f6 --- /dev/null +++ b/subprojects/stylesheet @@ -0,0 +1 @@ +Subproject commit 983b83f6858a31af3bc2b7cd0f33a572dd8ec011 From 94162f46359bad736fc79f7e1d61721a53a0ab92 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 13 Feb 2023 14:33:29 +0100 Subject: [PATCH 08/36] convert flatpak manifest to json --- com.github.stsdc.monitor.json | 113 ++++++++++++++++++++++++++++++++++ com.github.stsdc.monitor.yml | 76 ----------------------- subprojects/live-chart | 2 +- 3 files changed, 114 insertions(+), 77 deletions(-) create mode 100644 com.github.stsdc.monitor.json delete mode 100644 com.github.stsdc.monitor.yml diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json new file mode 100644 index 00000000..050d8ebb --- /dev/null +++ b/com.github.stsdc.monitor.json @@ -0,0 +1,113 @@ +{ + "app-id": "com.github.stsdc.monitor", + "runtime": "io.elementary.Platform", + "runtime-version": "6.1", + "sdk": "io.elementary.Sdk", + "command": "com.github.stsdc.monitor", + "finish-args": [ + "--allow=devel", + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland", + "--socket=system-bus", + "--device=all", + "--share=network", + "--talk-name=org.freedesktop.Flatpak", + "--system-talk-name=org.freedesktop.Accounts", + "--system-talk-name=org.freedesktop.UDisks2" + ], + "modules": [ + { + "name": "sassc", + "cleanup": [ + "*" + ], + "sources": [ + { + "type": "git", + "url": "https://github.com/sass/sassc.git", + "tag": "3.6.2" + }, + { + "type": "script", + "dest-filename": "autogen.sh", + "commands": [ + "autoreconf -si" + ] + } + ], + "modules": [ + { + "name": "libsass", + "cleanup": [ + "*" + ], + "sources": [ + { + "type": "git", + "url": "https://github.com/sass/libsass.git", + "tag": "3.6.5" + }, + { + "type": "script", + "dest-filename": "autogen.sh", + "commands": [ + "autoreconf -si" + ] + } + ] + } + ] + }, + { + "name": "libstartup-notification", + "sources": [ + { + "type": "archive", + "url": "http://www.freedesktop.org/software/startup-notification/releases/startup-notification-0.12.tar.gz", + "sha256": "3c391f7e930c583095045cd2d10eb73a64f085c7fde9d260f2652c7cb3cfbe4a" + } + ] + }, + { + "name": "libwnck", + "buildsystem": "meson", + "config-opts": [ + "-Dstartup_notification=enabled" + ], + "cleanup": [ + "/include", + "/lib/pkgconfig", + "/bin" + ], + "sources": [ + { + "type": "archive", + "url": "https://download.gnome.org/sources/libwnck/3.36/libwnck-3.36.0.tar.xz", + "sha256": "bc508150b3ed5d22354b0e6774ad4eee465381ebc0ace45eb0e2d3a4186c925f" + } + ] + }, + { + "name": "libgtop", + "sources": [ + { + "type": "archive", + "url": "https://download.gnome.org/sources/libgtop/2.40/libgtop-2.40.0.tar.xz", + "sha256": "78f3274c0c79c434c03655c1b35edf7b95ec0421430897fb1345a98a265ed2d4" + } + ] + }, + { + "name": "com.github.stsdc.monitor", + "buildsystem": "meson", + "sources": [ + { + "type": "dir", + "path": "." + } + ] + } + ] +} \ No newline at end of file diff --git a/com.github.stsdc.monitor.yml b/com.github.stsdc.monitor.yml deleted file mode 100644 index 185b8910..00000000 --- a/com.github.stsdc.monitor.yml +++ /dev/null @@ -1,76 +0,0 @@ -app-id: com.github.stsdc.monitor -runtime: io.elementary.Platform -runtime-version: '6.1' -sdk: io.elementary.Sdk -command: com.github.stsdc.monitor -finish-args: - - '--allow=devel' - - '--share=ipc' - - '--socket=fallback-x11' - - '--device=dri' - - '--socket=wayland' - - '--socket=system-bus' - - '--device=all' - - '--share=network' - - '--talk-name=org.freedesktop.Flatpak' - - # needed for prefers-color-scheme - - '--system-talk-name=org.freedesktop.Accounts' - -# This section is where you list all the source code required to build your app. -# If we had external dependencies that weren't included in our SDK, we would list -# them here. -modules: - - name: libstartup-notification - sources: - - type: archive - url: http://www.freedesktop.org/software/startup-notification/releases/startup-notification-0.12.tar.gz - sha256: 3c391f7e930c583095045cd2d10eb73a64f085c7fde9d260f2652c7cb3cfbe4a - - - name: libwnck - buildsystem: meson - config-opts: - - '-Dstartup_notification=enabled' - cleanup: - - /include - - /lib/pkgconfig - - /bin - sources: - - type: archive - url: https://download.gnome.org/sources/libwnck/3.36/libwnck-3.36.0.tar.xz - sha256: bc508150b3ed5d22354b0e6774ad4eee465381ebc0ace45eb0e2d3a4186c925f - - - name: libgtop - sources: - - type: archive - url: https://download.gnome.org/sources/libgtop/2.40/libgtop-2.40.0.tar.xz - sha256: 78f3274c0c79c434c03655c1b35edf7b95ec0421430897fb1345a98a265ed2d4 - - # - name: gnome-common - # sources: - # - type: archive - # url: https://download.gnome.org/sources/gnome-common/3.18/gnome-common-3.18.0.tar.xz - # sha256: 22569e370ae755e04527b76328befc4c73b62bfd4a572499fde116b8318af8cf - # cleanup: - # - '*' - - # - name: python3-lxml - # buildsystem: simple - # sources: - # - type: file - # url: https://files.pythonhosted.org/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz - # sha256: 39b78571b3b30645ac77b95f7c69d1bffc4cf8c3b157c435a34da72e78c82468 - # build-commands: - # - pip3 install --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} lxml - - # - name: bamf - # sources: - # - type: archive - # url: https://launchpad.net/bamf/0.5/0.5.5/+download/bamf-0.5.5.tar.xz - # md5: 682269ccdde6f6842cceb3cd636d087e - - - name: com.github.stsdc.monitor - buildsystem: meson - sources: - - type: dir - path: . diff --git a/subprojects/live-chart b/subprojects/live-chart index 1c090e18..5f8ddce7 160000 --- a/subprojects/live-chart +++ b/subprojects/live-chart @@ -1 +1 @@ -Subproject commit 1c090e18fa4ae9f3ccfe0f38d619ebeccd7d6361 +Subproject commit 5f8ddce715f6a9130955bc5f08437050265a317c From 106cdf6de4eddf17366985595abbdb67babcebcf Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 13 Feb 2023 15:16:03 +0100 Subject: [PATCH 09/36] update readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c478348d..d56d7eb8 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ sudo apt install com.github.stsdc.monitor Monitor will then be available from the Applications menu. -### Fedora (34, 35) +### Fedora (36) ```bash sudo dnf copr enable stsdc/monitor @@ -93,10 +93,12 @@ sudo dnf install com.github.stsdc.monitor flatpak-builder build com.github.stsdc.monitor.yml --user --install --force-clean -### Debug -`G_MESSAGES_DEBUG=all ./com.github.stsdc.monitor` ### Debug logging ```bash G_MESSAGES_DEBUG=all GTK_DEBUG=interactive com.github.stsdc.monitor ``` + +#### Debug Flatpak + + flatpak run --command=sh --devel com.github.stsdc.monitor \ No newline at end of file From 824633c89fe6c36995cc764709d9cfe3f1cee423 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 13 Feb 2023 22:07:39 +0100 Subject: [PATCH 10/36] adding udisks2 dependency --- .../com.github.stsdc.monitor.json | 51 +++++++ flatpak/polkit-autogen | 4 + ...-Add-option-to-build-without-polkitd.patch | 131 ++++++++++++++++++ subprojects/live-chart | 2 +- 4 files changed, 187 insertions(+), 1 deletion(-) rename com.github.stsdc.monitor.json => flatpak/com.github.stsdc.monitor.json (63%) create mode 100644 flatpak/polkit-autogen create mode 100644 flatpak/polkit-build-Add-option-to-build-without-polkitd.patch diff --git a/com.github.stsdc.monitor.json b/flatpak/com.github.stsdc.monitor.json similarity index 63% rename from com.github.stsdc.monitor.json rename to flatpak/com.github.stsdc.monitor.json index 050d8ebb..4232028c 100644 --- a/com.github.stsdc.monitor.json +++ b/flatpak/com.github.stsdc.monitor.json @@ -38,6 +38,57 @@ } ], "modules": [ + { + "name" : "pam", + "config-opts" : [ + "--includedir=/app/include/security", + "--disable-doc" + ], + "sources" : [ + { + "type" : "archive", + "url" : "https://github.com/linux-pam/linux-pam/releases/download/v1.4.0/Linux-PAM-1.4.0.tar.xz", + "sha256" : "cd6d928c51e64139be3bdb38692c68183a509b83d4f2c221024ccd4bcddfd034" + } + ] + }, + { + "name": "polkit", + "buildsystem": "meson", + "config-opts": [ + "-Dlibs-only=true" + ], + "sources": [ + { + "type": "git", + "url": "https://gitlab.freedesktop.org/polkit/polkit.git", + "tag": "122" + } + ] + }, + { + "name": "udisks2", + "buildsystem": "autotools", + "config-opts": [ + "--enable-available-modules=no", + "--enable-bcache=no", + "--enable-btrfs=no", + "--enable-introspection=yes", + "--enable-lvm2=no", + "--enable-modules=no", + "--enable-vdo=no", + "--enable-zram=no", + "--with-systemdsystemunitdir=no", + "--with-tmpfilesdir=no" + ], + "sources": [ + { + "type": "git", + "url": "https://github.com/storaged-project/udisks.git", + "tag": "udisks-2.9.4" + } + ] + }, { "name": "libsass", "cleanup": [ diff --git a/flatpak/polkit-autogen b/flatpak/polkit-autogen new file mode 100644 index 00000000..3ba457e5 --- /dev/null +++ b/flatpak/polkit-autogen @@ -0,0 +1,4 @@ +#!/bin/sh + +gtkdocize --flavour no-tmpl +autoreconf -if diff --git a/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch b/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch new file mode 100644 index 00000000..9b1a56d8 --- /dev/null +++ b/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch @@ -0,0 +1,131 @@ +From 1073a44277316348d40d86ecec908f1d4812f360 Mon Sep 17 00:00:00 2001 +From: Christian Hergert +Date: Mon, 27 May 2019 11:49:09 -0700 +Subject: [PATCH] flatpak: make polkit suitable for use within flatpak + +This is based on patches from Patrick Griffis with additional fixes +to allow us to disable use of PAM within Flaptak. +--- + configure.ac | 20 ++++++++++++++++---- + src/Makefile.am | 6 +++++- + src/polkitagent/Makefile.am | 5 +++++ + test/Makefile.am | 6 +++++- + 4 files changed, 31 insertions(+), 6 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 5cedb4e..729d78d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -79,11 +79,13 @@ PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) + +-PKG_CHECK_MODULES(LIBJS, [mozjs-60]) ++AS_IF([test x${enable_polkitd} = yes], [ ++ PKG_CHECK_MODULES(LIBJS, [mozjs-60]) + +-AC_SUBST(LIBJS_CFLAGS) +-AC_SUBST(LIBJS_CXXFLAGS) +-AC_SUBST(LIBJS_LIBS) ++ AC_SUBST(LIBJS_CFLAGS) ++ AC_SUBST(LIBJS_CXXFLAGS) ++ AC_SUBST(LIBJS_LIBS) ++]) + + EXPAT_LIB="" + AC_ARG_WITH(expat, [ --with-expat= Use expat from here], +@@ -236,6 +238,15 @@ if test "x$with_systemdsystemunitdir" != "xno"; then + fi + AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$systemdsystemunitdir"]) + ++dnl --------------------------------------------------------------------------- ++dnl - Disable polkitd when using library alone ++dnl --------------------------------------------------------------------------- ++ ++AC_ARG_ENABLE([polkitd], ++ [AS_HELP_STRING([--disable-polkitd], [Do not build polkitd])], ++ [enable_polkitd=$enableval], [enable_polkitd=yes]) ++AM_CONDITIONAL(BUILD_POLKITD, [test x${enable_polkitd} = yes]) ++ + dnl --------------------------------------------------------------------------- + dnl - User for running polkitd + dnl --------------------------------------------------------------------------- +@@ -579,6 +590,7 @@ echo " + Session tracking: ${SESSION_TRACKING} + PAM support: ${have_pam} + systemdsystemunitdir: ${systemdsystemunitdir} ++ polkitd: ${enable_polkitd} + polkitd user: ${POLKITD_USER}" + + if test "$have_pam" = yes ; then +diff --git a/src/Makefile.am b/src/Makefile.am +index 09fc7b3..c6fe91b 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -1,5 +1,9 @@ + +-SUBDIRS = polkit polkitbackend polkitagent programs ++SUBDIRS = polkit polkitagent programs ++ ++if BUILD_POLKITD ++SUBDIRS += polkitbackend ++endif + + if BUILD_EXAMPLES + SUBDIRS += examples +diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am +index 49720db..633f9d4 100644 +--- a/src/polkitagent/Makefile.am ++++ b/src/polkitagent/Makefile.am +@@ -79,6 +79,7 @@ libpolkit_agent_1_la_LIBADD = \ + + libpolkit_agent_1_la_LDFLAGS = -export-symbols-regex '(^polkit_.*)' + ++if !POLKIT_AUTHFW_NONE + libprivdir = $(prefix)/lib/polkit-1 + libpriv_PROGRAMS = polkit-agent-helper-1 + +@@ -113,6 +114,8 @@ polkit_agent_helper_1_LDFLAGS = \ + $(AM_LDFLAGS) \ + $(NULL) + ++endif # !POLKIT_AUTHFW_NONE ++ + if HAVE_INTROSPECTION + + girdir = $(INTROSPECTION_GIRDIR) +@@ -142,6 +145,7 @@ include $(INTROSPECTION_MAKEFILE) + + endif # HAVE_INTROSPECTION + ++if !POLKIT_AUTHFW_NONE + # polkit-agent-helper-1 need to be setuid root because it's used to + # authenticate not only the invoking user, but possibly also root + # and/or other users. +@@ -149,6 +153,7 @@ endif # HAVE_INTROSPECTION + install-data-hook: + -chown root $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 + -chmod 4755 $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 ++endif # !POLKIT_AUTHFW_NONE + + EXTRA_DIST = polkitagentmarshal.list polkitagentenumtypes.h.template polkitagentenumtypes.c.template + CLEANFILES = $(gir_DATA) $(typelibs_DATA) +diff --git a/test/Makefile.am b/test/Makefile.am +index 59d0680..d43b0fe 100644 +--- a/test/Makefile.am ++++ b/test/Makefile.am +@@ -1,7 +1,11 @@ + +-SUBDIRS = mocklibc . polkit polkitbackend ++SUBDIRS = mocklibc . polkit + AM_CFLAGS = $(GLIB_CFLAGS) + ++if BUILD_POLKITD ++SUBDIRS += polkitbackend ++endif ++ + noinst_LTLIBRARIES = libpolkit-test-helper.la + libpolkit_test_helper_la_SOURCES = polkittesthelper.c polkittesthelper.h + libpolkit_test_helper_la_LIBADD = $(GLIB_LIBS) +-- +2.21.0 diff --git a/subprojects/live-chart b/subprojects/live-chart index 5f8ddce7..1c090e18 160000 --- a/subprojects/live-chart +++ b/subprojects/live-chart @@ -1 +1 @@ -Subproject commit 5f8ddce715f6a9130955bc5f08437050265a317c +Subproject commit 1c090e18fa4ae9f3ccfe0f38d619ebeccd7d6361 From 8ff18f76007507975f83803bd634cdc0138f3ae4 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 15 Feb 2023 21:54:54 +0100 Subject: [PATCH 11/36] [Flatpak]: add libXNVCtrl module --- ...itor.json => com.github.stsdc.monitor.json | 64 ++++++--- flatpak/patches/libxnvctrl_so_0.patch | 39 ++++++ flatpak/polkit-autogen | 4 - ...-Add-option-to-build-without-polkitd.patch | 131 ------------------ subprojects/live-chart | 2 +- 5 files changed, 88 insertions(+), 152 deletions(-) rename flatpak/com.github.stsdc.monitor.json => com.github.stsdc.monitor.json (69%) create mode 100644 flatpak/patches/libxnvctrl_so_0.patch delete mode 100644 flatpak/polkit-autogen delete mode 100644 flatpak/polkit-build-Add-option-to-build-without-polkitd.patch diff --git a/flatpak/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json similarity index 69% rename from flatpak/com.github.stsdc.monitor.json rename to com.github.stsdc.monitor.json index 4232028c..9a9eaf95 100644 --- a/flatpak/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -39,30 +39,31 @@ ], "modules": [ { - "name" : "pam", - "config-opts" : [ - "--includedir=/app/include/security", - "--disable-doc" + "name": "pam", + "config-opts": [ + "--includedir=/app/include/security", + "--disable-doc" ], - "sources" : [ - { - "type" : "archive", - "url" : "https://github.com/linux-pam/linux-pam/releases/download/v1.4.0/Linux-PAM-1.4.0.tar.xz", - "sha256" : "cd6d928c51e64139be3bdb38692c68183a509b83d4f2c221024ccd4bcddfd034" - } + "sources": [ + { + "type": "archive", + "url": "https://github.com/linux-pam/linux-pam/releases/download/v1.4.0/Linux-PAM-1.4.0.tar.xz", + "sha256": "cd6d928c51e64139be3bdb38692c68183a509b83d4f2c221024ccd4bcddfd034" + } ] - }, + }, { "name": "polkit", "buildsystem": "meson", "config-opts": [ - "-Dlibs-only=true" - ], + "-Dlibs-only=true", + "-Dauthfw=pam" + ], "sources": [ { "type": "git", - "url": "https://gitlab.freedesktop.org/polkit/polkit.git", - "tag": "122" + "url": "https://gitlab.freedesktop.org/stsdc/polkit.git", + "branch": "polkit-agent-building-option" } ] }, @@ -79,7 +80,8 @@ "--enable-vdo=no", "--enable-zram=no", "--with-systemdsystemunitdir=no", - "--with-tmpfilesdir=no" + "--with-tmpfilesdir=no", + "--disable-daemon" ], "sources": [ { @@ -150,6 +152,36 @@ } ] }, + { + "name": "libNVCtrl", + "build-options": { + "env": { + "LIB": "lib/x86_64-linux-gnu" + } + }, + "no-autogen": true, + "no-make-install": true, + + "subdir": "src/libXNVCtrl", + "sources": [ + { + "type": "archive", + "archive-type": "tar", + "url": "https://api.github.com/repos/NVIDIA/nvidia-settings/tarball/refs/tags/470.63.01", + "sha256": "0ede63515851d85ac0d1ed5f00e355f539968e6d1fd226120a27b2c66c3575de" + }, + { + "type": "patch", + "path": "flatpak/patches/libxnvctrl_so_0.patch", + "x-checker-data": { + "type": "json", + "url": "https://api.github.com/repos/NVIDIA/nvidia-settings/tags", + "url-query": ".[0].tarball_url", + "version-query": ".[0].name" + } + } + ] + }, { "name": "com.github.stsdc.monitor", "buildsystem": "meson", diff --git a/flatpak/patches/libxnvctrl_so_0.patch b/flatpak/patches/libxnvctrl_so_0.patch new file mode 100644 index 00000000..279ae92f --- /dev/null +++ b/flatpak/patches/libxnvctrl_so_0.patch @@ -0,0 +1,39 @@ +diff -up nvidia-settings-435.17/src/libXNVCtrl/Makefile.shared nvidia-settings-435.17/src/libXNVCtrl/Makefile +--- nvidia-settings-435.17/src/libXNVCtrl/Makefile.shared 2019-08-07 06:12:32.000000000 +0200 ++++ nvidia-settings-435.17/src/libXNVCtrl/Makefile 2019-08-26 16:23:41.921778088 +0200 +@@ -50,8 +50,9 @@ LDFLAGS += $(XNVCTRL_LDFLAGS) + + .PHONY: clean + +-all: $(LIBXNVCTRL) ++all: $(LIBXNVCTRL) libXNVCtrl.so + + clean: + rm -rf $(LIBXNVCTRL) *~ \ + $(OUTPUTDIR)/*.o $(OUTPUTDIR)/*.d ++ rm -f libXNVCtrl.so libXNVCtrl.so.* +diff -up nvidia-settings-435.17/src/Makefile.shared nvidia-settings-435.17/src/Makefile +--- nvidia-settings-435.17/src/Makefile.shared 2019-08-07 06:12:31.000000000 +0200 ++++ nvidia-settings-435.17/src/Makefile 2019-08-26 16:17:31.133406921 +0200 +@@ -106,6 +106,9 @@ endif + XNVCTRL_DIR ?= libXNVCtrl + XCONFIG_PARSER_DIR ?= XF86Config-parser + COMMON_UTILS_DIR ?= common-utils ++XNVCTRL_SHARED ?= $(XNVCTRL_DIR)/libXNVCtrl.so.0 ++#XNVCTRL_LIB ?= $(XNVCTRL_ARCHIVE) ++XNVCTRL_LIB ?= $(XNVCTRL_SHARED) + COMMON_UNIX_DIR ?= common-unix + VIRTUAL_RESOLUTIONS_DIR ?= $(COMMON_UNIX_DIR)/virtual-resolutions + +diff -up nvidia-settings-435.17/src/libXNVCtrl/xnvctrl.mk.shared nvidia-settings-435.17/src/libXNVCtrl/xnvctrl.mk +--- nvidia-settings-435.17/src/libXNVCtrl/xnvctrl.mk.shared 2019-08-07 06:12:32.000000000 +0200 ++++ nvidia-settings-435.17/src/libXNVCtrl/xnvctrl.mk 2019-08-26 16:54:44.518016474 +0200 +@@ -47,3 +47,8 @@ $(eval $(call DEFINE_OBJECT_RULE,TARGET, + + $(LIBXNVCTRL) : $(LIBXNVCTRL_OBJ) + $(call quiet_cmd,AR) ru $@ $(LIBXNVCTRL_OBJ) ++ ++libXNVCtrl.so: $(LIBXNVCTRL_OBJ) ++ $(CC) -shared -Wl,-soname=$@.0 -o $@.0.0.0 $(LDFLAGS) $^ -lXext -lX11 ++ ln -s $@.0.0.0 $@.0 ++ ln -s $@.0 $@ diff --git a/flatpak/polkit-autogen b/flatpak/polkit-autogen deleted file mode 100644 index 3ba457e5..00000000 --- a/flatpak/polkit-autogen +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -gtkdocize --flavour no-tmpl -autoreconf -if diff --git a/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch b/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch deleted file mode 100644 index 9b1a56d8..00000000 --- a/flatpak/polkit-build-Add-option-to-build-without-polkitd.patch +++ /dev/null @@ -1,131 +0,0 @@ -From 1073a44277316348d40d86ecec908f1d4812f360 Mon Sep 17 00:00:00 2001 -From: Christian Hergert -Date: Mon, 27 May 2019 11:49:09 -0700 -Subject: [PATCH] flatpak: make polkit suitable for use within flatpak - -This is based on patches from Patrick Griffis with additional fixes -to allow us to disable use of PAM within Flaptak. ---- - configure.ac | 20 ++++++++++++++++---- - src/Makefile.am | 6 +++++- - src/polkitagent/Makefile.am | 5 +++++ - test/Makefile.am | 6 +++++- - 4 files changed, 31 insertions(+), 6 deletions(-) - -diff --git a/configure.ac b/configure.ac -index 5cedb4e..729d78d 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -79,11 +79,13 @@ PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) - AC_SUBST(GLIB_CFLAGS) - AC_SUBST(GLIB_LIBS) - --PKG_CHECK_MODULES(LIBJS, [mozjs-60]) -+AS_IF([test x${enable_polkitd} = yes], [ -+ PKG_CHECK_MODULES(LIBJS, [mozjs-60]) - --AC_SUBST(LIBJS_CFLAGS) --AC_SUBST(LIBJS_CXXFLAGS) --AC_SUBST(LIBJS_LIBS) -+ AC_SUBST(LIBJS_CFLAGS) -+ AC_SUBST(LIBJS_CXXFLAGS) -+ AC_SUBST(LIBJS_LIBS) -+]) - - EXPAT_LIB="" - AC_ARG_WITH(expat, [ --with-expat= Use expat from here], -@@ -236,6 +238,15 @@ if test "x$with_systemdsystemunitdir" != "xno"; then - fi - AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$systemdsystemunitdir"]) - -+dnl --------------------------------------------------------------------------- -+dnl - Disable polkitd when using library alone -+dnl --------------------------------------------------------------------------- -+ -+AC_ARG_ENABLE([polkitd], -+ [AS_HELP_STRING([--disable-polkitd], [Do not build polkitd])], -+ [enable_polkitd=$enableval], [enable_polkitd=yes]) -+AM_CONDITIONAL(BUILD_POLKITD, [test x${enable_polkitd} = yes]) -+ - dnl --------------------------------------------------------------------------- - dnl - User for running polkitd - dnl --------------------------------------------------------------------------- -@@ -579,6 +590,7 @@ echo " - Session tracking: ${SESSION_TRACKING} - PAM support: ${have_pam} - systemdsystemunitdir: ${systemdsystemunitdir} -+ polkitd: ${enable_polkitd} - polkitd user: ${POLKITD_USER}" - - if test "$have_pam" = yes ; then -diff --git a/src/Makefile.am b/src/Makefile.am -index 09fc7b3..c6fe91b 100644 ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -1,5 +1,9 @@ - --SUBDIRS = polkit polkitbackend polkitagent programs -+SUBDIRS = polkit polkitagent programs -+ -+if BUILD_POLKITD -+SUBDIRS += polkitbackend -+endif - - if BUILD_EXAMPLES - SUBDIRS += examples -diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am -index 49720db..633f9d4 100644 ---- a/src/polkitagent/Makefile.am -+++ b/src/polkitagent/Makefile.am -@@ -79,6 +79,7 @@ libpolkit_agent_1_la_LIBADD = \ - - libpolkit_agent_1_la_LDFLAGS = -export-symbols-regex '(^polkit_.*)' - -+if !POLKIT_AUTHFW_NONE - libprivdir = $(prefix)/lib/polkit-1 - libpriv_PROGRAMS = polkit-agent-helper-1 - -@@ -113,6 +114,8 @@ polkit_agent_helper_1_LDFLAGS = \ - $(AM_LDFLAGS) \ - $(NULL) - -+endif # !POLKIT_AUTHFW_NONE -+ - if HAVE_INTROSPECTION - - girdir = $(INTROSPECTION_GIRDIR) -@@ -142,6 +145,7 @@ include $(INTROSPECTION_MAKEFILE) - - endif # HAVE_INTROSPECTION - -+if !POLKIT_AUTHFW_NONE - # polkit-agent-helper-1 need to be setuid root because it's used to - # authenticate not only the invoking user, but possibly also root - # and/or other users. -@@ -149,6 +153,7 @@ endif # HAVE_INTROSPECTION - install-data-hook: - -chown root $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 - -chmod 4755 $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 -+endif # !POLKIT_AUTHFW_NONE - - EXTRA_DIST = polkitagentmarshal.list polkitagentenumtypes.h.template polkitagentenumtypes.c.template - CLEANFILES = $(gir_DATA) $(typelibs_DATA) -diff --git a/test/Makefile.am b/test/Makefile.am -index 59d0680..d43b0fe 100644 ---- a/test/Makefile.am -+++ b/test/Makefile.am -@@ -1,7 +1,11 @@ - --SUBDIRS = mocklibc . polkit polkitbackend -+SUBDIRS = mocklibc . polkit - AM_CFLAGS = $(GLIB_CFLAGS) - -+if BUILD_POLKITD -+SUBDIRS += polkitbackend -+endif -+ - noinst_LTLIBRARIES = libpolkit-test-helper.la - libpolkit_test_helper_la_SOURCES = polkittesthelper.c polkittesthelper.h - libpolkit_test_helper_la_LIBADD = $(GLIB_LIBS) --- -2.21.0 diff --git a/subprojects/live-chart b/subprojects/live-chart index 1c090e18..5f8ddce7 160000 --- a/subprojects/live-chart +++ b/subprojects/live-chart @@ -1 +1 @@ -Subproject commit 1c090e18fa4ae9f3ccfe0f38d619ebeccd7d6361 +Subproject commit 5f8ddce715f6a9130955bc5f08437050265a317c From d92477a1803e23ef1053d81c32d087196317ef28 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 15 Feb 2023 22:00:02 +0100 Subject: [PATCH 12/36] [Flatpak]: Fix installing path for libNVCtrl --- com.github.stsdc.monitor.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json index 9a9eaf95..4de0cd58 100644 --- a/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -161,7 +161,11 @@ }, "no-autogen": true, "no-make-install": true, - + "build-commands": [ + "mkdir -p ${FLATPAK_DEST}/lib", + "cp -a libXNVCtrl.so* ${FLATPAK_DEST}/lib/", + "install -D *.h -t ${FLATPAK_DEST}/include/NVCtrl" + ], "subdir": "src/libXNVCtrl", "sources": [ { From 15f6e12acd0d15e8b31b25a62743e7737613829a Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 15 Feb 2023 22:16:38 +0100 Subject: [PATCH 13/36] [Flatpak]: Build works --- com.github.stsdc.monitor.json | 5 +- data/com.github.stsdc.monitor.appdata.xml.in | 113 +++++++++---------- 2 files changed, 58 insertions(+), 60 deletions(-) diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json index 4de0cd58..3a690de8 100644 --- a/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -5,17 +5,16 @@ "sdk": "io.elementary.Sdk", "command": "com.github.stsdc.monitor", "finish-args": [ - "--allow=devel", "--share=ipc", "--socket=fallback-x11", - "--device=dri", "--socket=wayland", "--socket=system-bus", "--device=all", "--share=network", "--talk-name=org.freedesktop.Flatpak", "--system-talk-name=org.freedesktop.Accounts", - "--system-talk-name=org.freedesktop.UDisks2" + "--system-talk-name=org.freedesktop.UDisks2", + "--filesystem=host:ro" ], "modules": [ { diff --git a/data/com.github.stsdc.monitor.appdata.xml.in b/data/com.github.stsdc.monitor.appdata.xml.in index 738e4be0..1d54f4bd 100644 --- a/data/com.github.stsdc.monitor.appdata.xml.in +++ b/data/com.github.stsdc.monitor.appdata.xml.in @@ -1,5 +1,5 @@ - + com.github.stsdc.monitor CC0 @@ -25,60 +25,59 @@ StanisΕ‚aw Dac https://github.com/stsdc/monitor https://github.com/stsdc/monitor/issues -https://github.com/stsdc/monitor/issues - - - -​ -​

            Add info about drives (based on Dirli's code)

            -​
            -​
            - -​ -​

            Adds dark theme 🌚

            -​
            -​
            - -​ -​

            Uses Wingpanel v3; New *.deb package maintainer: Kristopher Ives

            -​
            -​
            - -​ -​

            πŸ› Should fix empty Indicator. Please reboot after installation ⚑️

            -​
            -​
            - -​ -​
              -
            • πŸ› Try to fix frequent GUI hangs πŸ₯Ά
            • -
            • πŸ‡³πŸ‡± Update Dutch translation (@Vistaus)
            • -
            • πŸ‡΅πŸ‡Ή Update Portuguese translation (@hugok79)
            • -
            • πŸ‡·πŸ‡΄ Add Romanian translation (@tiberiufrat)
            • -
            -​
            -​
            - -​ -​
              -
            • Display Storage usage
            • -
            • Update Russian translation (@camellan)
            • -
            • Update Portuguese translation (@hugok79)
            • -
            • Different colours for Upload and Download
            • -
            -​
            -​
            - -​ -​
              -
            • Update Portuguese translation (@rottenpants466)
            • -
            • Update Dutch translation (@Vistaus)
            • -
            • Smoother animations (@DevAlien)
            • -
            • Preselect first entry so that the info panel is always open (@DevAlien)
            • -
            • Show CPU temperature in the Indicator
            • -
            -​
            -​
            + https://github.com/stsdc/monitor/issues + + + +

            Add info about drives (based on Dirli's code)

            +
            +
            + + +

            Adds dark theme 🌚

            +
            +
            + + +

            Uses Wingpanel v3; New *.deb package maintainer: Kristopher Ives

            +
            +
            + + +

            🐛 Should fix empty Indicator. Please reboot after installation ⚑️

            +
            +
            + + +
              +
            • 🐛 Try to fix frequent GUI hangs 🥶
            • +
            • 🇳🇱 Update Dutch translation (@Vistaus)
            • +
            • 🇵🇹 Update Portuguese translation (@hugok79)
            • +
            • 🇷🇴 Add Romanian translation (@tiberiufrat)
            • +
            +
            +
            + + +
              +
            • Display Storage usage
            • +
            • Update Russian translation (@camellan)
            • +
            • Update Portuguese translation (@hugok79)
            • +
            • Different colours for Upload and Download
            • +
            +
            +
            + + +
              +
            • Update Portuguese translation (@rottenpants466)
            • +
            • Update Dutch translation (@Vistaus)
            • +
            • Smoother animations (@DevAlien)
            • +
            • Preselect first entry so that the info panel is always open (@DevAlien)
            • +
            • Show CPU temperature in the Indicator
            • +
            +
            +
              @@ -119,7 +118,8 @@
            • Update Russian translation (camellan)
            • Add Turkish translation (Harun Yasar)
            • Use newest version of live-chart (Laurent Callarec) ← Check his lib for creating charts, it's amazing!
            • -
            ​ +
          +
          @@ -191,7 +191,6 @@ - ​
          • Minor bug fix
          • Make End process button red
          • From 70eb435f4baf178098bb275fce6609afd226520b Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 30 Nov 2023 23:49:45 +0100 Subject: [PATCH 14/36] Make it compile --- com.github.stsdc.monitor.json | 140 ++++++++++++++++++++++++++++++++- flatpak/patches/snowball.patch | 68 ++++++++++++++++ 2 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 flatpak/patches/snowball.patch diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json index 3a690de8..18350232 100644 --- a/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -1,7 +1,7 @@ { "app-id": "com.github.stsdc.monitor", "runtime": "io.elementary.Platform", - "runtime-version": "6.1", + "runtime-version": "7.3", "sdk": "io.elementary.Sdk", "command": "com.github.stsdc.monitor", "finish-args": [ @@ -11,10 +11,15 @@ "--socket=system-bus", "--device=all", "--share=network", + "--env=XDG_DATA_DIRS=/app/share:/usr/share:/usr/share/runtime/share:/run/host/user-share:/run/host/usr/share:/run/host/share:/var/lib/flatpak/exports/share:~/.local/share/flatpak/exports/share", "--talk-name=org.freedesktop.Flatpak", "--system-talk-name=org.freedesktop.Accounts", "--system-talk-name=org.freedesktop.UDisks2", - "--filesystem=host:ro" + "--filesystem=host:ro", + "--filesystem=/var/lib/flatpak/app:ro", + "--filesystem=/var/lib/flatpak/exports/share:ro", + "--filesystem=xdg-data/flatpak/app:ro", + "--filesystem=xdg-data/flatpak/exports/share:ro" ], "modules": [ { @@ -122,6 +127,137 @@ } ] }, + { + "name": "flatpak", + "config-opts": [ + "--disable-documentation", + "--disable-seccomp", + "--disable-sandboxed-triggers", + "--disable-system-helper", + "--with-system-install-dir=/var/lib/flatpak" + ], + "cleanup": [ + "/etc/profile.d", + "/lib/systemd", + "/share/dbus-1/interfaces/org.freedesktop.*", + "/share/dbus-1/services/org.freedesktop.*", + "/share/gdm" + ], + "post-install": [ + "cp /usr/bin/update-mime-database /app/bin", + "cp /usr/bin/update-desktop-database /app/bin" + ], + "sources": [ + { + "type": "archive", + "url": "https://github.com/flatpak/flatpak/releases/download/1.14.4/flatpak-1.14.4.tar.xz", + "sha256": "8a34dbd0b67c434e7598b98ec690953d046f0db26e480aeafb46d72aec716799", + "x-checker-data": { + "type": "json", + "url": "https://api.github.com/repos/flatpak/flatpak/releases/latest", + "version-query": ".tag_name", + "url-query": "\"https://github.com/flatpak/flatpak/releases/download/\\($version)/flatpak-\\($version).tar.xz\"" + } + } + ], + "modules": [ + { + "name": "snowball", + "buildsystem": "simple", + "sources": [ + { + "type": "archive", + "url": "https://github.com/snowballstem/snowball/archive/refs/tags/v2.2.0.tar.gz", + "sha512": "02c43313de9de2518ea51cfb11f1c29145fc046c7838329bfdefd70b604009ad44b6db8175c25b0db31f03db30a6aec5857aa35775a9c204ec976df9cae62957" + }, + { + "type": "patch", + "paths": [ + "flatpak/patches/snowball.patch" + ] + } + ], + "build-commands": [ + "make libstemmer.so -j$FLATPAK_BUILDER_N_JOBS", + "install -Dm644 include/libstemmer.h /app/include/libstemmer.h", + "install -Dm644 libstemmer.so /app/lib/libstemmer.so.0.0.0", + "ln -s libstemmer.so.0.0.0 /app/lib/libstemmer.so.0", + "ln -s libstemmer.so.0 /app/lib/libstemmer.so" + ] + }, + { + "name": "libfuse", + "buildsystem": "meson", + "config-opts": [ + "-Dexamples=false", + "-Dinitscriptdir=", + "-Duseroot=false", + "-Dtests=false", + "-Dudevrulesdir=/tmp/" + ], + "sources": [ + { + "type": "archive", + "url": "https://github.com/libfuse/libfuse/releases/download/fuse-3.14.1/fuse-3.14.1.tar.xz", + "sha256": "126919d72b46b3e0eb58a9c6933a2a50c36f2ea69f61fe9e78bdba9f463ffa20", + "x-checker-data": { + "type": "anitya", + "project-id": 861, + "url-template": "https://github.com/libfuse/libfuse/releases/download/fuse-$version/fuse-$version.tar.gz", + "versions": { + "<": "4.0" + } + } + } + ] + }, + { + "name": "ostree", + "config-opts": [ + "--disable-man", + "--with-systemdsystemgeneratordir=/app/lib/systemd/system-generators", + "--without-systemdsystemunitdir", + "--with-curl" + ], + "cleanup": [ + "/etc/grub.d", + "/etc/ostree", + "/share/ostree", + "/libexec" + ], + "sources": [ + { + "type": "archive", + "url": "https://github.com/ostreedev/ostree/releases/download/v2023.7/libostree-2023.7.tar.xz", + "sha256": "19cda718705f7ac8c018c939c38b1bb8412deaaa04862da98cd9fe9243f073bf", + "x-checker-data": { + "type": "json", + "url": "https://api.github.com/repos/ostreedev/ostree/releases/latest", + "version-query": ".tag_name", + "url-query": ".assets | first | .browser_download_url" + } + } + ] + }, + { + "name": "python3-pyparsing", + "cleanup": [ + "*" + ], + "buildsystem": "simple", + "build-commands": [ + "pip3 install --prefix=/app pyparsing-2.4.7-py2.py3-none-any.whl" + ], + "sources": [ + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl", + "sha256": "ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" + } + ] + } + ] + }, { "name": "libwnck", "buildsystem": "meson", diff --git a/flatpak/patches/snowball.patch b/flatpak/patches/snowball.patch new file mode 100644 index 00000000..8b30670f --- /dev/null +++ b/flatpak/patches/snowball.patch @@ -0,0 +1,68 @@ + GNUmakefile | 15 +++++++-------- + libstemmer/symbol.map | 6 ++++++ + 2 files changed, 13 insertions(+), 8 deletions(-) + +diff --git c/GNUmakefile i/GNUmakefile +index 98eb1fa..86e4855 100644 +--- c/GNUmakefile ++++ i/GNUmakefile +@@ -170,20 +170,19 @@ C_OTHER_OBJECTS = $(C_OTHER_SOURCES:.c=.o) + JAVA_CLASSES = $(JAVA_SOURCES:.java=.class) + JAVA_RUNTIME_CLASSES=$(JAVARUNTIME_SOURCES:.java=.class) + +-CFLAGS=-O2 -W -Wall -Wmissing-prototypes -Wmissing-declarations +-CPPFLAGS= ++CFLAGS+=-fPIC -W -Wall -Wmissing-prototypes -Wmissing-declarations + + INCLUDES=-Iinclude + +-all: snowball$(EXEEXT) libstemmer.a stemwords$(EXEEXT) $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS) ++all: snowball$(EXEEXT) libstemmer.so stemwords$(EXEEXT) $(C_OTHER_SOURCES) $(C_OTHER_HEADERS) $(C_OTHER_OBJECTS) + + algorithms.mk: libstemmer/mkalgorithms.pl libstemmer/modules.txt + libstemmer/mkalgorithms.pl algorithms.mk libstemmer/modules.txt + + clean: + rm -f $(COMPILER_OBJECTS) $(RUNTIME_OBJECTS) \ + $(LIBSTEMMER_OBJECTS) $(LIBSTEMMER_UTF8_OBJECTS) $(STEMWORDS_OBJECTS) snowball$(EXEEXT) \ +- libstemmer.a stemwords$(EXEEXT) \ ++ libstemmer.so stemwords$(EXEEXT) \ + libstemmer/modules.h \ + libstemmer/modules_utf8.h \ + $(C_LIB_SOURCES) $(C_LIB_HEADERS) $(C_LIB_OBJECTS) \ +@@ -222,19 +221,19 @@ libstemmer/modules_utf8.h libstemmer/mkinc_utf8.mak: libstemmer/mkmodules.pl lib + + libstemmer/libstemmer.o: libstemmer/modules.h $(C_LIB_HEADERS) + +-libstemmer.a: libstemmer/libstemmer.o $(RUNTIME_OBJECTS) $(C_LIB_OBJECTS) +- $(AR) -cru $@ $^ ++libstemmer.so: libstemmer/libstemmer.o $(RUNTIME_OBJECTS) $(C_LIB_OBJECTS) ++ $(CC) $(CFLAGS) -shared $(LDFLAGS) -Wl,-soname,$@,-version-script,libstemmer/symbol.map -o $@ $^ + + examples/%.o: examples/%.c + $(CC) $(CFLAGS) $(INCLUDES) $(CPPFLAGS) -c -o $@ $< + +-stemwords$(EXEEXT): $(STEMWORDS_OBJECTS) libstemmer.a ++stemwords$(EXEEXT): $(STEMWORDS_OBJECTS) libstemmer.so + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + + tests/%.o: tests/%.c + $(CC) $(CFLAGS) $(INCLUDES) $(CPPFLAGS) -c -o $@ $< + +-stemtest$(EXEEXT): $(STEMTEST_OBJECTS) libstemmer.a ++stemtest$(EXEEXT): $(STEMTEST_OBJECTS) libstemmer.so + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + + csharp_stemwords$(EXEEXT): $(CSHARP_STEMWORDS_SOURCES) $(CSHARP_RUNTIME_SOURCES) $(CSHARP_SOURCES) +diff --git c/libstemmer/symbol.map i/libstemmer/symbol.map +new file mode 100644 +index 0000000..7a3d423 +--- /dev/null ++++ i/libstemmer/symbol.map +@@ -0,0 +1,6 @@ ++SB_STEMMER_0 { ++ global: ++ sb_stemmer_*; ++ local: ++ *; ++}; From aa43cef87da046eb0102246eaf44b8d0a264e287 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:15:46 +0100 Subject: [PATCH 15/36] there is an attempt --- src/Managers/Process.vala | 60 ++++++++-------- src/Managers/ProcessFlatpak.vala | 23 ++++++ src/Managers/ProcessManager.vala | 30 ++++++-- src/Managers/ProcessProvider.vala | 109 ++++++++++++++++++++++++++++ src/Managers/ProcessUtils.vala | 113 ++++++++++++++++++++++++++++-- src/meson.build | 2 + subprojects/stylesheet | 2 +- 7 files changed, 301 insertions(+), 38 deletions(-) create mode 100644 src/Managers/ProcessFlatpak.vala create mode 100644 src/Managers/ProcessProvider.vala diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index ff55c5f1..dafcca68 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -81,13 +81,11 @@ public class Monitor.Process : GLib.Object { stat.pid = _pid; // getting uid - GTop.ProcUid proc_uid; - GTop.get_proc_uid (out proc_uid, stat.pid); - uid = proc_uid.uid; - + get_uid (); // getting username - // @TOFIX: Can't get username for postgres when started from docker (?) + // @TOFIX: Can't get username for postgres which + // is started from docker (?) unowned Posix.Passwd passwd = Posix.getpwuid (uid); if (passwd != null) { username = passwd.pw_name; @@ -98,6 +96,12 @@ public class Monitor.Process : GLib.Object { get_usage (0, 1); } + private void get_uid () { + GTop.ProcUid proc_uid; + GTop.get_proc_uid (out proc_uid, stat.pid); + uid = proc_uid.uid; + } + // Updates the process to get latest information // Returns if the update was successful @@ -105,9 +109,9 @@ public class Monitor.Process : GLib.Object { exists = parse_stat (); if (exists) { get_usage (cpu_total, cpu_last_total); - parse_io (); - parse_statm (); - get_open_files (); + // parse_io (); + // parse_statm (); + // get_open_files (); } return exists; } @@ -251,26 +255,26 @@ public class Monitor.Process : GLib.Object { } private bool get_open_files () { - try { - string directory = "/proc/%d/fd".printf (stat.pid); - Dir dir = Dir.open (directory, 0); - string ? name = null; - while ((name = dir.read_name ()) != null) { - string path = Path.build_filename (directory, name); - - if (FileUtils.test (path, FileTest.IS_SYMLINK)) { - string real_path = FileUtils.read_link (path); - // debug(content); - open_files_paths.add (real_path); - } - } - } catch (FileError err) { - if (err is FileError.ACCES) { - fd_permission_error (err.message); - } else { - warning (err.message); - } - } + // try { + // string directory = "/proc/%d/fd".printf (stat.pid); + // Dir dir = Dir.open (directory, 0); + // string ? name = null; + // while ((name = dir.read_name ()) != null) { + // string path = Path.build_filename (directory, name); + + // if (FileUtils.test (path, FileTest.IS_SYMLINK)) { + // string real_path = FileUtils.read_link (path); + // // debug(content); + // open_files_paths.add (real_path); + // } + // } + // } catch (FileError err) { + // if (err is FileError.ACCES) { + // fd_permission_error (err.message); + // } else { + // warning (err.message); + // } + // } return true; } diff --git a/src/Managers/ProcessFlatpak.vala b/src/Managers/ProcessFlatpak.vala new file mode 100644 index 00000000..a6f72462 --- /dev/null +++ b/src/Managers/ProcessFlatpak.vala @@ -0,0 +1,23 @@ +public class Monitor.ProcessFlatpak : Process { + public ProcessFlatpak (int _pid) { + base (_pid); + } + // Kills the process + public new bool kill () { + // Sends a kill signal that cannot be ignored + if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) { + return true; + } + return false; + } + + // Ends the process + public new bool end () { + // Sends a terminate signal + if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { + return true; + } + return false; + } + +} diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index b2d38659..3cd06b2d 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -135,14 +135,34 @@ namespace Monitor { // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, uid); - for (int i = 0; i < proclist.number; i++) { - int pid = pids[i]; + if (ProcessUtils.is_flatpak_env ()) { + var pp = ProcessProvider.get_default (); + var pp_pids = pp.get_pids (); - if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { - add_process (pid); + // foreach (var pid in pp_pids) { + // debug ("yeah %d", pid); + // } + + debug ("Size %u", pp_pids.length ()); + + foreach (int pid in pp_pids) { + if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { + add_process (pid); + } } + debug ("process_list size %u", process_list.size); + } else { + // for (int i = 0; i < proclist.number; i++) { + // int pid = pids[i]; + + // if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { + // add_process (pid); + // } + // } } + + cpu_last_used = used; cpu_last_total = cpu_data.total; cpu_last_useds = useds; @@ -225,7 +245,7 @@ namespace Monitor { return true; } // some processes have semicolon in command - // do not sanitizing to improve readability + // do not sanitize to improve readability else if (process.command.split (" ")[0].contains (":")) { process.application_name = process.command; return true; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala new file mode 100644 index 00000000..abcb4d66 --- /dev/null +++ b/src/Managers/ProcessProvider.vala @@ -0,0 +1,109 @@ +namespace Monitor { + public class ProcessProvider { + private static GLib.Once instance; + public static unowned ProcessProvider get_default () { + return instance.once (() => { return new ProcessProvider (); }); + } + + public Gee.HashSet pids = new Gee.HashSet (); + + public ProcessProvider () { + } + + public GLib.List get_pids () { + var new_pids = new GLib.List (); + + try { + string[] spawn_args = { "flatpak-spawn", "--host", "ls" }; + string[] spawn_env = Environ.get (); + Pid child_pid; + + int standard_input; + int standard_output; + int standard_error; + + + string ls_stdout; + string ls_stderr; + int ls_status; + + // GLib.Process.spawn_async_with_pipes + // ( + // "/proc/", + // spawn_args, + // spawn_env, + // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, + // null, + // out child_pid, + // out standard_input, + // out standard_output, + // out standard_error + // ); + + GLib.Process.spawn_command_line_sync ( + "flatpak-spawn --host ls /proc/", + out ls_stdout, + out ls_stderr, + out ls_status); + + // stdout: + // IOChannel output = new IOChannel.unix_new (standard_output); + // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + // return process_line (channel, condition, new_pids); + // }); + + //// stderr: + // IOChannel error = new IOChannel.unix_new (standard_error); + // error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + //// return process_line (channel, condition, "stderr"); + // return true; + // }); + + // ChildWatch.add (child_pid, (pid, status) => { + ////// Triggered when the child indicated by child_pid exits + // GLib.Process.close_pid (pid); + //// loop.quit (); + // }); + + // debug (ls_stdout); + foreach (var line in ls_stdout.strip ().split ("\n")) { + if (line[0].isdigit ()) { + // print ("---->" + line + "\n"); + new_pids.append (int.parse (line)); + } + } + + + } catch (SpawnError e) { + error ("Error: %s\n", e.message); + } + return new_pids; + } + + private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { + if (condition == IOCondition.HUP) { + // debug ("%s: The fd has been closed.\n", stream_name); + return false; + } + + try { + string line; + channel.read_line (out line, null, null); + if (line[0].isdigit ()) { + print ("%d\n", int.parse (line)); + // pids.add (line.strip ()); + + } + } catch (IOChannelError e) { + warning ("IOChannelError: %s\n", e.message); + return false; + } catch (ConvertError e) { + warning ("ConvertError: %s\n", e.message); + return false; + } + + return true; + } + + } +} diff --git a/src/Managers/ProcessUtils.vala b/src/Managers/ProcessUtils.vala index 31807093..8fce4ac2 100644 --- a/src/Managers/ProcessUtils.vala +++ b/src/Managers/ProcessUtils.vala @@ -15,18 +15,26 @@ public class Monitor.ProcessUtils { var splitted_commandline = commandline.split (" "); // check if started by any shell - if (is_shell (splitted_commandline[0]) || is_python (splitted_commandline[0]) ) { + if (is_shell (splitted_commandline[0]) || is_python (splitted_commandline[0])) { return commandline; } - // if (!splitted_commandline[0].contains ("/")) { - // return commandline; - // } + // if (!splitted_commandline[0].contains ("/")) { + // return commandline; + // } return splitted_commandline[0]; } public static string ? read_file (string path) { + if (ProcessUtils.is_flatpak_env ()) { + return ProcessUtils.read_file_on_host (path); + } + + return ProcessUtils.read_file_native (path); + } + + public static string ? read_file_native (string path) { var file = File.new_for_path (path); /* make sure that it exists, not an error if it doesn't */ @@ -54,6 +62,93 @@ public class Monitor.ProcessUtils { } } + public static string ? read_file_on_host (string path) { + string stdout; + string stderr; + string stdin; + int status; + + int standard_input; + int standard_output; + int standard_error; + + + string command = "flatpak-spawn --host cat " + path; + string[] spawn_args = { "flatpak-spawn", "--host", "env", "LANG=C", "cat", path }; + Pid child_pid; + + try { + // string command = "flatpak-spawn --host cat " + path + " | grep -av DEBUG"; + debug (command); + GLib.Process.spawn_command_line_sync + ( + command, + out stdout, + out stderr, + out status + ); + + + // GLib.Process.spawn_async_with_pipes + // ("/", + // spawn_args, + // Environ.get (), + // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, + // null, + // out child_pid, + // out standard_input, + // out standard_output, + // out standard_error + // ); + // debug ("Status: %d", status); + } catch (SpawnError e) { + error (e.message); + } + // IOChannel output = new IOChannel.unix_new (standard_output); + // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + // if (condition == IOCondition.HUP) { + // print ("%s: The fd has been closed.\n", "stream_name"); + // return false; + // } + + // try { + // string line; + // channel.read_line (out line, null, null); + // print ("%s: %s", "stream_name", line); + // } catch (IOChannelError e) { + // print ("%s: IOChannelError: %s\n", "stream_name", e.message); + // return false; + // } catch (ConvertError e) { + // print ("%s: ConvertError: %s\n", "stream_name", e.message); + // return false; + // } + + // return true; + // }); + + // ChildWatch.add (child_pid, (pid, status) => { + // // Triggered when the child indicated by child_pid exits + // GLib.Process.close_pid (pid); + // }); + + + string ? stdout_no_debug = ""; + + if (stdout == "" || status != 0) { + warning ("Tried to execute %s, but got null. Status: %d", command, status); + return null; + } + + foreach (var line in stdout.split ("\n")) { + if (!line.contains ("DEBUG")) { + stdout_no_debug += line + "\n"; + } + } + // print (stdout_no_debug); + // return null; + return stdout_no_debug; + } + public static Icon ? get_default_icon () { try { return Icon.new_for_string ("application-x-executable"); @@ -62,4 +157,14 @@ public class Monitor.ProcessUtils { return null; } } + + public static bool is_flatpak_env () { + string environment = GLib.Environment.get_variable ("container"); + // debug ("Monitor is running in %s environment", environment); + if (environment == "flatpak") { + return true; + } + return false; + } + } diff --git a/src/meson.build b/src/meson.build index 24ef83a5..cd68b508 100644 --- a/src/meson.build +++ b/src/meson.build @@ -52,11 +52,13 @@ source_app_files = [ # 'Managers/AppManager.vala', 'Managers/ProcessManager.vala', 'Managers/Process.vala', + 'Managers/ProcessFlatpak.vala', 'Managers/ProcessStructs.vala', 'Managers/ProcessUtils.vala', 'Managers/HttpClientAsync.vala', 'Managers/ContainerManager.vala', 'Managers/Container.vala', + 'Managers/ProcessProvider.vala', # Services 'Services/Shortcuts.vala', diff --git a/subprojects/stylesheet b/subprojects/stylesheet index da0c4196..a8b3c703 160000 --- a/subprojects/stylesheet +++ b/subprojects/stylesheet @@ -1 +1 @@ -Subproject commit da0c4196ce246c6506a8a709f4140a098796fd4f +Subproject commit a8b3c70331f983ed9a2568817188df15a257e319 From 787e3198bd2ebc9473dce67610d45e588a1d13d3 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:18:26 +0100 Subject: [PATCH 16/36] . --- flatpak/workaround/process_monitor.py | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 flatpak/workaround/process_monitor.py diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py new file mode 100644 index 00000000..78bc9ea7 --- /dev/null +++ b/flatpak/workaround/process_monitor.py @@ -0,0 +1,35 @@ +import os + +import dbus +import dbus.service +import dbus.mainloop.glib +from gi.repository import GLib + + +def get_pids(): + # Define the path to the directory + path = '/proc' + + # Get a list of all directories in the path + directories = [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))] + + # Filter out directories that contain only numbers in their names + return [d for d in directories if d.isnumeric()] + + +class HelloWorld(dbus.service.Object): + def __init__(self, conn=None, object_path=None, bus_name=None): + dbus.service.Object.__init__(self, conn, object_path, bus_name) + + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="as", sender_keyword="sender", connection_keyword="conn") + def get_processes(self, name, sender=None, conn=None): + return get_pids() + +if __name__ == "__main__": + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + bus = dbus.SessionBus() + name = dbus.service.BusName("com.github.stsdc.monitor.workaround", bus) + helloworld = HelloWorld(bus, "/processes") + mainloop = GLib.MainLoop() + mainloop.run() + From 69e199cda1e49a6092ac007e4f1e0b0733dad809 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:33:40 +0100 Subject: [PATCH 17/36] . --- com.github.stsdc.monitor.json | 10 ++++++++- flatpak/workaround/process_monitor.py | 29 +++++++++++++++++++++++++-- src/Managers/Process.vala | 6 +++--- src/Managers/ProcessProvider.vala | 2 +- src/Managers/ProcessUtils.vala | 6 +++--- subprojects/stylesheet | 2 +- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json index 18350232..1195471a 100644 --- a/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -8,18 +8,26 @@ "--share=ipc", "--socket=fallback-x11", "--socket=wayland", + "--socket=session-bus", "--socket=system-bus", + "--device=shm", "--device=all", "--share=network", "--env=XDG_DATA_DIRS=/app/share:/usr/share:/usr/share/runtime/share:/run/host/user-share:/run/host/usr/share:/run/host/share:/var/lib/flatpak/exports/share:~/.local/share/flatpak/exports/share", "--talk-name=org.freedesktop.Flatpak", + "--talk-name=com.github.stsdc.monitor", "--system-talk-name=org.freedesktop.Accounts", "--system-talk-name=org.freedesktop.UDisks2", "--filesystem=host:ro", "--filesystem=/var/lib/flatpak/app:ro", "--filesystem=/var/lib/flatpak/exports/share:ro", "--filesystem=xdg-data/flatpak/app:ro", - "--filesystem=xdg-data/flatpak/exports/share:ro" + "--filesystem=xdg-data/flatpak/exports/share:ro", + "--filesystem=/run/docker.sock", + "--filesystem=xdg-run/docker.sock", + "--filesystem=/run/podman/podman.sock", + "--filesystem=xdg-run/podman/podman.sock", + "--filesystem=/tmp" ], "modules": [ { diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index 78bc9ea7..49d19ade 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -16,14 +16,39 @@ def get_pids(): # Filter out directories that contain only numbers in their names return [d for d in directories if d.isnumeric()] +def get_processes_stats(): + processes = [] + for pid in get_pids(): + process = [pid] + with open(f'/proc/{pid}/stat', 'r') as file: + process.append(file.read()) + processes.append(process) + return processes + class HelloWorld(dbus.service.Object): def __init__(self, conn=None, object_path=None, bus_name=None): dbus.service.Object.__init__(self, conn, object_path, bus_name) - @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="as", sender_keyword="sender", connection_keyword="conn") + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="aas", sender_keyword="sender", connection_keyword="conn") def get_processes(self, name, sender=None, conn=None): - return get_pids() + processes = [] + for pid in get_pids(): + process = [pid] + with open(f'/proc/{pid}/cmdline', 'rb') as file: + process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) + with open(f'/proc/{pid}/stat', 'rb') as file: + process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) + with open(f'/proc/{pid}/statm', 'rb') as file: + process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) + try: + with open(f'/proc/{pid}/io', 'r') as file: + process.append(file.read()) + except PermissionError as err: + # print(err) + pass + processes.append(process) + return processes if __name__ == "__main__": dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index dafcca68..1dfd1a1a 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -135,7 +135,7 @@ public class Monitor.Process : GLib.Object { } private bool get_children_pids () { - string ? children_content = ProcessUtils.read_file ("/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); + string ? children_content = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); if (children_content == "" || children_content == null) { return false; } @@ -201,7 +201,7 @@ public class Monitor.Process : GLib.Object { // Reads the /proc/%pid%/stat file and updates the process with the information therein. private bool parse_stat () { - string ? stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); + string ? stat_contents = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/stat".printf (stat.pid)); if (stat_contents == null) { return false; @@ -282,7 +282,7 @@ public class Monitor.Process : GLib.Object { * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ private bool read_cmdline () { - string ? cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); + string ? cmdline = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/cmdline".printf (stat.pid)); if (cmdline == null) { return false; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index abcb4d66..a888808d 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -41,7 +41,7 @@ namespace Monitor { // ); GLib.Process.spawn_command_line_sync ( - "flatpak-spawn --host ls /proc/", + "ls /tmp/fakeproc/proc/", out ls_stdout, out ls_stderr, out ls_status); diff --git a/src/Managers/ProcessUtils.vala b/src/Managers/ProcessUtils.vala index 8fce4ac2..8eb9ed4a 100644 --- a/src/Managers/ProcessUtils.vala +++ b/src/Managers/ProcessUtils.vala @@ -27,9 +27,9 @@ public class Monitor.ProcessUtils { } public static string ? read_file (string path) { - if (ProcessUtils.is_flatpak_env ()) { - return ProcessUtils.read_file_on_host (path); - } + // if (ProcessUtils.is_flatpak_env ()) { + // return ProcessUtils.read_file_on_host (path); + // } return ProcessUtils.read_file_native (path); } diff --git a/subprojects/stylesheet b/subprojects/stylesheet index a8b3c703..fbe2b247 160000 --- a/subprojects/stylesheet +++ b/subprojects/stylesheet @@ -1 +1 @@ -Subproject commit a8b3c70331f983ed9a2568817188df15a257e319 +Subproject commit fbe2b24704bbfd489152350627033295b3770a38 From 8f7c929f38eae0d7d0b6547d45aa40df56dd0df9 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:01:04 +0100 Subject: [PATCH 18/36] parse data from python --- flatpak/workaround/process_monitor.py | 39 +++++++++++++++----------- src/MainWindow.vala | 7 +++++ src/Services/DBusWorkaroundClient.vala | 39 ++++++++++++++++++++++++++ src/meson.build | 1 + 4 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 src/Services/DBusWorkaroundClient.vala diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index 49d19ade..02519e0c 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -5,7 +5,6 @@ import dbus.mainloop.glib from gi.repository import GLib - def get_pids(): # Define the path to the directory path = '/proc' @@ -27,26 +26,34 @@ def get_processes_stats(): class HelloWorld(dbus.service.Object): + def __init__(self, conn=None, object_path=None, bus_name=None): dbus.service.Object.__init__(self, conn, object_path, bus_name) - @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="aas", sender_keyword="sender", connection_keyword="conn") - def get_processes(self, name, sender=None, conn=None): + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="aa{ss}", sender_keyword="sender", connection_keyword="conn") + def GetProcesses(self, name, sender=None, conn=None): + print("GetProcesses") processes = [] for pid in get_pids(): - process = [pid] + process = { + "pid": pid, + "cmdline": "", + "stat": "", + "statm": "", + "io": "" + } with open(f'/proc/{pid}/cmdline', 'rb') as file: - process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) - with open(f'/proc/{pid}/stat', 'rb') as file: - process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) - with open(f'/proc/{pid}/statm', 'rb') as file: - process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) - try: - with open(f'/proc/{pid}/io', 'r') as file: - process.append(file.read()) - except PermissionError as err: - # print(err) - pass + process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', '')) + # with open(f'/proc/{pid}/stat', 'rb') as file: + # process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) + # with open(f'/proc/{pid}/statm', 'rb') as file: + # process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) + # try: + # with open(f'/proc/{pid}/io', 'r') as file: + # process.append(file.read()) + # except PermissionError as err: + # # print(err) + # pass processes.append(process) return processes @@ -54,7 +61,7 @@ def get_processes(self, name, sender=None, conn=None): dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() name = dbus.service.BusName("com.github.stsdc.monitor.workaround", bus) - helloworld = HelloWorld(bus, "/processes") + helloworld = HelloWorld(bus, "/com/github/stsdc/monitor/workaround") mainloop = GLib.MainLoop() mainloop.run() diff --git a/src/MainWindow.vala b/src/MainWindow.vala index eba8a92b..77c7c0cb 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -69,6 +69,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { show_all (); dbusserver = DBusServer.get_default (); + var dbus_workaround_client = DBusWorkaroundClient.get_default(); headerbar.search_revealer.set_reveal_child (stack.visible_child_name == "process_view"); stack.notify["visible-child-name"].connect (() => { @@ -89,6 +90,12 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { var res = resources.serialize (); statusbar.update (res); dbusserver.update (res); + try { + HashTable[] p = dbus_workaround_client.interface.get_processes (""); + debug("%s", p[400]["cmdline"] ); + } catch (Error e) { + warning (e.message); + } return false; }); return true; diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala new file mode 100644 index 00000000..bdf5ccff --- /dev/null +++ b/src/Services/DBusWorkaroundClient.vala @@ -0,0 +1,39 @@ +[DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")] +public interface Monitor.DBusWorkaroundClientInterface : Object { + public abstract HashTable[] get_processes (string empty) throws Error; + +} + +public class Monitor.DBusWorkaroundClient : Object { + public DBusWorkaroundClientInterface ? interface = null; + + private static GLib.Once instance; + public static unowned DBusWorkaroundClient get_default () { + return instance.once (() => { return new DBusWorkaroundClient (); }); + } + + public signal void monitor_vanished (); + public signal void monitor_appeared (); + + construct { + try { + interface = Bus.get_proxy_sync ( + BusType.SESSION, + "com.github.stsdc.monitor.workaround", + "/com/github/stsdc/monitor/workaround" + ); + + Bus.watch_name ( + BusType.SESSION, + "com.github.stsdc.monitor.workaround", + BusNameWatcherFlags.NONE, + () => monitor_appeared (), + () => monitor_vanished () + ); + } catch (IOError e) { + error ("Monitor Indicator DBus: %s\n", e.message); + } + + + } +} diff --git a/src/meson.build b/src/meson.build index cd68b508..8f85f0aa 100644 --- a/src/meson.build +++ b/src/meson.build @@ -63,6 +63,7 @@ source_app_files = [ # Services 'Services/Shortcuts.vala', 'Services/DBusServer.vala', + 'Services/DBusWorkaroundClient.vala', 'Services/Appearance.vala', # Resources From bb35702bdd57b0aa8119aab3ccd440635951679b Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:41:46 +0100 Subject: [PATCH 19/36] provider wip --- src/MainWindow.vala | 8 +-- src/Managers/ContainerManager.vala | 2 - src/Managers/HttpClientAsync.vala | 2 +- src/Managers/ProcessManager.vala | 30 ++------- src/Managers/ProcessProvider.vala | 85 ++++++-------------------- src/Services/DBusWorkaroundClient.vala | 2 +- subprojects/stylesheet | 2 +- 7 files changed, 26 insertions(+), 105 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 77c7c0cb..5c620623 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -69,7 +69,6 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { show_all (); dbusserver = DBusServer.get_default (); - var dbus_workaround_client = DBusWorkaroundClient.get_default(); headerbar.search_revealer.set_reveal_child (stack.visible_child_name == "process_view"); stack.notify["visible-child-name"].connect (() => { @@ -90,12 +89,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { var res = resources.serialize (); statusbar.update (res); dbusserver.update (res); - try { - HashTable[] p = dbus_workaround_client.interface.get_processes (""); - debug("%s", p[400]["cmdline"] ); - } catch (Error e) { - warning (e.message); - } + return false; }); return true; diff --git a/src/Managers/ContainerManager.vala b/src/Managers/ContainerManager.vala index 9d04fae1..75e21183 100644 --- a/src/Managers/ContainerManager.vala +++ b/src/Managers/ContainerManager.vala @@ -157,8 +157,6 @@ namespace Monitor { assert_nonnull (container_object); this.add_container (container_object); - - } var remove_me = new Gee.HashSet (); foreach (var container in this.container_list.values) { diff --git a/src/Managers/HttpClientAsync.vala b/src/Managers/HttpClientAsync.vala index f5a222b0..abf2b5c6 100644 --- a/src/Managers/HttpClientAsync.vala +++ b/src/Managers/HttpClientAsync.vala @@ -49,7 +49,7 @@ namespace Monitor { r = curl.setopt (Curl.Option.WRITEFUNCTION, HttpClientResponse.read_body_data); assert_true (r == Curl.Code.OK); - // debug ("call api method: %s - %s", this.get_request_method (method), url); + debug ("call api method: %s - %s", this.get_request_method (method), url); yield this.perform (curl); diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index 3cd06b2d..c7954f17 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -97,7 +97,7 @@ namespace Monitor { /** * Gets all new process and adds them */ - public async void update_processes () { + public async void update_processes () { /* CPU */ GTop.Cpu cpu_data; GTop.get_cpu (out cpu_data); @@ -135,34 +135,14 @@ namespace Monitor { // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, uid); - if (ProcessUtils.is_flatpak_env ()) { - var pp = ProcessProvider.get_default (); - var pp_pids = pp.get_pids (); + for (int i = 0; i < proclist.number; i++) { + int pid = pids[i]; - // foreach (var pid in pp_pids) { - // debug ("yeah %d", pid); - // } - - debug ("Size %u", pp_pids.length ()); - - foreach (int pid in pp_pids) { - if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { - add_process (pid); - } + if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { + add_process (pid); } - debug ("process_list size %u", process_list.size); - } else { - // for (int i = 0; i < proclist.number; i++) { - // int pid = pids[i]; - - // if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { - // add_process (pid); - // } - // } } - - cpu_last_used = used; cpu_last_total = cpu_data.total; cpu_last_useds = useds; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index a888808d..431d6e25 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -7,77 +7,26 @@ namespace Monitor { public Gee.HashSet pids = new Gee.HashSet (); + DBusWorkaroundClient dbus_workaround_client; + public ProcessProvider () { + if (ProcessUtils.is_flatpak_env ()) { + dbus_workaround_client = DBusWorkaroundClient.get_default (); + } } - public GLib.List get_pids () { - var new_pids = new GLib.List (); - - try { - string[] spawn_args = { "flatpak-spawn", "--host", "ls" }; - string[] spawn_env = Environ.get (); - Pid child_pid; - - int standard_input; - int standard_output; - int standard_error; - - - string ls_stdout; - string ls_stderr; - int ls_status; - - // GLib.Process.spawn_async_with_pipes - // ( - // "/proc/", - // spawn_args, - // spawn_env, - // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, - // null, - // out child_pid, - // out standard_input, - // out standard_output, - // out standard_error - // ); - - GLib.Process.spawn_command_line_sync ( - "ls /tmp/fakeproc/proc/", - out ls_stdout, - out ls_stderr, - out ls_status); - - // stdout: - // IOChannel output = new IOChannel.unix_new (standard_output); - // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - // return process_line (channel, condition, new_pids); - // }); - - //// stderr: - // IOChannel error = new IOChannel.unix_new (standard_error); - // error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - //// return process_line (channel, condition, "stderr"); - // return true; - // }); - - // ChildWatch.add (child_pid, (pid, status) => { - ////// Triggered when the child indicated by child_pid exits - // GLib.Process.close_pid (pid); - //// loop.quit (); - // }); - - // debug (ls_stdout); - foreach (var line in ls_stdout.strip ().split ("\n")) { - if (line[0].isdigit ()) { - // print ("---->" + line + "\n"); - new_pids.append (int.parse (line)); - } - } - - - } catch (SpawnError e) { - error ("Error: %s\n", e.message); - } - return new_pids; + public int[] get_pids () { + // try { + // HashTable[] p = dbus_workaround_client.interface.get_processes (""); + // debug ("%s", p[400]["cmdline"] ); + // } catch (Error e) { + // warning (e.message); + // } + GTop.ProcList proclist; + // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); + int[] pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); + debug("%d", pids.length); + return pids; } private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala index bdf5ccff..dc425bfd 100644 --- a/src/Services/DBusWorkaroundClient.vala +++ b/src/Services/DBusWorkaroundClient.vala @@ -1,6 +1,6 @@ [DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")] public interface Monitor.DBusWorkaroundClientInterface : Object { - public abstract HashTable[] get_processes (string empty) throws Error; + public abstract HashTable[] get_processes (string empty) throws Error; } diff --git a/subprojects/stylesheet b/subprojects/stylesheet index fbe2b247..a8b3c703 160000 --- a/subprojects/stylesheet +++ b/subprojects/stylesheet @@ -1 +1 @@ -Subproject commit fbe2b24704bbfd489152350627033295b3770a38 +Subproject commit a8b3c70331f983ed9a2568817188df15a257e319 From d673254b9055d0f7a2a5fd5f76e9db1fc8efb169 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 11 Dec 2023 01:07:36 +0100 Subject: [PATCH 20/36] Use provider to get pids --- src/Managers/Process.vala | 6 +++--- src/Managers/ProcessFlatpak.vala | 23 ----------------------- src/Managers/ProcessManager.vala | 10 +++------- src/Managers/ProcessProvider.vala | 5 +++-- src/meson.build | 1 - subprojects/stylesheet | 2 +- 6 files changed, 10 insertions(+), 37 deletions(-) delete mode 100644 src/Managers/ProcessFlatpak.vala diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index 1dfd1a1a..dafcca68 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -135,7 +135,7 @@ public class Monitor.Process : GLib.Object { } private bool get_children_pids () { - string ? children_content = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); + string ? children_content = ProcessUtils.read_file ("/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); if (children_content == "" || children_content == null) { return false; } @@ -201,7 +201,7 @@ public class Monitor.Process : GLib.Object { // Reads the /proc/%pid%/stat file and updates the process with the information therein. private bool parse_stat () { - string ? stat_contents = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/stat".printf (stat.pid)); + string ? stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); if (stat_contents == null) { return false; @@ -282,7 +282,7 @@ public class Monitor.Process : GLib.Object { * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ private bool read_cmdline () { - string ? cmdline = ProcessUtils.read_file ("/tmp/fakeproc/proc/%d/cmdline".printf (stat.pid)); + string ? cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); if (cmdline == null) { return false; diff --git a/src/Managers/ProcessFlatpak.vala b/src/Managers/ProcessFlatpak.vala deleted file mode 100644 index a6f72462..00000000 --- a/src/Managers/ProcessFlatpak.vala +++ /dev/null @@ -1,23 +0,0 @@ -public class Monitor.ProcessFlatpak : Process { - public ProcessFlatpak (int _pid) { - base (_pid); - } - // Kills the process - public new bool kill () { - // Sends a kill signal that cannot be ignored - if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) { - return true; - } - return false; - } - - // Ends the process - public new bool end () { - // Sends a terminate signal - if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { - return true; - } - return false; - } - -} diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index c7954f17..8ef55611 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -130,14 +130,10 @@ namespace Monitor { remove_process (pid); } - var uid = Posix.getuid (); - GTop.ProcList proclist; - // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); - var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, uid); - - for (int i = 0; i < proclist.number; i++) { - int pid = pids[i]; + var process_provider = ProcessProvider.get_default (); + var pids = process_provider.get_pids (); + foreach (int pid in pids) { if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { add_process (pid); } diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 431d6e25..0e8aa92e 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -24,8 +24,9 @@ namespace Monitor { // } GTop.ProcList proclist; // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); - int[] pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); - debug("%d", pids.length); + var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); + pids.length = (int) proclist.number; + return pids; } diff --git a/src/meson.build b/src/meson.build index 8f85f0aa..670dc56c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -52,7 +52,6 @@ source_app_files = [ # 'Managers/AppManager.vala', 'Managers/ProcessManager.vala', 'Managers/Process.vala', - 'Managers/ProcessFlatpak.vala', 'Managers/ProcessStructs.vala', 'Managers/ProcessUtils.vala', 'Managers/HttpClientAsync.vala', diff --git a/subprojects/stylesheet b/subprojects/stylesheet index a8b3c703..fbe2b247 160000 --- a/subprojects/stylesheet +++ b/subprojects/stylesheet @@ -1 +1 @@ -Subproject commit a8b3c70331f983ed9a2568817188df15a257e319 +Subproject commit fbe2b24704bbfd489152350627033295b3770a38 From d7d38d48b08fe33d04d19b836b8e930b95e7cbb4 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:41:34 +0100 Subject: [PATCH 21/36] return pids --- src/Managers/HttpClientAsync.vala | 2 +- src/Managers/ProcessProvider.vala | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Managers/HttpClientAsync.vala b/src/Managers/HttpClientAsync.vala index abf2b5c6..d641d3a0 100644 --- a/src/Managers/HttpClientAsync.vala +++ b/src/Managers/HttpClientAsync.vala @@ -49,7 +49,7 @@ namespace Monitor { r = curl.setopt (Curl.Option.WRITEFUNCTION, HttpClientResponse.read_body_data); assert_true (r == Curl.Code.OK); - debug ("call api method: %s - %s", this.get_request_method (method), url); + // debug ("call api method: %s - %s", this.get_request_method (method), url); yield this.perform (curl); diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 0e8aa92e..5ec54669 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -16,12 +16,22 @@ namespace Monitor { } public int[] get_pids () { - // try { - // HashTable[] p = dbus_workaround_client.interface.get_processes (""); - // debug ("%s", p[400]["cmdline"] ); - // } catch (Error e) { - // warning (e.message); - // } + if (ProcessUtils.is_flatpak_env ()) { + int[] pids; + try { + HashTable[] procs = dbus_workaround_client.interface.get_processes (""); + pids = new int[procs.length]; + debug ("Workaround: pids: %d", procs.length); + for (int i = 0; i < procs.length; i++) { + debug (procs[i]["pid"]); + pids[i] = int.parse (procs[i]["pid"]); + } + } catch (Error e) { + warning (e.message); + } + return pids; + } + debug ("normal"); GTop.ProcList proclist; // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); From 5256763777b4f8ebcc4180cfbfb5e01fdead5916 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:13:13 +0100 Subject: [PATCH 22/36] get list of processes --- flatpak/workaround/process_monitor.py | 25 ++++++++++-------- src/Managers/Process.vala | 38 ++++++++++++++++++++------- src/Managers/ProcessProvider.vala | 6 ++++- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index 02519e0c..49136698 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -43,17 +43,20 @@ def GetProcesses(self, name, sender=None, conn=None): "io": "" } with open(f'/proc/{pid}/cmdline', 'rb') as file: - process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', '')) - # with open(f'/proc/{pid}/stat', 'rb') as file: - # process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) - # with open(f'/proc/{pid}/statm', 'rb') as file: - # process.append(file.read().decode('utf-8', 'ignore').replace('\0', '')) - # try: - # with open(f'/proc/{pid}/io', 'r') as file: - # process.append(file.read()) - # except PermissionError as err: - # # print(err) - # pass + process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + + with open(f'/proc/{pid}/stat', 'rb') as file: + process["stat"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + + with open(f'/proc/{pid}/statm', 'rb') as file: + process["statm"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + try: + with open(f'/proc/{pid}/io', 'rb') as file: + process["io"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + + except PermissionError as err: + # print(err) + pass processes.append(process) return processes diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index dafcca68..cf5637f0 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -109,9 +109,9 @@ public class Monitor.Process : GLib.Object { exists = parse_stat (); if (exists) { get_usage (cpu_total, cpu_last_total); - // parse_io (); - // parse_statm (); - // get_open_files (); + parse_io (); + parse_statm (); + get_open_files (); } return exists; } @@ -201,12 +201,18 @@ public class Monitor.Process : GLib.Object { // Reads the /proc/%pid%/stat file and updates the process with the information therein. private bool parse_stat () { - string ? stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); - - if (stat_contents == null) { - return false; + string ? stat_contents; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + stat_contents = process_provider.pids_stat.get (this.stat.pid); + } else { + stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); } + if (stat_contents == null) return false; + + // debug (stat_contents); + // Split the contents into an array and parse each value that we care about // But first we have to extract the command name, since it might include spaces @@ -238,7 +244,13 @@ public class Monitor.Process : GLib.Object { } private bool parse_statm () { - string ? statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); + string ? statm_contents; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + statm_contents = process_provider.pids_stat.get (this.stat.pid); + } else { + statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); + } if (statm_contents == null) return false; @@ -282,7 +294,13 @@ public class Monitor.Process : GLib.Object { * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ private bool read_cmdline () { - string ? cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); + string ? cmdline; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + cmdline = process_provider.pids_cmdline.get (this.stat.pid); + } else { + cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); + } if (cmdline == null) { return false; @@ -292,11 +310,11 @@ public class Monitor.Process : GLib.Object { // if cmdline has 0 length we look into stat file // useful for kworker processes command = stat.comm; - return true; } command = cmdline; + return true; } diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 5ec54669..63cdf449 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -6,6 +6,8 @@ namespace Monitor { } public Gee.HashSet pids = new Gee.HashSet (); + public Gee.HashMap pids_cmdline = new Gee.HashMap (); + public Gee.HashMap pids_stat = new Gee.HashMap (); DBusWorkaroundClient dbus_workaround_client; @@ -23,8 +25,10 @@ namespace Monitor { pids = new int[procs.length]; debug ("Workaround: pids: %d", procs.length); for (int i = 0; i < procs.length; i++) { - debug (procs[i]["pid"]); + // debug (procs[i]["pid"]); pids[i] = int.parse (procs[i]["pid"]); + pids_cmdline.set (pids[i], procs[i]["cmdline"]); + pids_stat.set (pids[i], procs[i]["stat"]); } } catch (Error e) { warning (e.message); From a94f2da5fe58d11e1e0a4b9e9275f30dba54123f Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:23:12 +0100 Subject: [PATCH 23/36] read uid --- flatpak/workaround/process_monitor.py | 5 ++ src/Managers/Process.vala | 102 +++++++++++++++++++------- src/Managers/ProcessProvider.vala | 5 +- 3 files changed, 85 insertions(+), 27 deletions(-) diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index 49136698..fcac1c94 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -40,6 +40,7 @@ def GetProcesses(self, name, sender=None, conn=None): "cmdline": "", "stat": "", "statm": "", + "status": "", "io": "" } with open(f'/proc/{pid}/cmdline', 'rb') as file: @@ -47,12 +48,16 @@ def GetProcesses(self, name, sender=None, conn=None): with open(f'/proc/{pid}/stat', 'rb') as file: process["stat"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + + with open(f'/proc/{pid}/status', 'rb') as file: + process["status"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) with open(f'/proc/{pid}/statm', 'rb') as file: process["statm"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) try: with open(f'/proc/{pid}/io', 'rb') as file: process["io"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + # print(process["io"]) except PermissionError as err: # print(err) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index cf5637f0..e5d983fb 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -56,7 +56,6 @@ public class Monitor.Process : GLib.Object { private uint64 cpu_last_used; // Memory usage of the process, measured in KiB. - public uint64 mem_usage { get; private set; } public double mem_percentage { get; private set; } @@ -81,7 +80,7 @@ public class Monitor.Process : GLib.Object { stat.pid = _pid; // getting uid - get_uid (); + uid = get_uid (); // getting username // @TOFIX: Can't get username for postgres which @@ -96,13 +95,19 @@ public class Monitor.Process : GLib.Object { get_usage (0, 1); } - private void get_uid () { + private int get_uid () { + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + string ? status = process_provider.pids_status.get (this.stat.pid); + var status_line = status.split ("\n"); + return int.parse(status_line[8].split("\t")[1]); + + } GTop.ProcUid proc_uid; GTop.get_proc_uid (out proc_uid, stat.pid); - uid = proc_uid.uid; + return proc_uid.uid; } - // Updates the process to get latest information // Returns if the update was successful public bool update (uint64 cpu_total, uint64 cpu_last_total) { @@ -147,7 +152,52 @@ public class Monitor.Process : GLib.Object { return true; } + private bool parse_io_workaround () { + var process_provider = ProcessProvider.get_default (); + string ? io_stats = process_provider.pids_io.get (this.stat.pid); + + if (io_stats == "") return false; + + foreach (string line in io_stats.split ("\n")) { + if (line == "") continue; + var splitted_line = line.split (":"); + switch (splitted_line[0]) { + case "wchar": + io.wchar = uint64.parse (splitted_line[1]); + break; + case "rchar": + io.rchar = uint64.parse (splitted_line[1]); + break; + case "syscr": + io.syscr = uint64.parse (splitted_line[1]); + break; + case "syscw": + io.syscw = uint64.parse (splitted_line[1]); + break; + case "read_bytes": + io.read_bytes = uint64.parse (splitted_line[1]); + break; + case "write_bytes": + io.write_bytes = uint64.parse (splitted_line[1]); + break; + case "cancelled_write_bytes": + io.cancelled_write_bytes = uint64.parse (splitted_line[1]); + break; + default: + warning ("Unknown value in /proc/%d/io", stat.pid); + break; + } + } + + return true; + } + private bool parse_io () { + + if (ProcessUtils.is_flatpak_env ()) { + return parse_io_workaround (); + } + var io_file = File.new_for_path ("/proc/%d/io".printf (stat.pid)); if (!io_file.query_exists ()) { @@ -211,7 +261,7 @@ public class Monitor.Process : GLib.Object { if (stat_contents == null) return false; - // debug (stat_contents); + // debug (stat_contents); // Split the contents into an array and parse each value that we care about @@ -267,26 +317,26 @@ public class Monitor.Process : GLib.Object { } private bool get_open_files () { - // try { - // string directory = "/proc/%d/fd".printf (stat.pid); - // Dir dir = Dir.open (directory, 0); - // string ? name = null; - // while ((name = dir.read_name ()) != null) { - // string path = Path.build_filename (directory, name); - - // if (FileUtils.test (path, FileTest.IS_SYMLINK)) { - // string real_path = FileUtils.read_link (path); - // // debug(content); - // open_files_paths.add (real_path); - // } - // } - // } catch (FileError err) { - // if (err is FileError.ACCES) { - // fd_permission_error (err.message); - // } else { - // warning (err.message); - // } - // } + // try { + // string directory = "/proc/%d/fd".printf (stat.pid); + // Dir dir = Dir.open (directory, 0); + // string ? name = null; + // while ((name = dir.read_name ()) != null) { + // string path = Path.build_filename (directory, name); + + // if (FileUtils.test (path, FileTest.IS_SYMLINK)) { + // string real_path = FileUtils.read_link (path); + //// debug(content); + // open_files_paths.add (real_path); + // } + // } + // } catch (FileError err) { + // if (err is FileError.ACCES) { + // fd_permission_error (err.message); + // } else { + // warning (err.message); + // } + // } return true; } diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 63cdf449..8d85544c 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -8,6 +8,8 @@ namespace Monitor { public Gee.HashSet pids = new Gee.HashSet (); public Gee.HashMap pids_cmdline = new Gee.HashMap (); public Gee.HashMap pids_stat = new Gee.HashMap (); + public Gee.HashMap pids_io = new Gee.HashMap (); + public Gee.HashMap pids_status = new Gee.HashMap (); DBusWorkaroundClient dbus_workaround_client; @@ -29,13 +31,14 @@ namespace Monitor { pids[i] = int.parse (procs[i]["pid"]); pids_cmdline.set (pids[i], procs[i]["cmdline"]); pids_stat.set (pids[i], procs[i]["stat"]); + pids_status.set (pids[i], procs[i]["status"]); + pids_io.set (pids[i], procs[i]["io"]); } } catch (Error e) { warning (e.message); } return pids; } - debug ("normal"); GTop.ProcList proclist; // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); From 5a00128cb9ed067cb485b61c734db5746b8c7219 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:27:27 +0100 Subject: [PATCH 24/36] clean hashmaps in ProcessProvider; retrieve children for a process --- flatpak/workaround/process_monitor.py | 6 +- src/Managers/Process.vala | 4 +- src/Managers/ProcessProvider.vala | 14 ++-- src/Managers/ProcessUtils.vala | 96 +++++++++++++-------------- 4 files changed, 65 insertions(+), 55 deletions(-) diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index fcac1c94..7d6c03d5 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -41,7 +41,8 @@ def GetProcesses(self, name, sender=None, conn=None): "stat": "", "statm": "", "status": "", - "io": "" + "io": "", + "children": "" } with open(f'/proc/{pid}/cmdline', 'rb') as file: process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) @@ -51,6 +52,9 @@ def GetProcesses(self, name, sender=None, conn=None): with open(f'/proc/{pid}/status', 'rb') as file: process["status"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + + with open(f'/proc/{pid}/task/{pid}/children', 'rb') as file: + process["children"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) with open(f'/proc/{pid}/statm', 'rb') as file: process["statm"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index e5d983fb..e6e1a1e2 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -100,8 +100,8 @@ public class Monitor.Process : GLib.Object { var process_provider = ProcessProvider.get_default (); string ? status = process_provider.pids_status.get (this.stat.pid); var status_line = status.split ("\n"); - return int.parse(status_line[8].split("\t")[1]); - + return int.parse (status_line[8].split ("\t")[1]); + } GTop.ProcUid proc_uid; GTop.get_proc_uid (out proc_uid, stat.pid); diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 8d85544c..75ef4cb9 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -5,11 +5,11 @@ namespace Monitor { return instance.once (() => { return new ProcessProvider (); }); } - public Gee.HashSet pids = new Gee.HashSet (); public Gee.HashMap pids_cmdline = new Gee.HashMap (); public Gee.HashMap pids_stat = new Gee.HashMap (); public Gee.HashMap pids_io = new Gee.HashMap (); public Gee.HashMap pids_status = new Gee.HashMap (); + public Gee.HashMap pids_children = new Gee.HashMap (); DBusWorkaroundClient dbus_workaround_client; @@ -22,17 +22,23 @@ namespace Monitor { public int[] get_pids () { if (ProcessUtils.is_flatpak_env ()) { int[] pids; + pids_cmdline.clear (); + pids_stat.clear (); + pids_io.clear (); + pids_status.clear (); + pids_children.clear (); try { HashTable[] procs = dbus_workaround_client.interface.get_processes (""); pids = new int[procs.length]; - debug ("Workaround: pids: %d", procs.length); + debug ("Workaround: retrieved pids: %d", procs.length); for (int i = 0; i < procs.length; i++) { - // debug (procs[i]["pid"]); + // debug (procs[i]["pid"]); pids[i] = int.parse (procs[i]["pid"]); pids_cmdline.set (pids[i], procs[i]["cmdline"]); pids_stat.set (pids[i], procs[i]["stat"]); - pids_status.set (pids[i], procs[i]["status"]); pids_io.set (pids[i], procs[i]["io"]); + pids_children.set (pids[i], procs[i]["children"]); + pids_status.set (pids[i], procs[i]["status"]); } } catch (Error e) { warning (e.message); diff --git a/src/Managers/ProcessUtils.vala b/src/Managers/ProcessUtils.vala index 8eb9ed4a..ae0788bb 100644 --- a/src/Managers/ProcessUtils.vala +++ b/src/Managers/ProcessUtils.vala @@ -27,9 +27,9 @@ public class Monitor.ProcessUtils { } public static string ? read_file (string path) { - // if (ProcessUtils.is_flatpak_env ()) { - // return ProcessUtils.read_file_on_host (path); - // } + // if (ProcessUtils.is_flatpak_env ()) { + // return ProcessUtils.read_file_on_host (path); + // } return ProcessUtils.read_file_native (path); } @@ -78,60 +78,60 @@ public class Monitor.ProcessUtils { Pid child_pid; try { - // string command = "flatpak-spawn --host cat " + path + " | grep -av DEBUG"; + // string command = "flatpak-spawn --host cat " + path + " | grep -av DEBUG"; debug (command); GLib.Process.spawn_command_line_sync ( - command, - out stdout, - out stderr, - out status + command, + out stdout, + out stderr, + out status ); - // GLib.Process.spawn_async_with_pipes - // ("/", - // spawn_args, - // Environ.get (), - // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, - // null, - // out child_pid, - // out standard_input, - // out standard_output, - // out standard_error - // ); + // GLib.Process.spawn_async_with_pipes + // ("/", + // spawn_args, + // Environ.get (), + // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, + // null, + // out child_pid, + // out standard_input, + // out standard_output, + // out standard_error + // ); // debug ("Status: %d", status); } catch (SpawnError e) { error (e.message); } - // IOChannel output = new IOChannel.unix_new (standard_output); - // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - // if (condition == IOCondition.HUP) { - // print ("%s: The fd has been closed.\n", "stream_name"); - // return false; - // } - - // try { - // string line; - // channel.read_line (out line, null, null); - // print ("%s: %s", "stream_name", line); - // } catch (IOChannelError e) { - // print ("%s: IOChannelError: %s\n", "stream_name", e.message); - // return false; - // } catch (ConvertError e) { - // print ("%s: ConvertError: %s\n", "stream_name", e.message); - // return false; - // } - - // return true; - // }); - - // ChildWatch.add (child_pid, (pid, status) => { - // // Triggered when the child indicated by child_pid exits - // GLib.Process.close_pid (pid); - // }); - - + // IOChannel output = new IOChannel.unix_new (standard_output); + // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + // if (condition == IOCondition.HUP) { + // print ("%s: The fd has been closed.\n", "stream_name"); + // return false; + // } + + // try { + // string line; + // channel.read_line (out line, null, null); + // print ("%s: %s", "stream_name", line); + // } catch (IOChannelError e) { + // print ("%s: IOChannelError: %s\n", "stream_name", e.message); + // return false; + // } catch (ConvertError e) { + // print ("%s: ConvertError: %s\n", "stream_name", e.message); + // return false; + // } + + // return true; + // }); + + // ChildWatch.add (child_pid, (pid, status) => { + //// Triggered when the child indicated by child_pid exits + // GLib.Process.close_pid (pid); + // }); + + string ? stdout_no_debug = ""; if (stdout == "" || status != 0) { @@ -145,7 +145,7 @@ public class Monitor.ProcessUtils { } } // print (stdout_no_debug); - // return null; + // return null; return stdout_no_debug; } From 0a3cd3d75cb01f0e928f3a6d80234b1bebe3e575 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:41:28 +0100 Subject: [PATCH 25/36] Create ProcessWorkaround class and use it if in Flatpak env --- flatpak/workaround/process_monitor.py | 10 +- src/Managers/Process.vala | 77 ++------- src/Managers/ProcessManager.vala | 2 +- src/Managers/ProcessProvider.vala | 7 + src/Managers/ProcessWorkaround.vala | 226 ++++++++++++++++++++++++++ src/meson.build | 2 + 6 files changed, 259 insertions(+), 65 deletions(-) create mode 100644 src/Managers/ProcessWorkaround.vala diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/process_monitor.py index 7d6c03d5..a8feafdb 100644 --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/process_monitor.py @@ -44,9 +44,13 @@ def GetProcesses(self, name, sender=None, conn=None): "io": "", "children": "" } - with open(f'/proc/{pid}/cmdline', 'rb') as file: - process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) - + try: + with open(f'/proc/{pid}/cmdline', 'rb') as file: + process["cmdline"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) + except FileNotFoundError as err: + process["cmdline"] = None + continue + with open(f'/proc/{pid}/stat', 'rb') as file: process["stat"] = (file.read().decode('utf-8', 'ignore').replace('\0', ' ')) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index e6e1a1e2..bd6342d0 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -6,10 +6,10 @@ public class Monitor.Process : GLib.Object { // Whether or not the PID leads to something - public bool exists { get; private set; } + public bool exists { get; protected set; } // Full command from cmdline file - public string command { get; private set; } + public string command { get; protected set; } // If process is an installed app, this will contain its name, // otherwise it is just a trimmed command @@ -51,17 +51,17 @@ public class Monitor.Process : GLib.Object { * * Will be 0 on first update. */ - public double cpu_percentage { get; private set; } + public double cpu_percentage { get; protected set; } - private uint64 cpu_last_used; + protected uint64 cpu_last_used; // Memory usage of the process, measured in KiB. - public uint64 mem_usage { get; private set; } - public double mem_percentage { get; private set; } + public uint64 mem_usage { get; protected set; } + public double mem_percentage { get; protected set; } - private uint64 last_total; + protected uint64 last_total; - const int HISTORY_BUFFER_SIZE = 30; + protected const int HISTORY_BUFFER_SIZE = 30; public Gee.ArrayList cpu_percentage_history = new Gee.ArrayList (); public Gee.ArrayList mem_percentage_history = new Gee.ArrayList (); @@ -95,7 +95,7 @@ public class Monitor.Process : GLib.Object { get_usage (0, 1); } - private int get_uid () { + protected int get_uid () { if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); string ? status = process_provider.pids_status.get (this.stat.pid); @@ -139,7 +139,7 @@ public class Monitor.Process : GLib.Object { return false; } - private bool get_children_pids () { + protected bool get_children_pids () { string ? children_content = ProcessUtils.read_file ("/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); if (children_content == "" || children_content == null) { return false; @@ -152,52 +152,7 @@ public class Monitor.Process : GLib.Object { return true; } - private bool parse_io_workaround () { - var process_provider = ProcessProvider.get_default (); - string ? io_stats = process_provider.pids_io.get (this.stat.pid); - - if (io_stats == "") return false; - - foreach (string line in io_stats.split ("\n")) { - if (line == "") continue; - var splitted_line = line.split (":"); - switch (splitted_line[0]) { - case "wchar": - io.wchar = uint64.parse (splitted_line[1]); - break; - case "rchar": - io.rchar = uint64.parse (splitted_line[1]); - break; - case "syscr": - io.syscr = uint64.parse (splitted_line[1]); - break; - case "syscw": - io.syscw = uint64.parse (splitted_line[1]); - break; - case "read_bytes": - io.read_bytes = uint64.parse (splitted_line[1]); - break; - case "write_bytes": - io.write_bytes = uint64.parse (splitted_line[1]); - break; - case "cancelled_write_bytes": - io.cancelled_write_bytes = uint64.parse (splitted_line[1]); - break; - default: - warning ("Unknown value in /proc/%d/io", stat.pid); - break; - } - } - - return true; - } - - private bool parse_io () { - - if (ProcessUtils.is_flatpak_env ()) { - return parse_io_workaround (); - } - + protected bool parse_io () { var io_file = File.new_for_path ("/proc/%d/io".printf (stat.pid)); if (!io_file.query_exists ()) { @@ -250,7 +205,7 @@ public class Monitor.Process : GLib.Object { } // Reads the /proc/%pid%/stat file and updates the process with the information therein. - private bool parse_stat () { + protected bool parse_stat () { string ? stat_contents; if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); @@ -293,7 +248,7 @@ public class Monitor.Process : GLib.Object { return true; } - private bool parse_statm () { + protected bool parse_statm () { string ? statm_contents; if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); @@ -316,7 +271,7 @@ public class Monitor.Process : GLib.Object { return true; } - private bool get_open_files () { + protected bool get_open_files () { // try { // string directory = "/proc/%d/fd".printf (stat.pid); // Dir dir = Dir.open (directory, 0); @@ -343,7 +298,7 @@ public class Monitor.Process : GLib.Object { /** * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ - private bool read_cmdline () { + protected bool read_cmdline () { string ? cmdline; if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); @@ -368,7 +323,7 @@ public class Monitor.Process : GLib.Object { return true; } - private void get_usage (uint64 cpu_total, uint64 cpu_last_total) { + protected void get_usage (uint64 cpu_total, uint64 cpu_last_total) { // Get CPU usage by process GTop.ProcTime proc_time; GTop.get_proc_time (out proc_time, stat.pid); diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index 8ef55611..cbf6ce34 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -250,7 +250,7 @@ namespace Monitor { */ private Process ? add_process (int pid, bool lazy_signal = false) { // create the process - var process = new Process (pid); + var process = ProcessProvider.get_default ().create_process (pid); if (!process.exists) { return null; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 75ef4cb9..039b78fb 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -53,6 +53,13 @@ namespace Monitor { return pids; } + public Process create_process (int pid) { + if (ProcessUtils.is_flatpak_env ()) { + return new ProcessWorkaround (pid); + } + return new Process (pid); + } + private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { if (condition == IOCondition.HUP) { // debug ("%s: The fd has been closed.\n", stream_name); diff --git a/src/Managers/ProcessWorkaround.vala b/src/Managers/ProcessWorkaround.vala new file mode 100644 index 00000000..7a196d52 --- /dev/null +++ b/src/Managers/ProcessWorkaround.vala @@ -0,0 +1,226 @@ +public class Monitor.ProcessWorkaround : Monitor.Process { + + // Construct a new process + public ProcessWorkaround (int _pid) { + base (_pid); + } + + private new int get_uid () { + var process_provider = ProcessProvider.get_default (); + string ? status = process_provider.pids_status.get (this.stat.pid); + var status_line = status.split ("\n"); + return int.parse (status_line[8].split ("\t")[1]); + } + + // Kills the process + public new bool kill () { + // Sends a kill signal that cannot be ignored + if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) { + return true; + } + return false; + } + + // Ends the process + public new bool end () { + // Sends a terminate signal + if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { + return true; + } + return false; + } + + private new bool get_children_pids () { + var process_provider = ProcessProvider.get_default (); + string ? children_content = process_provider.pids_children.get (this.stat.pid); + + var splitted_children_pids = children_content.split (" "); + foreach (var child in splitted_children_pids) { + this.children.add (int.parse (child)); + } + return true; + } + + private new bool parse_io () { + var process_provider = ProcessProvider.get_default (); + string ? io_stats = process_provider.pids_io.get (this.stat.pid); + + if (io_stats == "") return false; + + foreach (string line in io_stats.split ("\n")) { + if (line == "") continue; + var splitted_line = line.split (":"); + switch (splitted_line[0]) { + case "wchar": + io.wchar = uint64.parse (splitted_line[1]); + break; + case "rchar": + io.rchar = uint64.parse (splitted_line[1]); + break; + case "syscr": + io.syscr = uint64.parse (splitted_line[1]); + break; + case "syscw": + io.syscw = uint64.parse (splitted_line[1]); + break; + case "read_bytes": + io.read_bytes = uint64.parse (splitted_line[1]); + break; + case "write_bytes": + io.write_bytes = uint64.parse (splitted_line[1]); + break; + case "cancelled_write_bytes": + io.cancelled_write_bytes = uint64.parse (splitted_line[1]); + break; + default: + warning ("Unknown value in /proc/%d/io", stat.pid); + break; + } + } + + return true; + } + + // Reads the /proc/%pid%/stat file and updates the process with the information therein. + private new bool parse_stat () { + var process_provider = ProcessProvider.get_default (); + string ? stat_contents = process_provider.pids_stat.get (this.stat.pid); + + if (stat_contents == null) return false; + + // debug (stat_contents); + + // Split the contents into an array and parse each value that we care about + + // But first we have to extract the command name, since it might include spaces + // First find the command in stat file. It is inside `(command)` + + /* *INDENT-OFF* */ + Regex regex = /\((.*?)\)/; // vala-lint=space-before-paren, + /* *INDENT-ON* */ + + MatchInfo match_info; + regex.match (stat_contents, 0, out match_info); + string matched_command = match_info.fetch (0); + + // Remove command from stat_contents + stat_contents = stat_contents.replace (matched_command, ""); + + // split the string and extract some stats + var splitted_stat = stat_contents.split (" "); + stat.comm = matched_command[1 : -1]; + + stat.state = splitted_stat[2]; + stat.ppid = int.parse (splitted_stat[3]); + stat.pgrp = int.parse (splitted_stat[4]); + stat.priority = int.parse (splitted_stat[17]); + stat.nice = int.parse (splitted_stat[18]); + stat.num_threads = int.parse (splitted_stat[19]); + + return true; + } + + private new bool parse_statm () { + var process_provider = ProcessProvider.get_default (); + string ? statm_contents = process_provider.pids_stat.get (this.stat.pid); + + if (statm_contents == null) return false; + + var splitted_statm = statm_contents.split (" "); + statm.size = int.parse (splitted_statm[0]); + statm.resident = int.parse (splitted_statm[1]); + statm.shared = int.parse (splitted_statm[2]); + statm.trs = int.parse (splitted_statm[3]); + statm.lrs = int.parse (splitted_statm[4]); + statm.drs = int.parse (splitted_statm[5]); + statm.dt = int.parse (splitted_statm[6]); + + return true; + } + + private new bool get_open_files () { + // try { + // string directory = "/proc/%d/fd".printf (stat.pid); + // Dir dir = Dir.open (directory, 0); + // string ? name = null; + // while ((name = dir.read_name ()) != null) { + // string path = Path.build_filename (directory, name); + + // if (FileUtils.test (path, FileTest.IS_SYMLINK)) { + // string real_path = FileUtils.read_link (path); + //// debug(content); + // open_files_paths.add (real_path); + // } + // } + // } catch (FileError err) { + // if (err is FileError.ACCES) { + // fd_permission_error (err.message); + // } else { + // warning (err.message); + // } + // } + return true; + } + + /** + * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. + */ + private new bool read_cmdline () { + var process_provider = ProcessProvider.get_default (); + string ? cmdline = process_provider.pids_cmdline.get (this.stat.pid); + + + if (cmdline == null) { + return false; + } + + if (cmdline.length <= 0) { + // if cmdline has 0 length we look into stat file + // useful for kworker processes + command = stat.comm; + return true; + } + + command = cmdline; + + return true; + } + + private new void get_usage (uint64 cpu_total, uint64 cpu_last_total) { + // Get CPU usage by process + GTop.ProcTime proc_time; + GTop.get_proc_time (out proc_time, stat.pid); + cpu_percentage = 100 * ((double) (proc_time.rtime - cpu_last_used)) / (cpu_total - cpu_last_total); + cpu_last_used = proc_time.rtime; + + // Making CPU history + if (cpu_percentage_history.size == HISTORY_BUFFER_SIZE) { + cpu_percentage_history.remove_at (0); + } + cpu_percentage_history.add (cpu_percentage); + + // Get memory usage by process + GTop.Memory mem; + GTop.get_mem (out mem); + + GTop.ProcMem proc_mem; + GTop.get_proc_mem (out proc_mem, stat.pid); + mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB + + // also if it is using X Window Server + if (Gdk.Display.get_default () is Gdk.X11.Display) { + Wnck.ResourceUsage resu = Wnck.ResourceUsage.pid_read (Gdk.Display.get_default (), stat.pid); + mem_usage += (resu.total_bytes_estimate / 1024); + } + + var total_installed_memory = (double) mem.total / 1024; + mem_percentage = (mem_usage / total_installed_memory) * 100; + + // Making RAM history + if (mem_percentage_history.size == HISTORY_BUFFER_SIZE) { + mem_percentage_history.remove_at (0); + } + mem_percentage_history.add (mem_percentage); + } + +} diff --git a/src/meson.build b/src/meson.build index 670dc56c..ec117034 100644 --- a/src/meson.build +++ b/src/meson.build @@ -58,6 +58,8 @@ source_app_files = [ 'Managers/ContainerManager.vala', 'Managers/Container.vala', 'Managers/ProcessProvider.vala', + 'Managers/ProcessWorkaround.vala', + # 'Managers/IProcess.vala', # Services 'Services/Shortcuts.vala', From 7ba68218ed1536e3a7e50d3820a0c11b0f82d50b Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:52:27 +0100 Subject: [PATCH 26/36] remove unnecessary conditions --- src/Managers/Process.vala | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index bd6342d0..21ed825a 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -206,13 +206,7 @@ public class Monitor.Process : GLib.Object { // Reads the /proc/%pid%/stat file and updates the process with the information therein. protected bool parse_stat () { - string ? stat_contents; - if (ProcessUtils.is_flatpak_env ()) { - var process_provider = ProcessProvider.get_default (); - stat_contents = process_provider.pids_stat.get (this.stat.pid); - } else { - stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); - } + string ? stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); if (stat_contents == null) return false; @@ -249,13 +243,7 @@ public class Monitor.Process : GLib.Object { } protected bool parse_statm () { - string ? statm_contents; - if (ProcessUtils.is_flatpak_env ()) { - var process_provider = ProcessProvider.get_default (); - statm_contents = process_provider.pids_stat.get (this.stat.pid); - } else { - statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); - } + string ? statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); if (statm_contents == null) return false; @@ -299,13 +287,7 @@ public class Monitor.Process : GLib.Object { * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ protected bool read_cmdline () { - string ? cmdline; - if (ProcessUtils.is_flatpak_env ()) { - var process_provider = ProcessProvider.get_default (); - cmdline = process_provider.pids_cmdline.get (this.stat.pid); - } else { - cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); - } + string ? cmdline = process_provider.pids_cmdline.get (this.stat.pid); if (cmdline == null) { return false; From 24f0dc7b3a99486518cdd4accc6cdfb015315ae0 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:13:54 +0100 Subject: [PATCH 27/36] Show cpu usage for processes in Flatpak --- src/Managers/Process.vala | 119 ++++++++++++--- src/Managers/ProcessManager.vala | 2 +- src/Managers/ProcessProvider.vala | 7 - src/Managers/ProcessStructs.vala | 3 + src/Managers/ProcessWorkaround.vala | 226 ---------------------------- src/meson.build | 2 +- 6 files changed, 100 insertions(+), 259 deletions(-) delete mode 100644 src/Managers/ProcessWorkaround.vala diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index 21ed825a..bb79b9a6 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -6,10 +6,10 @@ public class Monitor.Process : GLib.Object { // Whether or not the PID leads to something - public bool exists { get; protected set; } + public bool exists { get; private set; } // Full command from cmdline file - public string command { get; protected set; } + public string command { get; private set; } // If process is an installed app, this will contain its name, // otherwise it is just a trimmed command @@ -51,17 +51,17 @@ public class Monitor.Process : GLib.Object { * * Will be 0 on first update. */ - public double cpu_percentage { get; protected set; } + public double cpu_percentage { get; private set; } - protected uint64 cpu_last_used; + private uint64 cpu_last_used; // Memory usage of the process, measured in KiB. - public uint64 mem_usage { get; protected set; } - public double mem_percentage { get; protected set; } + public uint64 mem_usage { get; private set; } + public double mem_percentage { get; private set; } - protected uint64 last_total; + private uint64 last_total; - protected const int HISTORY_BUFFER_SIZE = 30; + const int HISTORY_BUFFER_SIZE = 30; public Gee.ArrayList cpu_percentage_history = new Gee.ArrayList (); public Gee.ArrayList mem_percentage_history = new Gee.ArrayList (); @@ -95,7 +95,7 @@ public class Monitor.Process : GLib.Object { get_usage (0, 1); } - protected int get_uid () { + private int get_uid () { if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); string ? status = process_provider.pids_status.get (this.stat.pid); @@ -139,7 +139,7 @@ public class Monitor.Process : GLib.Object { return false; } - protected bool get_children_pids () { + private bool get_children_pids () { string ? children_content = ProcessUtils.read_file ("/proc/%d/task/%d/children".printf (stat.pid, stat.pid)); if (children_content == "" || children_content == null) { return false; @@ -152,7 +152,52 @@ public class Monitor.Process : GLib.Object { return true; } - protected bool parse_io () { + private bool parse_io_workaround () { + var process_provider = ProcessProvider.get_default (); + string ? io_stats = process_provider.pids_io.get (this.stat.pid); + + if (io_stats == "") return false; + + foreach (string line in io_stats.split ("\n")) { + if (line == "") continue; + var splitted_line = line.split (":"); + switch (splitted_line[0]) { + case "wchar": + io.wchar = uint64.parse (splitted_line[1]); + break; + case "rchar": + io.rchar = uint64.parse (splitted_line[1]); + break; + case "syscr": + io.syscr = uint64.parse (splitted_line[1]); + break; + case "syscw": + io.syscw = uint64.parse (splitted_line[1]); + break; + case "read_bytes": + io.read_bytes = uint64.parse (splitted_line[1]); + break; + case "write_bytes": + io.write_bytes = uint64.parse (splitted_line[1]); + break; + case "cancelled_write_bytes": + io.cancelled_write_bytes = uint64.parse (splitted_line[1]); + break; + default: + warning ("Unknown value in /proc/%d/io", stat.pid); + break; + } + } + + return true; + } + + private bool parse_io () { + + if (ProcessUtils.is_flatpak_env ()) { + return parse_io_workaround (); + } + var io_file = File.new_for_path ("/proc/%d/io".printf (stat.pid)); if (!io_file.query_exists ()) { @@ -205,8 +250,14 @@ public class Monitor.Process : GLib.Object { } // Reads the /proc/%pid%/stat file and updates the process with the information therein. - protected bool parse_stat () { - string ? stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); + private bool parse_stat () { + string ? stat_contents; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + stat_contents = process_provider.pids_stat.get (this.stat.pid); + } else { + stat_contents = ProcessUtils.read_file ("/proc/%d/stat".printf (stat.pid)); + } if (stat_contents == null) return false; @@ -238,12 +289,20 @@ public class Monitor.Process : GLib.Object { stat.priority = int.parse (splitted_stat[17]); stat.nice = int.parse (splitted_stat[18]); stat.num_threads = int.parse (splitted_stat[19]); + stat.utime = ulong.parse (splitted_stat[13]); + stat.stime = ulong.parse (splitted_stat[14]); return true; } - protected bool parse_statm () { - string ? statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); + private bool parse_statm () { + string ? statm_contents; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + statm_contents = process_provider.pids_stat.get (this.stat.pid); + } else { + statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); + } if (statm_contents == null) return false; @@ -259,7 +318,7 @@ public class Monitor.Process : GLib.Object { return true; } - protected bool get_open_files () { + private bool get_open_files () { // try { // string directory = "/proc/%d/fd".printf (stat.pid); // Dir dir = Dir.open (directory, 0); @@ -286,8 +345,14 @@ public class Monitor.Process : GLib.Object { /** * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. */ - protected bool read_cmdline () { - string ? cmdline = process_provider.pids_cmdline.get (this.stat.pid); + private bool read_cmdline () { + string ? cmdline; + if (ProcessUtils.is_flatpak_env ()) { + var process_provider = ProcessProvider.get_default (); + cmdline = process_provider.pids_cmdline.get (this.stat.pid); + } else { + cmdline = ProcessUtils.read_file ("/proc/%d/cmdline".printf (stat.pid)); + } if (cmdline == null) { return false; @@ -305,12 +370,18 @@ public class Monitor.Process : GLib.Object { return true; } - protected void get_usage (uint64 cpu_total, uint64 cpu_last_total) { + private void get_usage (uint64 cpu_total, uint64 cpu_last_total) { // Get CPU usage by process - GTop.ProcTime proc_time; - GTop.get_proc_time (out proc_time, stat.pid); - cpu_percentage = 100 * ((double) (proc_time.rtime - cpu_last_used)) / (cpu_total - cpu_last_total); - cpu_last_used = proc_time.rtime; + if (ProcessUtils.is_flatpak_env ()) { + var rtime = stat.utime + stat.stime; + cpu_percentage = 100 * ((double) (rtime - cpu_last_used)) / (cpu_total - cpu_last_total); + cpu_last_used = rtime; + } else { + GTop.ProcTime proc_time; + GTop.get_proc_time (out proc_time, stat.pid); + cpu_percentage = 100 * ((double) (proc_time.rtime - cpu_last_used)) / (cpu_total - cpu_last_total); + cpu_last_used = proc_time.rtime; + } // Making CPU history if (cpu_percentage_history.size == HISTORY_BUFFER_SIZE) { @@ -342,4 +413,4 @@ public class Monitor.Process : GLib.Object { mem_percentage_history.add (mem_percentage); } -} +} \ No newline at end of file diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index cbf6ce34..8ef55611 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -250,7 +250,7 @@ namespace Monitor { */ private Process ? add_process (int pid, bool lazy_signal = false) { // create the process - var process = ProcessProvider.get_default ().create_process (pid); + var process = new Process (pid); if (!process.exists) { return null; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 039b78fb..75ef4cb9 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -53,13 +53,6 @@ namespace Monitor { return pids; } - public Process create_process (int pid) { - if (ProcessUtils.is_flatpak_env ()) { - return new ProcessWorkaround (pid); - } - return new Process (pid); - } - private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { if (condition == IOCondition.HUP) { // debug ("%s: The fd has been closed.\n", stream_name); diff --git a/src/Managers/ProcessStructs.vala b/src/Managers/ProcessStructs.vala index 97f06889..78878f49 100644 --- a/src/Managers/ProcessStructs.vala +++ b/src/Managers/ProcessStructs.vala @@ -101,4 +101,7 @@ public struct Monitor.ProcessStatus { // The time the process started after system boot. public uint64 starttime; + + public ulong utime; + public ulong stime; } diff --git a/src/Managers/ProcessWorkaround.vala b/src/Managers/ProcessWorkaround.vala deleted file mode 100644 index 7a196d52..00000000 --- a/src/Managers/ProcessWorkaround.vala +++ /dev/null @@ -1,226 +0,0 @@ -public class Monitor.ProcessWorkaround : Monitor.Process { - - // Construct a new process - public ProcessWorkaround (int _pid) { - base (_pid); - } - - private new int get_uid () { - var process_provider = ProcessProvider.get_default (); - string ? status = process_provider.pids_status.get (this.stat.pid); - var status_line = status.split ("\n"); - return int.parse (status_line[8].split ("\t")[1]); - } - - // Kills the process - public new bool kill () { - // Sends a kill signal that cannot be ignored - if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) { - return true; - } - return false; - } - - // Ends the process - public new bool end () { - // Sends a terminate signal - if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { - return true; - } - return false; - } - - private new bool get_children_pids () { - var process_provider = ProcessProvider.get_default (); - string ? children_content = process_provider.pids_children.get (this.stat.pid); - - var splitted_children_pids = children_content.split (" "); - foreach (var child in splitted_children_pids) { - this.children.add (int.parse (child)); - } - return true; - } - - private new bool parse_io () { - var process_provider = ProcessProvider.get_default (); - string ? io_stats = process_provider.pids_io.get (this.stat.pid); - - if (io_stats == "") return false; - - foreach (string line in io_stats.split ("\n")) { - if (line == "") continue; - var splitted_line = line.split (":"); - switch (splitted_line[0]) { - case "wchar": - io.wchar = uint64.parse (splitted_line[1]); - break; - case "rchar": - io.rchar = uint64.parse (splitted_line[1]); - break; - case "syscr": - io.syscr = uint64.parse (splitted_line[1]); - break; - case "syscw": - io.syscw = uint64.parse (splitted_line[1]); - break; - case "read_bytes": - io.read_bytes = uint64.parse (splitted_line[1]); - break; - case "write_bytes": - io.write_bytes = uint64.parse (splitted_line[1]); - break; - case "cancelled_write_bytes": - io.cancelled_write_bytes = uint64.parse (splitted_line[1]); - break; - default: - warning ("Unknown value in /proc/%d/io", stat.pid); - break; - } - } - - return true; - } - - // Reads the /proc/%pid%/stat file and updates the process with the information therein. - private new bool parse_stat () { - var process_provider = ProcessProvider.get_default (); - string ? stat_contents = process_provider.pids_stat.get (this.stat.pid); - - if (stat_contents == null) return false; - - // debug (stat_contents); - - // Split the contents into an array and parse each value that we care about - - // But first we have to extract the command name, since it might include spaces - // First find the command in stat file. It is inside `(command)` - - /* *INDENT-OFF* */ - Regex regex = /\((.*?)\)/; // vala-lint=space-before-paren, - /* *INDENT-ON* */ - - MatchInfo match_info; - regex.match (stat_contents, 0, out match_info); - string matched_command = match_info.fetch (0); - - // Remove command from stat_contents - stat_contents = stat_contents.replace (matched_command, ""); - - // split the string and extract some stats - var splitted_stat = stat_contents.split (" "); - stat.comm = matched_command[1 : -1]; - - stat.state = splitted_stat[2]; - stat.ppid = int.parse (splitted_stat[3]); - stat.pgrp = int.parse (splitted_stat[4]); - stat.priority = int.parse (splitted_stat[17]); - stat.nice = int.parse (splitted_stat[18]); - stat.num_threads = int.parse (splitted_stat[19]); - - return true; - } - - private new bool parse_statm () { - var process_provider = ProcessProvider.get_default (); - string ? statm_contents = process_provider.pids_stat.get (this.stat.pid); - - if (statm_contents == null) return false; - - var splitted_statm = statm_contents.split (" "); - statm.size = int.parse (splitted_statm[0]); - statm.resident = int.parse (splitted_statm[1]); - statm.shared = int.parse (splitted_statm[2]); - statm.trs = int.parse (splitted_statm[3]); - statm.lrs = int.parse (splitted_statm[4]); - statm.drs = int.parse (splitted_statm[5]); - statm.dt = int.parse (splitted_statm[6]); - - return true; - } - - private new bool get_open_files () { - // try { - // string directory = "/proc/%d/fd".printf (stat.pid); - // Dir dir = Dir.open (directory, 0); - // string ? name = null; - // while ((name = dir.read_name ()) != null) { - // string path = Path.build_filename (directory, name); - - // if (FileUtils.test (path, FileTest.IS_SYMLINK)) { - // string real_path = FileUtils.read_link (path); - //// debug(content); - // open_files_paths.add (real_path); - // } - // } - // } catch (FileError err) { - // if (err is FileError.ACCES) { - // fd_permission_error (err.message); - // } else { - // warning (err.message); - // } - // } - return true; - } - - /** - * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. - */ - private new bool read_cmdline () { - var process_provider = ProcessProvider.get_default (); - string ? cmdline = process_provider.pids_cmdline.get (this.stat.pid); - - - if (cmdline == null) { - return false; - } - - if (cmdline.length <= 0) { - // if cmdline has 0 length we look into stat file - // useful for kworker processes - command = stat.comm; - return true; - } - - command = cmdline; - - return true; - } - - private new void get_usage (uint64 cpu_total, uint64 cpu_last_total) { - // Get CPU usage by process - GTop.ProcTime proc_time; - GTop.get_proc_time (out proc_time, stat.pid); - cpu_percentage = 100 * ((double) (proc_time.rtime - cpu_last_used)) / (cpu_total - cpu_last_total); - cpu_last_used = proc_time.rtime; - - // Making CPU history - if (cpu_percentage_history.size == HISTORY_BUFFER_SIZE) { - cpu_percentage_history.remove_at (0); - } - cpu_percentage_history.add (cpu_percentage); - - // Get memory usage by process - GTop.Memory mem; - GTop.get_mem (out mem); - - GTop.ProcMem proc_mem; - GTop.get_proc_mem (out proc_mem, stat.pid); - mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB - - // also if it is using X Window Server - if (Gdk.Display.get_default () is Gdk.X11.Display) { - Wnck.ResourceUsage resu = Wnck.ResourceUsage.pid_read (Gdk.Display.get_default (), stat.pid); - mem_usage += (resu.total_bytes_estimate / 1024); - } - - var total_installed_memory = (double) mem.total / 1024; - mem_percentage = (mem_usage / total_installed_memory) * 100; - - // Making RAM history - if (mem_percentage_history.size == HISTORY_BUFFER_SIZE) { - mem_percentage_history.remove_at (0); - } - mem_percentage_history.add (mem_percentage); - } - -} diff --git a/src/meson.build b/src/meson.build index ec117034..f7fb6f2a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -58,7 +58,7 @@ source_app_files = [ 'Managers/ContainerManager.vala', 'Managers/Container.vala', 'Managers/ProcessProvider.vala', - 'Managers/ProcessWorkaround.vala', + # 'Managers/ProcessWorkaround.vala', # 'Managers/IProcess.vala', # Services From cbeb5196128ac5d2abe88169505bcbf23637b539 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:18:39 +0100 Subject: [PATCH 28/36] Showing process memory usage works in Flatpak --- src/Managers/Process.vala | 21 ++++++++++++++++----- src/Managers/ProcessProvider.vala | 2 ++ src/Managers/ProcessStructs.vala | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index bb79b9a6..4fe002bc 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -291,6 +291,7 @@ public class Monitor.Process : GLib.Object { stat.num_threads = int.parse (splitted_stat[19]); stat.utime = ulong.parse (splitted_stat[13]); stat.stime = ulong.parse (splitted_stat[14]); + stat.rss = long.parse (splitted_stat[23]); return true; } @@ -299,7 +300,7 @@ public class Monitor.Process : GLib.Object { string ? statm_contents; if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); - statm_contents = process_provider.pids_stat.get (this.stat.pid); + statm_contents = process_provider.pids_statm.get (this.stat.pid); } else { statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); } @@ -393,9 +394,19 @@ public class Monitor.Process : GLib.Object { GTop.Memory mem; GTop.get_mem (out mem); - GTop.ProcMem proc_mem; - GTop.get_proc_mem (out proc_mem, stat.pid); - mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB + if (ProcessUtils.is_flatpak_env ()) { + mem_usage = (stat.rss * 4096 - statm.shared) / 1024; + + if (stat.pid == 552677) { + debug ("%lld %lld", stat.rss, statm.shared); + } + + } else { + GTop.ProcMem proc_mem; + GTop.get_proc_mem (out proc_mem, stat.pid); + mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB + } + // also if it is using X Window Server if (Gdk.Display.get_default () is Gdk.X11.Display) { @@ -413,4 +424,4 @@ public class Monitor.Process : GLib.Object { mem_percentage_history.add (mem_percentage); } -} \ No newline at end of file +} diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 75ef4cb9..7ee14daf 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -7,6 +7,7 @@ namespace Monitor { public Gee.HashMap pids_cmdline = new Gee.HashMap (); public Gee.HashMap pids_stat = new Gee.HashMap (); + public Gee.HashMap pids_statm = new Gee.HashMap (); public Gee.HashMap pids_io = new Gee.HashMap (); public Gee.HashMap pids_status = new Gee.HashMap (); public Gee.HashMap pids_children = new Gee.HashMap (); @@ -36,6 +37,7 @@ namespace Monitor { pids[i] = int.parse (procs[i]["pid"]); pids_cmdline.set (pids[i], procs[i]["cmdline"]); pids_stat.set (pids[i], procs[i]["stat"]); + pids_statm.set (pids[i], procs[i]["statm"]); pids_io.set (pids[i], procs[i]["io"]); pids_children.set (pids[i], procs[i]["children"]); pids_status.set (pids[i], procs[i]["status"]); diff --git a/src/Managers/ProcessStructs.vala b/src/Managers/ProcessStructs.vala index 78878f49..2a352772 100644 --- a/src/Managers/ProcessStructs.vala +++ b/src/Managers/ProcessStructs.vala @@ -104,4 +104,7 @@ public struct Monitor.ProcessStatus { public ulong utime; public ulong stime; + + /** Resident Set Size: number of pages the process has in real memory. */ + public long rss; } From fe48f0ef167d0305fc4835f608e5b8b54d31146d Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:18:59 +0100 Subject: [PATCH 29/36] remove debug message --- src/Managers/Process.vala | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index 4fe002bc..bafbb189 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -396,11 +396,6 @@ public class Monitor.Process : GLib.Object { if (ProcessUtils.is_flatpak_env ()) { mem_usage = (stat.rss * 4096 - statm.shared) / 1024; - - if (stat.pid == 552677) { - debug ("%lld %lld", stat.rss, statm.shared); - } - } else { GTop.ProcMem proc_mem; GTop.get_proc_mem (out proc_mem, stat.pid); From 841fd80df76370060c75c40bc273b9527295a6b4 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Tue, 2 Jan 2024 16:09:52 +0100 Subject: [PATCH 30/36] Workaround started automatically --- com.github.stsdc.monitor.json | 3 ++ ...=> com.github.stsdc.monitor-workaround.py} | 4 ++ flatpak/workaround/meson.build | 4 ++ meson.build | 6 +++ meson_options.txt | 3 +- src/Managers/ProcessProvider.vala | 50 ++++++++----------- src/Managers/ProcessUtils.vala | 49 ++++-------------- 7 files changed, 49 insertions(+), 70 deletions(-) rename flatpak/workaround/{process_monitor.py => com.github.stsdc.monitor-workaround.py} (97%) mode change 100644 => 100755 create mode 100644 flatpak/workaround/meson.build diff --git a/com.github.stsdc.monitor.json b/com.github.stsdc.monitor.json index 1195471a..78dd2144 100644 --- a/com.github.stsdc.monitor.json +++ b/com.github.stsdc.monitor.json @@ -332,6 +332,9 @@ { "name": "com.github.stsdc.monitor", "buildsystem": "meson", + "config-opts": [ + "-Dflatpak-workaround=enabled" + ], "sources": [ { "type": "dir", diff --git a/flatpak/workaround/process_monitor.py b/flatpak/workaround/com.github.stsdc.monitor-workaround.py old mode 100644 new mode 100755 similarity index 97% rename from flatpak/workaround/process_monitor.py rename to flatpak/workaround/com.github.stsdc.monitor-workaround.py index a8feafdb..fd1b6adf --- a/flatpak/workaround/process_monitor.py +++ b/flatpak/workaround/com.github.stsdc.monitor-workaround.py @@ -1,3 +1,7 @@ +#!/usr/bin/python + +"""The workaround script should run only in Flatpak environment.""" + import os import dbus diff --git a/flatpak/workaround/meson.build b/flatpak/workaround/meson.build new file mode 100644 index 00000000..375f837d --- /dev/null +++ b/flatpak/workaround/meson.build @@ -0,0 +1,4 @@ +install_data( + join_paths('com.github.stsdc.monitor-workaround.py'), + install_dir: join_paths(datadir, 'workaround') +) diff --git a/meson.build b/meson.build index 2c47b0f3..3dc1863b 100644 --- a/meson.build +++ b/meson.build @@ -74,4 +74,10 @@ subdir('src') meson.add_install_script('meson/post_install.py') subdir('po') + + +if get_option('flatpak-workaround').enabled() + subdir('flatpak/workaround') +endif + # subdir('tests') \ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt index d0fedb3b..c19f93f2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ -option('indicator-wingpanel', type : 'feature', value : 'disabled', description : 'Enables the Indicator for Wingpanel.') \ No newline at end of file +option('indicator-wingpanel', type : 'feature', value : 'disabled', description : 'Enables the Indicator for Wingpanel.') +option('flatpak-workaround', type : 'feature', value : 'disabled', description : 'Enables the Flatpak workaround.') \ No newline at end of file diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 7ee14daf..b714659a 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -1,10 +1,12 @@ namespace Monitor { - public class ProcessProvider { + public class ProcessProvider : GLib.Object{ private static GLib.Once instance; public static unowned ProcessProvider get_default () { return instance.once (() => { return new ProcessProvider (); }); } + private bool is_flatpak; + public Gee.HashMap pids_cmdline = new Gee.HashMap (); public Gee.HashMap pids_stat = new Gee.HashMap (); public Gee.HashMap pids_statm = new Gee.HashMap (); @@ -14,14 +16,28 @@ namespace Monitor { DBusWorkaroundClient dbus_workaround_client; - public ProcessProvider () { - if (ProcessUtils.is_flatpak_env ()) { + construct { + this.is_flatpak = ProcessUtils.is_flatpak_env (); + if (this.is_flatpak) { + this.spawn_workaround (); dbus_workaround_client = DBusWorkaroundClient.get_default (); } } + private bool spawn_workaround () { + try { + debug ("Spawning workaround..."); + string app_path = ProcessUtils.get_flatpak_app_path (); + string command = @"flatpak-spawn --host env LANG=C $app_path/share/workaround/com.github.stsdc.monitor-workaround.py"; + return GLib.Process.spawn_command_line_async (command); + } catch (SpawnError e) { + warning ("Spawning workaround error: %s\n", e.message); + return false; + } + } + public int[] get_pids () { - if (ProcessUtils.is_flatpak_env ()) { + if (this.is_flatpak) { int[] pids; pids_cmdline.clear (); pids_stat.clear (); @@ -54,31 +70,5 @@ namespace Monitor { return pids; } - - private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { - if (condition == IOCondition.HUP) { - // debug ("%s: The fd has been closed.\n", stream_name); - return false; - } - - try { - string line; - channel.read_line (out line, null, null); - if (line[0].isdigit ()) { - print ("%d\n", int.parse (line)); - // pids.add (line.strip ()); - - } - } catch (IOChannelError e) { - warning ("IOChannelError: %s\n", e.message); - return false; - } catch (ConvertError e) { - warning ("ConvertError: %s\n", e.message); - return false; - } - - return true; - } - } } diff --git a/src/Managers/ProcessUtils.vala b/src/Managers/ProcessUtils.vala index ae0788bb..43e57679 100644 --- a/src/Managers/ProcessUtils.vala +++ b/src/Managers/ProcessUtils.vala @@ -88,48 +88,9 @@ public class Monitor.ProcessUtils { out status ); - - // GLib.Process.spawn_async_with_pipes - // ("/", - // spawn_args, - // Environ.get (), - // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, - // null, - // out child_pid, - // out standard_input, - // out standard_output, - // out standard_error - // ); - // debug ("Status: %d", status); } catch (SpawnError e) { error (e.message); } - // IOChannel output = new IOChannel.unix_new (standard_output); - // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - // if (condition == IOCondition.HUP) { - // print ("%s: The fd has been closed.\n", "stream_name"); - // return false; - // } - - // try { - // string line; - // channel.read_line (out line, null, null); - // print ("%s: %s", "stream_name", line); - // } catch (IOChannelError e) { - // print ("%s: IOChannelError: %s\n", "stream_name", e.message); - // return false; - // } catch (ConvertError e) { - // print ("%s: ConvertError: %s\n", "stream_name", e.message); - // return false; - // } - - // return true; - // }); - - // ChildWatch.add (child_pid, (pid, status) => { - //// Triggered when the child indicated by child_pid exits - // GLib.Process.close_pid (pid); - // }); string ? stdout_no_debug = ""; @@ -167,4 +128,14 @@ public class Monitor.ProcessUtils { return false; } + public static string get_flatpak_app_path () { + string ? flatpak_info_content = ProcessUtils.read_file ("/.flatpak-info"); + foreach (var line in flatpak_info_content.split ("\n")) { + if (line.contains ("app-path")) { + return line.replace ("app-path=", ""); + } + } + return ""; + } + } From cd8ffd39e52cc3283797903decdfe1494aca626c Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:26:10 +0100 Subject: [PATCH 31/36] Ending and killing processes works thru workaround --- .../com.github.stsdc.monitor-workaround.py | 20 +++++++++++++++++-- src/Managers/Process.vala | 8 ++++++++ src/Managers/ProcessProvider.vala | 8 ++++++-- src/Services/DBusWorkaroundClient.vala | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/flatpak/workaround/com.github.stsdc.monitor-workaround.py b/flatpak/workaround/com.github.stsdc.monitor-workaround.py index fd1b6adf..73ef24a8 100755 --- a/flatpak/workaround/com.github.stsdc.monitor-workaround.py +++ b/flatpak/workaround/com.github.stsdc.monitor-workaround.py @@ -3,7 +3,7 @@ """The workaround script should run only in Flatpak environment.""" import os - +import subprocess import dbus import dbus.service import dbus.mainloop.glib @@ -36,7 +36,7 @@ def __init__(self, conn=None, object_path=None, bus_name=None): @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="aa{ss}", sender_keyword="sender", connection_keyword="conn") def GetProcesses(self, name, sender=None, conn=None): - print("GetProcesses") + print("WorkaroundServer: GetProcesses") processes = [] for pid in get_pids(): process = { @@ -77,6 +77,22 @@ def GetProcesses(self, name, sender=None, conn=None): processes.append(process) return processes + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="i", sender_keyword="sender", connection_keyword="conn") + def EndProcess(self, pid, sender=None, conn=None): + print(f"WorkaroundServer: EndProcess: kill -15 {pid}") + try: + (subprocess.check_output(["kill", "-15", str(pid)], stderr=subprocess.STDOUT, shell=False)).decode() + except subprocess.CalledProcessError as err: + print(err) + + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="i", sender_keyword="sender", connection_keyword="conn") + def KillProcess(self, pid, sender=None, conn=None): + print(f"WorkaroundServer: KillProcess: kill -9 {pid}") + try: + (subprocess.check_output(["kill", "-9", str(pid)], stderr=subprocess.STDOUT, shell=False)).decode() + except subprocess.CalledProcessError as err: + print(err) + if __name__ == "__main__": dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index bafbb189..200ca009 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -132,6 +132,14 @@ public class Monitor.Process : GLib.Object { // Ends the process public bool end () { + if (ProcessUtils.is_flatpak_env ()) { + try { + DBusWorkaroundClient.get_default ().interface.end_process (this.stat.pid); + } catch (Error e) { + warning (e.message); + } + } + // Sends a terminate signal if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { return true; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index b714659a..5fc5a737 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -19,7 +19,7 @@ namespace Monitor { construct { this.is_flatpak = ProcessUtils.is_flatpak_env (); if (this.is_flatpak) { - this.spawn_workaround (); + // this.spawn_workaround (); dbus_workaround_client = DBusWorkaroundClient.get_default (); } } @@ -47,7 +47,7 @@ namespace Monitor { try { HashTable[] procs = dbus_workaround_client.interface.get_processes (""); pids = new int[procs.length]; - debug ("Workaround: retrieved pids: %d", procs.length); + debug ("Workaround client: retrieved pids: %d", procs.length); for (int i = 0; i < procs.length; i++) { // debug (procs[i]["pid"]); pids[i] = int.parse (procs[i]["pid"]); @@ -70,5 +70,9 @@ namespace Monitor { return pids; } + + public void end_process (int pid) { + DBusWorkaroundClient.get_default (); + } } } diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala index dc425bfd..e2e6e276 100644 --- a/src/Services/DBusWorkaroundClient.vala +++ b/src/Services/DBusWorkaroundClient.vala @@ -1,6 +1,7 @@ [DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")] public interface Monitor.DBusWorkaroundClientInterface : Object { public abstract HashTable[] get_processes (string empty) throws Error; + public abstract void end_process (int pid) throws Error; } From 3b917e460be9cff2635e0e7a514c1f3a7dbee845 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:27:06 +0100 Subject: [PATCH 32/36] Uncomment spawn_workaround() --- src/Managers/ProcessProvider.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 5fc5a737..5d42d994 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -19,7 +19,7 @@ namespace Monitor { construct { this.is_flatpak = ProcessUtils.is_flatpak_env (); if (this.is_flatpak) { - // this.spawn_workaround (); + this.spawn_workaround (); dbus_workaround_client = DBusWorkaroundClient.get_default (); } } From 7046f0f8ca82f3ce2d6bbfb80788527caa2090f9 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:28:18 +0100 Subject: [PATCH 33/36] fix lint --- src/Managers/ProcessProvider.vala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 5d42d994..df3b2ba2 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -1,5 +1,5 @@ namespace Monitor { - public class ProcessProvider : GLib.Object{ + public class ProcessProvider : GLib.Object { private static GLib.Once instance; public static unowned ProcessProvider get_default () { return instance.once (() => { return new ProcessProvider (); }); @@ -26,7 +26,7 @@ namespace Monitor { private bool spawn_workaround () { try { - debug ("Spawning workaround..."); + debug ("Spawning workaround. . ."); string app_path = ProcessUtils.get_flatpak_app_path (); string command = @"flatpak-spawn --host env LANG=C $app_path/share/workaround/com.github.stsdc.monitor-workaround.py"; return GLib.Process.spawn_command_line_async (command); @@ -74,5 +74,6 @@ namespace Monitor { public void end_process (int pid) { DBusWorkaroundClient.get_default (); } + } } From 9d288563e19b81d35a95e60ac06f7bac658d22a5 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sat, 6 Jan 2024 13:27:25 +0100 Subject: [PATCH 34/36] add kill signal; show root user if uid 0 --- src/Managers/Process.vala | 17 ++++++++++++++++- src/Services/DBusWorkaroundClient.vala | 8 ++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index 200ca009..b59db33b 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -100,7 +100,12 @@ public class Monitor.Process : GLib.Object { var process_provider = ProcessProvider.get_default (); string ? status = process_provider.pids_status.get (this.stat.pid); var status_line = status.split ("\n"); - return int.parse (status_line[8].split ("\t")[1]); + + int uid = int.parse (status_line[8].split ("\t")[1]); + + // @TODO parse users file instead + if (uid == 0) username = "root"; + return uid; } GTop.ProcUid proc_uid; @@ -123,6 +128,15 @@ public class Monitor.Process : GLib.Object { // Kills the process public bool kill () { + if (ProcessUtils.is_flatpak_env ()) { + try { + DBusWorkaroundClient.get_default ().interface.kill_process (this.stat.pid); + return true; + } catch (Error e) { + warning (e.message); + } + } + // Sends a kill signal that cannot be ignored if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) { return true; @@ -135,6 +149,7 @@ public class Monitor.Process : GLib.Object { if (ProcessUtils.is_flatpak_env ()) { try { DBusWorkaroundClient.get_default ().interface.end_process (this.stat.pid); + return true; } catch (Error e) { warning (e.message); } diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala index e2e6e276..46e01be7 100644 --- a/src/Services/DBusWorkaroundClient.vala +++ b/src/Services/DBusWorkaroundClient.vala @@ -2,6 +2,7 @@ public interface Monitor.DBusWorkaroundClientInterface : Object { public abstract HashTable[] get_processes (string empty) throws Error; public abstract void end_process (int pid) throws Error; + public abstract void kill_process (int pid) throws Error; } @@ -13,9 +14,6 @@ public class Monitor.DBusWorkaroundClient : Object { return instance.once (() => { return new DBusWorkaroundClient (); }); } - public signal void monitor_vanished (); - public signal void monitor_appeared (); - construct { try { interface = Bus.get_proxy_sync ( @@ -27,9 +25,7 @@ public class Monitor.DBusWorkaroundClient : Object { Bus.watch_name ( BusType.SESSION, "com.github.stsdc.monitor.workaround", - BusNameWatcherFlags.NONE, - () => monitor_appeared (), - () => monitor_vanished () + BusNameWatcherFlags.NONE ); } catch (IOError e) { error ("Monitor Indicator DBus: %s\n", e.message); From b2119c073e8fe6f0484e1f7c8885f30e5f0b595c Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sat, 6 Jan 2024 14:16:58 +0100 Subject: [PATCH 35/36] Save flatpak-infobar-state --- data/com.github.stsdc.monitor.gschema.xml | 7 ++++++- src/MainWindow.vala | 16 ++++++++++++++++ src/Managers/Process.vala | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/data/com.github.stsdc.monitor.gschema.xml b/data/com.github.stsdc.monitor.gschema.xml index a242f8ff..dd366b6b 100644 --- a/data/com.github.stsdc.monitor.gschema.xml +++ b/data/com.github.stsdc.monitor.gschema.xml @@ -90,10 +90,15 @@ Update time This value sets update time for updating data and charts. - + false To show Containers view or not To show Containers view or not + + true + To show Flatpak infobar or not + To show Flatpak infobar or not + diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 5c620623..86c51feb 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -60,7 +60,23 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { orientation = Gtk.Orientation.VERTICAL }; + var flatpak_infobar = new Gtk.InfoBar (); + flatpak_infobar.message_type = Gtk.MessageType.WARNING; + flatpak_infobar.revealed = MonitorApp.settings.get_boolean ("flatpak-infobar-state"); + var button = new Gtk.Button.with_label("Hide"); + button.margin_start = 20; + button.hexpand = true; + button.halign = Gtk.Align.END; + flatpak_infobar.get_content_area ().add (new Gtk.Label (_("Some of Monitor features are limited by Flatpak environment."))); + flatpak_infobar.get_content_area ().add (new Gtk.LinkButton.with_label ("https://github.com/stsdc/monitor", _("Try native."))); + flatpak_infobar.get_content_area ().add (button); + button.clicked.connect(() => { + flatpak_infobar.revealed = false; + MonitorApp.settings.set_boolean ("flatpak-infobar-state", false); + }); + grid.add (headerbar); + if (ProcessUtils.is_flatpak_env ()) grid.add (flatpak_infobar); grid.add (stack); grid.add (statusbar); diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index b59db33b..b21edc0a 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -100,10 +100,10 @@ public class Monitor.Process : GLib.Object { var process_provider = ProcessProvider.get_default (); string ? status = process_provider.pids_status.get (this.stat.pid); var status_line = status.split ("\n"); - + int uid = int.parse (status_line[8].split ("\t")[1]); - // @TODO parse users file instead + // @TODO parse users file instead if (uid == 0) username = "root"; return uid; From 683cb6061ad5de56480255f617bbabe8bab7f458 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Sat, 6 Jan 2024 14:17:09 +0100 Subject: [PATCH 36/36] fix lint --- src/MainWindow.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 86c51feb..93235af1 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -63,14 +63,14 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { var flatpak_infobar = new Gtk.InfoBar (); flatpak_infobar.message_type = Gtk.MessageType.WARNING; flatpak_infobar.revealed = MonitorApp.settings.get_boolean ("flatpak-infobar-state"); - var button = new Gtk.Button.with_label("Hide"); + var button = new Gtk.Button.with_label ("Hide"); button.margin_start = 20; button.hexpand = true; button.halign = Gtk.Align.END; flatpak_infobar.get_content_area ().add (new Gtk.Label (_("Some of Monitor features are limited by Flatpak environment."))); flatpak_infobar.get_content_area ().add (new Gtk.LinkButton.with_label ("https://github.com/stsdc/monitor", _("Try native."))); flatpak_infobar.get_content_area ().add (button); - button.clicked.connect(() => { + button.clicked.connect (() => { flatpak_infobar.revealed = false; MonitorApp.settings.set_boolean ("flatpak-infobar-state", false); });