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

36
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 6228K of libraries. Click here for Pure Java version (8081L/42K).

1  
!7
2  
3  
set flag OshiNotSticky.
4  
5  
cmodule MemoryTrayIcon > DynPrintLog {
6  
  transient S value; // OS size in MB + free memory
7  
  transient JLabel lbl;
8  
  transient bool _startMinimized = true;
9  
  switchable bool countSwap = true;
10  
  switchable double interval = 10.0; // restart to take effect
11  
  switchable bool showOSSizeInTray = true; // otherwise only free mem, full specs in tooltip
12  
  transient long processSize;
13  
  
14  
  start {
15  
    dm_addTrayIcon(onLeftClick(rThread dm_verboseGC,
16  
      lbl = dm_fieldLabel_noAutoToolTip('value)));
17  
    componentPopupMenuItems(lbl,
18  
      "Garbage Collect", rThread { dm_gc(); actualUpdate(); },
19  
      "Show Module", rThread dm_showModule,
20  
      "Remove", rThread dm_deleteModule);
21  
    doEveryAndNow(interval, r actualUpdate);
22  
    dm_registerAs_direct processSize();
23  
  }
24  
  
25  
  void actualUpdate {
26  
    processSize = oshi_currentProcessResidentSize();
27  
    long mb = toM(processSize);
28  
    GlobalMemory mem = oshi_systemMemory();
29  
    long mb2 = freeSystemMemory(mem);
30  
    if (countSwap) mb2 -= mem.getSwapUsed();
31  
    mb2 = toM(mb2);
32  
    if (set_trueIfChanged(this, value := (showOSSizeInTray ? mb + " / " : "") + mb2))
33  
      fireChangeWithoutPersisting();
34  
    toolTip(lbl, "OS size in memory: " + mb + " MB, free system memory: " + mb2 + " MB");
35  
  }
36  
}

Author comment

Began life as a copy of #1020802

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pzhvpgtvlbxg, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022569
Snippet name: OS Size + Free Memory Tray Icon [Dyn Module]
Eternal ID of this version: #1022569/10
Text MD5: 8fbd3974a23f03d88ce1cb28c1e612bb
Transpilation MD5: 00bd1f931130137c1ab90441fb0b0fcd
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-19 14:23:54
Source code size: 1305 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 199 / 91826
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1022569 & http://1022569.tinybrain.de