[~] Refactor
This commit is contained in:
parent
e5ed84c35f
commit
d5e85ccfeb
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
tmp
|
tmp
|
||||||
__pycache__
|
__pycache__
|
||||||
|
d2/book1/books
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
$(window).on('load', () => {
|
(function() {
|
||||||
window.context.books.push(`
|
window.context.books.push(`
|
||||||
DEATH of a HERO
|
DEATH of a HERO
|
||||||
|
|
||||||
@ -4747,4 +4747,5 @@ $(window).on('load', () => {
|
|||||||
|
|
||||||
In an agony of helpless grief and pity.
|
In an agony of helpless grief and pity.
|
||||||
`);
|
`);
|
||||||
});
|
window.context.update_books();
|
||||||
|
})();
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
|
|
||||||
<title>Speech synthesiser</title>
|
<title>Speech synthesiser</title>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.context = {};
|
||||||
|
window.context.books = [];
|
||||||
|
</script>
|
||||||
<script src="NoSleep.min.js"></script>
|
<script src="NoSleep.min.js"></script>
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
<script src="book.js"></script>
|
<script src="book.js"></script>
|
||||||
@ -50,7 +54,7 @@
|
|||||||
<div class=screen>
|
<div class=screen>
|
||||||
<div class=widget>
|
<div class=widget>
|
||||||
<select name=book>
|
<select name=book>
|
||||||
<option value=0>Death of a Hear</option>
|
<!--<option value=0>Death of a Hear</option>-->
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
<br/>
|
||||||
<span>Current Sentence: </span>
|
<span>Current Sentence: </span>
|
||||||
@ -59,6 +63,7 @@
|
|||||||
<input type=input name=total-sentences disabled>
|
<input type=input name=total-sentences disabled>
|
||||||
</input>
|
</input>
|
||||||
<br/>
|
<br/>
|
||||||
|
<input type=button name=add-book value="Add Book">
|
||||||
<input type=button name=read-aloud value="Read Aloud">
|
<input type=button name=read-aloud value="Read Aloud">
|
||||||
<input type=button name=debug value="Debug">
|
<input type=button name=debug value="Debug">
|
||||||
</input>
|
</input>
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
$(window).on('load', () => {
|
$(window).on('load', () => {
|
||||||
window.context = {};
|
|
||||||
window.context.books = [];
|
|
||||||
|
|
||||||
var synth = window.speechSynthesis;
|
var synth = window.speechSynthesis;
|
||||||
|
|
||||||
@ -29,9 +27,20 @@ $(window).on('load', () => {
|
|||||||
$('.screen .widget input[name=total-sentences]'),
|
$('.screen .widget input[name=total-sentences]'),
|
||||||
read_aloud:
|
read_aloud:
|
||||||
$('.screen .widget input[name=read-aloud]'),
|
$('.screen .widget input[name=read-aloud]'),
|
||||||
|
add_book:
|
||||||
|
$('.screen .widget input[name=add-book]'),
|
||||||
debug:
|
debug:
|
||||||
$('.screen .widget input[name=debug]'),
|
$('.screen .widget input[name=debug]'),
|
||||||
};
|
};
|
||||||
|
context.update_books = () => {
|
||||||
|
context.ui.books_select.empty();
|
||||||
|
window.context.books.map(
|
||||||
|
(o, i) => $('<option>').attr('value', '' + i).text(o.slice(0, 10))
|
||||||
|
).forEach((o) => context.ui.books_select.append(o))
|
||||||
|
}
|
||||||
|
|
||||||
|
context.update_books();
|
||||||
|
|
||||||
context.sentences = null;
|
context.sentences = null;
|
||||||
context.pending_stop = false;
|
context.pending_stop = false;
|
||||||
context.current_book = null;
|
context.current_book = null;
|
||||||
@ -328,6 +337,22 @@ $(window).on('load', () => {
|
|||||||
|
|
||||||
context.callbacks.init();
|
context.callbacks.init();
|
||||||
|
|
||||||
|
context.ui.add_book.on(
|
||||||
|
'click',
|
||||||
|
async () => {
|
||||||
|
alert('fuck');
|
||||||
|
let book = await (
|
||||||
|
(await fetch(
|
||||||
|
'books/' + prompt('enter book file', '1.txt')
|
||||||
|
)).text()
|
||||||
|
);
|
||||||
|
//let book = prompt('enter text', '');
|
||||||
|
//let title = prompt('enter title', '');
|
||||||
|
//window.context.books.push(title + '\n' + book);
|
||||||
|
window.context.books.push(book);
|
||||||
|
window.context.update_books();
|
||||||
|
},
|
||||||
|
);
|
||||||
context.ui.read_aloud.on(
|
context.ui.read_aloud.on(
|
||||||
'click',
|
'click',
|
||||||
context.callbacks.ui_read_aloud_on_click,
|
context.callbacks.ui_read_aloud_on_click,
|
||||||
|
@ -724,6 +724,7 @@ def eternal_oom(argv):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
mem_used = None
|
mem_used = None
|
||||||
|
mem_stat = None
|
||||||
|
|
||||||
def oom_mem_high(memory_limit=None):
|
def oom_mem_high(memory_limit=None):
|
||||||
nonlocal mem_used
|
nonlocal mem_used
|
||||||
@ -731,12 +732,17 @@ def eternal_oom(argv):
|
|||||||
if memory_limit is None:
|
if memory_limit is None:
|
||||||
memory_limit = options.memory_limit
|
memory_limit = options.memory_limit
|
||||||
|
|
||||||
return mem_used > options.memory_limit
|
return mem_used > memory_limit
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
mem_used = memory_stats()['mem_used']
|
mem_stat = memory_stats()
|
||||||
|
mem_used = mem_stat['mem_used']
|
||||||
|
|
||||||
if not oom_mem_high(options.memory_limit / 2):
|
if options.memory_limit < mem_stat['mem_total'] and not oom_mem_high(
|
||||||
|
mem_stat['mem_total'] - (
|
||||||
|
mem_stat['mem_total'] - options.memory_limit
|
||||||
|
) / 2
|
||||||
|
):
|
||||||
extra_filters = lambda row: (
|
extra_filters = lambda row: (
|
||||||
'chrome' in row['COMMAND_y'] and '--type=renderer' in row['COMMAND_y']
|
'chrome' in row['COMMAND_y'] and '--type=renderer' in row['COMMAND_y']
|
||||||
or not 'chrome' in row['COMMAND_y']
|
or not 'chrome' in row['COMMAND_y']
|
||||||
@ -1441,7 +1447,7 @@ def desktop_services(argv):
|
|||||||
try:
|
try:
|
||||||
t4 = subprocess.check_output([
|
t4 = subprocess.check_output([
|
||||||
'playerctl', '-p', 'vlc', 'status'
|
'playerctl', '-p', 'vlc', 'status'
|
||||||
]).decode('utf-8').strip() == 'Playing'
|
], timeout=1,).decode('utf-8').strip() == 'Playing'
|
||||||
except:
|
except:
|
||||||
logging.error(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
|
|
||||||
@ -1537,7 +1543,7 @@ def desktop_services(argv):
|
|||||||
end=''
|
end=''
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
print(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
|
|
||||||
class Backlight:
|
class Backlight:
|
||||||
class Direction(enum.Enum):
|
class Direction(enum.Enum):
|
||||||
@ -1556,7 +1562,10 @@ def desktop_services(argv):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def dpms_get(cls):
|
def dpms_get(cls):
|
||||||
try:
|
try:
|
||||||
t1 = subprocess.check_output(['swaymsg', '-r', '-t', 'get_outputs'])
|
t1 = subprocess.check_output(
|
||||||
|
['swaymsg', '-r', '-t', 'get_outputs'],
|
||||||
|
timeout=1
|
||||||
|
)
|
||||||
t2 = t1.decode('utf-8')
|
t2 = t1.decode('utf-8')
|
||||||
t3 = json.loads(t2)
|
t3 = json.loads(t2)
|
||||||
t4 = [
|
t4 = [
|
||||||
@ -1821,6 +1830,7 @@ def desktop_services(argv):
|
|||||||
shutdown = False
|
shutdown = False
|
||||||
|
|
||||||
def on_interrupt(*args, **kwargs):
|
def on_interrupt(*args, **kwargs):
|
||||||
|
logging.info('blah')
|
||||||
nonlocal shutdown
|
nonlocal shutdown
|
||||||
shutdown = True
|
shutdown = True
|
||||||
|
|
||||||
@ -1835,11 +1845,12 @@ def desktop_services(argv):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if options.cpufreq == 0:
|
if options.cpufreq == 0:
|
||||||
print('launching cpufreq, need sudo')
|
logging.info('launching cpufreq, need sudo')
|
||||||
subprocess.check_call(['sudo', 'whoami'])
|
subprocess.check_call(['sudo', 'whoami'])
|
||||||
|
|
||||||
services.append(
|
services.append(
|
||||||
subprocess.Popen(r'''
|
subprocess.Popen(
|
||||||
|
r'''
|
||||||
exec sudo sh -c 'echo cpufreq, user; whoami;
|
exec sudo sh -c 'echo cpufreq, user; whoami;
|
||||||
while [[ -a /proc/{pid} ]]; do
|
while [[ -a /proc/{pid} ]]; do
|
||||||
echo passive > /sys/devices/system/cpu/intel_pstate/status;
|
echo passive > /sys/devices/system/cpu/intel_pstate/status;
|
||||||
@ -1851,7 +1862,12 @@ def desktop_services(argv):
|
|||||||
done;
|
done;
|
||||||
sleep 10;
|
sleep 10;
|
||||||
done;'
|
done;'
|
||||||
'''.format(pid=os.getpid()), shell=True)
|
'''.format(pid=os.getpid()),
|
||||||
|
shell=True,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
class start_swayidle:
|
class start_swayidle:
|
||||||
@ -1893,15 +1909,19 @@ def desktop_services(argv):
|
|||||||
lock 'echo t2; read;' \
|
lock 'echo t2; read;' \
|
||||||
unlock 'echo t3;' \
|
unlock 'echo t3;' \
|
||||||
before-sleep 'echo t6; read;' \
|
before-sleep 'echo t6; read;' \
|
||||||
after-resume 'echo t7; read;'
|
after-resume 'echo t7; read;' 2>&1
|
||||||
''',
|
''',
|
||||||
shell=True,
|
shell=True,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
restore_signals=False,
|
||||||
|
preexec_fn=lambda : os.setpgrp(),
|
||||||
)
|
)
|
||||||
self.output = intercept_output(
|
self.output = intercept_output(
|
||||||
self.swayidle,
|
self.swayidle,
|
||||||
real_time=True,
|
real_time=True,
|
||||||
|
transform_callback=lambda x: [logging.info(x), b''][-1],
|
||||||
)
|
)
|
||||||
self.events = []
|
self.events = []
|
||||||
self.last_skip_loop = None
|
self.last_skip_loop = None
|
||||||
@ -1977,6 +1997,10 @@ def desktop_services(argv):
|
|||||||
def check(self):
|
def check(self):
|
||||||
new_events = []
|
new_events = []
|
||||||
|
|
||||||
|
class event_t(enum.Enum):
|
||||||
|
idle_state = 'idle state'
|
||||||
|
active_state = 'active state'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if self.output is None:
|
if self.output is None:
|
||||||
break
|
break
|
||||||
@ -2005,17 +2029,21 @@ def desktop_services(argv):
|
|||||||
aggregated=False,
|
aggregated=False,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
new_events.extend([
|
for line in lines:
|
||||||
line
|
if event_t.idle_state.value in line:
|
||||||
for line in lines
|
line = event_t.idle_state.value
|
||||||
|
elif event_t.active_state.value in line:
|
||||||
|
line = event_t.active_state.value
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
if line in [
|
if line in [
|
||||||
't1', 't2', 't3', 't4',
|
't1', 't2', 't3', 't4',
|
||||||
't5', 't5', 't6', 't7',
|
't5', 't5', 't6', 't7',
|
||||||
] or (
|
event_t.idle_state.value,
|
||||||
'idle state' in line or \
|
event_t.active_state.value,
|
||||||
'active state' in line
|
]:
|
||||||
)
|
new_events.append(line)
|
||||||
])
|
|
||||||
|
|
||||||
def retry(cb, cnt=None):
|
def retry(cb, cnt=None):
|
||||||
if cnt is None:
|
if cnt is None:
|
||||||
@ -2023,7 +2051,7 @@ def desktop_services(argv):
|
|||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
print('retry i = %d, cnt = %d' % (i, cnt))
|
logging.info('retry i = %d, cnt = %d' % (i, cnt))
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
subprocess.call(['swaymsg', '-t', 'get_version']) == 0
|
subprocess.call(['swaymsg', '-t', 'get_version']) == 0
|
||||||
@ -2055,7 +2083,7 @@ def desktop_services(argv):
|
|||||||
self.backlight.dpms
|
self.backlight.dpms
|
||||||
):
|
):
|
||||||
skip_loop = True
|
skip_loop = True
|
||||||
print(
|
logging.info(
|
||||||
'skip loop, %s' % (
|
'skip loop, %s' % (
|
||||||
[
|
[
|
||||||
json.dumps(self.events),
|
json.dumps(self.events),
|
||||||
@ -2093,13 +2121,13 @@ def desktop_services(argv):
|
|||||||
if o == 't1':
|
if o == 't1':
|
||||||
#if self.force_idle():
|
#if self.force_idle():
|
||||||
# subprocess.check_call(self.commands['lock'], shell=True)
|
# subprocess.check_call(self.commands['lock'], shell=True)
|
||||||
print('started t1')
|
logging.info('started t1')
|
||||||
if self.force_idle():
|
if self.force_idle():
|
||||||
subprocess.check_call(self.commands['timeout1'], shell=True)
|
subprocess.check_call(self.commands['timeout1'], shell=True)
|
||||||
print('done t1')
|
logging.info('done t1')
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
elif o == 't2':
|
elif o == 't2':
|
||||||
print('started lock')
|
logging.info('started lock')
|
||||||
if self.force_idle():
|
if self.force_idle():
|
||||||
custom_notify(
|
custom_notify(
|
||||||
title='swayidle',
|
title='swayidle',
|
||||||
@ -2120,35 +2148,35 @@ def desktop_services(argv):
|
|||||||
) == 0:
|
) == 0:
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
print('done lock')
|
logging.info('done lock')
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
elif o == 't3':
|
elif o == 't3':
|
||||||
pass
|
pass
|
||||||
elif o == 't4':
|
elif o == 't4':
|
||||||
print('started t4')
|
logging.info('started t4')
|
||||||
if self.force_idle():
|
if self.force_idle():
|
||||||
subprocess.check_call(self.commands['lock'], shell=True)
|
subprocess.check_call(self.commands['lock'], shell=True)
|
||||||
subprocess.call(self.commands['timeout2'], shell=True)
|
subprocess.call(self.commands['timeout2'], shell=True)
|
||||||
subprocess.check_call(self.commands['timeout1'], shell=True)
|
subprocess.check_call(self.commands['timeout1'], shell=True)
|
||||||
print('done t4')
|
logging.info('done t4')
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
elif o == 't5':
|
elif o == 't5':
|
||||||
print('started timeout resume')
|
logging.info('started timeout resume')
|
||||||
if self.force_idle():
|
if self.force_idle():
|
||||||
subprocess.check_call(self.commands['lock'], shell=True)
|
subprocess.check_call(self.commands['lock'], shell=True)
|
||||||
retry(
|
retry(
|
||||||
lambda: subprocess.call(self.commands['resume'], shell=True),
|
lambda: subprocess.call(self.commands['resume'], shell=True),
|
||||||
)
|
)
|
||||||
print('done timeout resume')
|
logging.info('done timeout resume')
|
||||||
elif o == 't6':
|
elif o == 't6':
|
||||||
print('started before-sleep')
|
logging.info('started before-sleep')
|
||||||
if self.force_idle():
|
if self.force_idle():
|
||||||
subprocess.call(self.commands['timeout2'], shell=True),
|
subprocess.call(self.commands['timeout2'], shell=True),
|
||||||
subprocess.check_call(self.commands['timeout1'], shell=True),
|
subprocess.check_call(self.commands['timeout1'], shell=True),
|
||||||
print('done before-sleep')
|
logging.info('done before-sleep')
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
elif o == 't7':
|
elif o == 't7':
|
||||||
print('started after-resume')
|
logging.info('started after-resume')
|
||||||
#if self.force_idle():
|
#if self.force_idle():
|
||||||
#subprocess.check_call(self.commands['lock'], shell=True)
|
#subprocess.check_call(self.commands['lock'], shell=True)
|
||||||
while True:
|
while True:
|
||||||
@ -2159,9 +2187,15 @@ def desktop_services(argv):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
print('done after-resume')
|
logging.info('done after-resume')
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
|
elif o in [
|
||||||
|
event_t.idle_state.value,
|
||||||
|
event_t.active_state.value,
|
||||||
|
]:
|
||||||
|
logging.info(json.dumps(dict(o=o)))
|
||||||
else:
|
else:
|
||||||
|
logging.error(json.dumps(dict(o=o)))
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
if not skip_loop:
|
if not skip_loop:
|
||||||
@ -2174,14 +2208,19 @@ def desktop_services(argv):
|
|||||||
self.background_check()
|
self.background_check()
|
||||||
|
|
||||||
services.extend([
|
services.extend([
|
||||||
subprocess.Popen(['ibus-daemon']),
|
subprocess.Popen(
|
||||||
|
['ibus-daemon'],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
),
|
||||||
start_swayidle(),
|
start_swayidle(),
|
||||||
])
|
])
|
||||||
|
|
||||||
if not options.battery is None:
|
if not options.battery is None:
|
||||||
assert options.battery in [0]
|
assert options.battery in [0]
|
||||||
|
|
||||||
print('launching battery')
|
logging.info('launching battery')
|
||||||
services.append(
|
services.append(
|
||||||
Battery(
|
Battery(
|
||||||
should_start=True,
|
should_start=True,
|
||||||
@ -2191,11 +2230,11 @@ def desktop_services(argv):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
if shutdown:
|
if shutdown:
|
||||||
print('shutdown')
|
logging.info('shutdown')
|
||||||
break
|
break
|
||||||
|
|
||||||
if all([not o.poll() is None for o in services]):
|
if all([not o.poll() is None for o in services]):
|
||||||
print('done')
|
logging.info('done')
|
||||||
break
|
break
|
||||||
|
|
||||||
for o in services:
|
for o in services:
|
||||||
|
@ -35,3 +35,4 @@ set-option -g set-titles on
|
|||||||
set-option -g set-titles-string "#S / #W"
|
set-option -g set-titles-string "#S / #W"
|
||||||
set -g status-right "#H %H:%M:%S %Y-%m-%d %Z"
|
set -g status-right "#H %H:%M:%S %Y-%m-%d %Z"
|
||||||
set -g status-interval 1
|
set -g status-interval 1
|
||||||
|
set -g mouse on
|
||||||
|
@ -63,3 +63,4 @@ set foldmethod=indent
|
|||||||
set nofoldenable
|
set nofoldenable
|
||||||
map <Leader>e :e #<cR>
|
map <Leader>e :e #<cR>
|
||||||
set mouse=a
|
set mouse=a
|
||||||
|
au FileType netrw nmap <buffer> <LeftMouse> <LeftMouse> <CR>
|
||||||
|
Loading…
Reference in New Issue
Block a user