mirror of
https://github.com/lubosz/overte.git
synced 2025-04-29 15:43:19 +02:00
81 lines
2 KiB
JavaScript
81 lines
2 KiB
JavaScript
"use strict";
|
|
|
|
//
|
|
// EZrecord.js
|
|
//
|
|
// Created by David Rowe on 24 Jun 2017.
|
|
// Copyright 2017 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
(function () {
|
|
|
|
var APP_NAME = "EZRECORD",
|
|
APP_ICON_INACTIVE = "icons/tablet-icons/avatar-record-i.svg",
|
|
APP_ICON_ACTIVE = "icons/tablet-icons/avatar-record-a.svg",
|
|
SHORTCUT_KEY = "r", // Ctrl modifier is assumed.
|
|
tablet,
|
|
button,
|
|
isRecording = false;
|
|
|
|
function toggleRecording() {
|
|
isRecording = !isRecording;
|
|
button.editProperties({ isActive: isRecording });
|
|
// TODO: Start/cancel/finish recording.
|
|
}
|
|
|
|
function onKeyPressEvent(event) {
|
|
if (event.isControl && event.text === SHORTCUT_KEY && !event.isMeta && !event.isAlt && !event.isAutoRepeat) {
|
|
toggleRecording();
|
|
}
|
|
}
|
|
|
|
function onButtonClicked() {
|
|
toggleRecording();
|
|
}
|
|
|
|
function setUp() {
|
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
if (!tablet) {
|
|
return;
|
|
}
|
|
|
|
// Tablet/toolbar button.
|
|
button = tablet.addButton({
|
|
icon: APP_ICON_INACTIVE,
|
|
activeIcon: APP_ICON_ACTIVE,
|
|
text: APP_NAME,
|
|
isActive: false
|
|
});
|
|
if (button) {
|
|
button.clicked.connect(onButtonClicked);
|
|
}
|
|
|
|
Controller.keyPressEvent.connect(onKeyPressEvent);
|
|
}
|
|
|
|
function tearDown() {
|
|
if (isRecording) {
|
|
// TODO: Cancel recording.
|
|
}
|
|
|
|
if (!tablet) {
|
|
return;
|
|
}
|
|
|
|
if (button) {
|
|
button.clicked.disconnect(onButtonClicked);
|
|
tablet.removeButton(button);
|
|
button = null;
|
|
}
|
|
|
|
tablet = null;
|
|
|
|
Controller.keyPressEvent.disconnect(onKeyPressEvent);
|
|
}
|
|
|
|
setUp();
|
|
Script.scriptEnding.connect(tearDown);
|
|
}());
|