зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #5664 - [Issue#5582] Add Desktop Notifications for Long builds (from dhananjay92:DesktopNotif); r=jdm
Supported for Linux & Windows platforms. If it fails to generate the desktop notification, it simply gives a soft warning on the terminal. This PR is solving Issue #5582. Source-Repo: https://github.com/servo/servo Source-Revision: a13fa9c0c00fe99b5af19d873a9240dce522f16b
This commit is contained in:
Родитель
4872b079c3
Коммит
d38248989c
|
@ -1,5 +1,6 @@
|
|||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import sys
|
||||
import os
|
||||
import os.path as path
|
||||
import subprocess
|
||||
|
@ -16,6 +17,48 @@ from servo.command_base import CommandBase, cd
|
|||
def is_headless_build():
|
||||
return int(os.getenv('SERVO_HEADLESS', 0)) == 1
|
||||
|
||||
# Function to generate desktop notification once build is completed & limit exceeded!
|
||||
def notify(elapsed):
|
||||
if elapsed < 300:
|
||||
return
|
||||
|
||||
if sys.platform.startswith('linux'):
|
||||
try:
|
||||
import dbus
|
||||
bus = dbus.SessionBus()
|
||||
notify_obj = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
|
||||
method = notify_obj.get_dbus_method('Notify', 'org.freedesktop.Notifications')
|
||||
method('Servo Build System', 0, '', ' Servo build complete!', '', [], [], -1)
|
||||
except:
|
||||
print("[Warning] Could not generate notification! Please make sure that the python dbus module is installed!")
|
||||
|
||||
elif sys.platform.startswith('win'):
|
||||
try:
|
||||
from ctypes import Structure, windll, POINTER, sizeof
|
||||
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
|
||||
class FLASHWINDOW(Structure):
|
||||
_fields_ = [("cbSize", UINT),
|
||||
("hwnd", HANDLE),
|
||||
("dwFlags", DWORD),
|
||||
("uCount", UINT),
|
||||
("dwTimeout", DWORD)]
|
||||
FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
|
||||
FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
|
||||
FLASHW_CAPTION = 0x01
|
||||
FLASHW_TRAY = 0x02
|
||||
FLASHW_TIMERNOFG = 0x0C
|
||||
params = FLASHWINDOW(sizeof(FLASHWINDOW),
|
||||
windll.kernel32.GetConsoleWindow(),
|
||||
FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
|
||||
FlashWindowEx(params)
|
||||
except:
|
||||
print("[Warning] Could not generate notification! Please make sure that the required libraries are installed!")
|
||||
|
||||
elif sys.platform.startswith('darwin'):
|
||||
# Notification code for Darwin here! For the time being printing simple msg
|
||||
print("[Warning] : Darwin System! Notifications not supported currently!")
|
||||
|
||||
|
||||
@CommandProvider
|
||||
class MachCommands(CommandBase):
|
||||
@Command('build',
|
||||
|
@ -102,6 +145,9 @@ class MachCommands(CommandBase):
|
|||
env=env, cwd=self.servo_crate())
|
||||
elapsed = time() - build_start
|
||||
|
||||
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||
notify(elapsed)
|
||||
|
||||
print("Build completed in %0.2fs" % elapsed)
|
||||
return status
|
||||
|
||||
|
@ -135,6 +181,9 @@ class MachCommands(CommandBase):
|
|||
env=self.build_env())
|
||||
elapsed = time() - build_start
|
||||
|
||||
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||
notify(elapsed)
|
||||
|
||||
print("CEF build completed in %0.2fs" % elapsed)
|
||||
|
||||
return ret
|
||||
|
@ -170,6 +219,9 @@ class MachCommands(CommandBase):
|
|||
ret = subprocess.call(["cargo", "build"] + opts, env=env)
|
||||
elapsed = time() - build_start
|
||||
|
||||
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||
notify(elapsed)
|
||||
|
||||
print("Gonk build completed in %0.2fs" % elapsed)
|
||||
|
||||
return ret
|
||||
|
|
Загрузка…
Ссылка в новой задаче