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

44
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 6517K of libraries. Click here for Pure Java version (10969L/56K).

1  
!7
2  
3  
set flag OshiNotSticky.
4  
5  
cm 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, freeMem, totalMem;
13  
  
14  
  start {
15  
    dm_registerAs_direct processSize();
16  
    
17  
    dm_vmBus_answerToMessage freeSystemMemory(() -> freeMem);
18  
    dm_vmBus_answerToMessage totalSystemMemory(() -> totalMem);
19  
    
20  
    doEveryAndNow(interval, r actualUpdate);
21  
    dm_addTrayIcon(onLeftClick(rThreadEnter dm_verboseGC,
22  
      lbl = dm_fieldLabel_noAutoToolTip('value)));
23  
    componentPopupMenuItems(lbl,
24  
      "Garbage Collect", rThreadEnter { dm_gc(); actualUpdate(); },
25  
      "Show Module", rThreadEnter dm_showModule,
26  
      "Remove", rThreadEnter dm_deleteModule);
27  
  }
28  
  
29  
  void actualUpdate {
30  
    processSize = oshi_currentProcessResidentSize();
31  
    long mb = toM(processSize);
32  
    GlobalMemory mem = oshi_systemMemory();
33  
    totalMem = mem.getTotal();
34  
    long mb2 = freeSystemMemory(mem);
35  
    if (countSwap) mb2 -= mem.getSwapUsed();
36  
    freeMem = mb2;
37  
    mb2 = toM(mb2);
38  
    if (set_trueIfChanged(this, value := (showOSSizeInTray ? mb + " / " : "") + mb2)) {
39  
      fireChangeWithoutPersisting();
40  
      vmBus_send processSize(processSize);
41  
    }
42  
    toolTip(lbl, "OS size in memory: " + mb + " MB, free system memory: " + mb2 + " MB");
43  
  }
44  
}

Author comment

Began life as a copy of #1020802

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022569
Snippet name: OS Size + Free Memory Tray Icon [Dyn Module]
Eternal ID of this version: #1022569/16
Text MD5: 5002b2b62a09eec3c6351ee16943ae8c
Transpilation MD5: ae930525ae19efb1d436cf3b11dbafa6
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-02 00:53:05
Source code size: 1584 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 497 / 534691
Version history: 15 change(s)
Referenced in: [show references]