[2d3d31b] | 1 | # |
---|
| 2 | # Copyright (C) 2021 Soleta Networks <info@soleta.eu> |
---|
| 3 | # |
---|
| 4 | # This program is free software: you can redistribute it and/or modify it under |
---|
| 5 | # the terms of the GNU Affero General Public License as published by the |
---|
| 6 | # Free Software Foundation; either version 3 of the License, or |
---|
| 7 | # (at your option) any later version. |
---|
| 8 | |
---|
| 9 | import os |
---|
[69d214f] | 10 | from pystray import Icon, Menu, MenuItem |
---|
| 11 | import multiprocessing as mp |
---|
| 12 | from multiprocessing import Process |
---|
| 13 | from PIL import Image, ImageDraw |
---|
| 14 | |
---|
[2d3d31b] | 15 | from src.ogRest import ThreadState |
---|
| 16 | |
---|
| 17 | |
---|
[69d214f] | 18 | def _create_default_image(): |
---|
| 19 | """ |
---|
| 20 | Creates a default image for the tray icon. Use in case |
---|
| 21 | no favicon.ico is found. |
---|
| 22 | """ |
---|
| 23 | width = height = 250 |
---|
| 24 | color1 = (255, 255, 255) |
---|
| 25 | color2 = (255, 0, 255) |
---|
| 26 | |
---|
| 27 | image = Image.new('RGB', (width, height), color1) |
---|
| 28 | dc = ImageDraw.Draw(image) |
---|
| 29 | dc.rectangle( |
---|
| 30 | (width // 2, 0, width, height // 2), |
---|
| 31 | fill=color2) |
---|
| 32 | dc.rectangle( |
---|
| 33 | (0, height // 2, width // 2, height), |
---|
| 34 | fill=color2) |
---|
| 35 | |
---|
| 36 | return image |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | def create_image(): |
---|
| 40 | try: |
---|
| 41 | image = Image.open(r'./favicon.ico') |
---|
| 42 | image = Image.composite(image, Image.new('RGB', image.size, 'white'), image) |
---|
| 43 | except: |
---|
| 44 | image = _create_default_image() |
---|
| 45 | return image |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | def create_systray(): |
---|
| 49 | menu = Menu(MenuItem('Powered by Soleta Networks!', |
---|
| 50 | lambda icon, item: 1)) |
---|
| 51 | icon = Icon('ogClient', create_image(), menu=menu) |
---|
| 52 | assert icon.icon |
---|
| 53 | icon.run() |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | systray_p = Process(target=create_systray) |
---|
| 57 | |
---|
| 58 | |
---|
[2d3d31b] | 59 | class OgLinuxOperations: |
---|
| 60 | |
---|
[69d214f] | 61 | def __init__(self): |
---|
| 62 | mp.set_start_method('spawn') |
---|
| 63 | systray_p.start() |
---|
| 64 | |
---|
[2d3d31b] | 65 | def _restartBrowser(self, url): |
---|
| 66 | raise NotImplementedError |
---|
| 67 | |
---|
| 68 | def poweroff(self): |
---|
[69d214f] | 69 | systray_p.terminate() |
---|
[2d3d31b] | 70 | os.system('systemctl poweroff') |
---|
| 71 | |
---|
| 72 | def reboot(self): |
---|
[69d214f] | 73 | systray_p.terminate() |
---|
[2d3d31b] | 74 | os.system('systemctl reboot') |
---|
| 75 | |
---|
| 76 | def shellrun(self, request, ogRest): |
---|
| 77 | raise NotImplementedError |
---|
| 78 | |
---|
| 79 | def session(self, request, ogRest): |
---|
| 80 | raise NotImplementedError |
---|
| 81 | |
---|
| 82 | def hardware(self, path, ogRest): |
---|
| 83 | raise NotImplementedError |
---|
| 84 | |
---|
| 85 | def setup(self, request, ogRest): |
---|
| 86 | raise NotImplementedError |
---|
| 87 | |
---|
| 88 | def image_restore(self, request, ogRest): |
---|
| 89 | raise NotImplementedError |
---|
| 90 | |
---|
| 91 | def image_create(self, path, request, ogRest): |
---|
| 92 | raise NotImplementedError |
---|
| 93 | |
---|
| 94 | def refresh(self, ogRest): |
---|
| 95 | return {"status": "LINUX"} |
---|
| 96 | |
---|
| 97 | def probe(self, ogRest): |
---|
| 98 | return {'status': 'LINUX' if ogRest.state != ThreadState.BUSY else 'BSY'} |
---|