Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image Upload data

33
LINES

< > BotCompany Repo | #1022569 - OS Size + Free Memory Tray Icon [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 6168K of libraries. Click here for Pure Java version (5800L/29K).

!7

set flag OshiNotSticky.

cmodule MemoryTrayIcon > DynPrintLog {
  transient S value; // OS size in MB + free memory
  transient JLabel lbl;
  transient bool _startMinimized = true;
  switchable bool countSwap = true;
  transient long processSize;
  
  start {
    dm_addTrayIcon(onLeftClick(rThread { print("GC!"); timedGCPlusDeadlockSolving_printAlways(); },
      lbl = dm_fieldLabel_noAutoToolTip('value)));
    componentPopupMenuItems(lbl,
      "Garbage Collect", rThread { dm_gc(); actualUpdate(); },
      "Show Module", rThread dm_showModule,
      "Remove", rThread dm_deleteModule);
    doEveryAndNow(10.0, r actualUpdate);
    dm_registerAs_direct processSize();
  }
  
  void actualUpdate {
    processSize = oshi_currentProcessResidentSize();
    long mb = toM(processSize);
    GlobalMemory mem = oshi_systemMemory();
    long mb2 = freeSystemMemory(mem);
    if (countSwap) mb2 -= mem.getSwapUsed();
    mb2 = toM(mb2);
    setField(value := mb + " / " + mb2);
    toolTip(lbl, "OS size in memory: " + mb + " MB, free system memory: " + mb2 + " MB");
  }
}

Author comment

Began life as a copy of #1020802

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1022569
Snippet name: OS Size + Free Memory Tray Icon [Dyn Module]
Eternal ID of this version: #1022569/6
Text MD5: fb82c24ce4baf0d8bcc5d98b6ab8396f
Transpilation MD5: 79c22dfbe3aaeefea72048ee62403868
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-13 20:54:53
Source code size: 1107 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 62 / 15614
Version history: 5 change(s)
Referenced in: [show references]