Merge pull request #6 from AleziaKurdis/app-Note

Application: Notes
This commit is contained in:
Dale Glass 2022-07-23 22:21:35 +02:00 committed by GitHub
commit 01e0425c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 414 additions and 0 deletions

View file

@ -117,6 +117,15 @@ var metadata = { "applications":
"icon": "odometer/appicon_i.png",
"caption": "ODOMETER"
},
{
"isActive": true,
"directory": "notes",
"name": "Notes",
"description": "A simple notepad that can be used while you are in-world.",
"jsfile": "notes/app-notes.js",
"icon": "notes/icon_inactive.png",
"caption": "NOTES"
},
{
"isActive": true,
"directory": "home",

Binary file not shown.

View file

@ -0,0 +1,129 @@
"use strict";
//
// app-notes.js
//
// Created by Alezia Kurdis, May 27th 2022.
// Copyright 2022 Overte e.V.
//
// Simple application to take notes online, mainly for when we are in HMD mode.
//
// 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 jsMainFileName = "app-notes.js";
var ROOT = Script.resolvePath('').split(jsMainFileName)[0];
var APP_NAME = "NOTES";
var APP_URL = ROOT + "notes.html";
var APP_ICON_INACTIVE = ROOT + "icon_inactive.png";
var APP_ICON_ACTIVE = ROOT + "icon_active.png";
var appStatus = false;
var mode = "light";
var notes = "";
var channel = "overte.application.ak.notes";
var timestamp = 0;
var INTERCALL_DELAY = 200; //0.3 sec
var SETTING_NOTES = "application_ak_notes";
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.screenChanged.connect(onScreenChanged);
var button = tablet.addButton({
text: APP_NAME,
icon: APP_ICON_INACTIVE,
activeIcon: APP_ICON_ACTIVE
});
function clicked(){
if (appStatus === true) {
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
tablet.gotoHomeScreen();
appStatus = false;
}else{
loadDataFromSettings();
tablet.gotoWebScreen(APP_URL + "?mode=" + mode);
tablet.webEventReceived.connect(onMoreAppWebEventReceived);
appStatus = true;
}
button.editProperties({
isActive: appStatus
});
}
button.clicked.connect(clicked);
function onMoreAppWebEventReceived(message) {
var d = new Date();
var n = d.getTime();
if (typeof message === "string") {
eventObj = JSON.parse(message);
if (eventObj.channel === channel) {
if (eventObj.action === "saveText" && (n - timestamp) > INTERCALL_DELAY) {
d = new Date();
timestamp = d.getTime();
notes = eventObj.data;
saveDataToSetting();
clicked(); // this closes the app.
} else if (eventObj.action === "saveMode" && (n - timestamp) > INTERCALL_DELAY) {
d = new Date();
timestamp = d.getTime();
mode = eventObj.data;
saveDataToSetting();
} else if (eventObj.action === "requestData" && (n - timestamp) > INTERCALL_DELAY) {
var message = {
"channel": channel,
"action": "loadText",
"notes": notes
};
tablet.emitScriptEvent(JSON.stringify(message));
}
}
}
}
function onScreenChanged(type, url) {
if (type === "Web" && url.indexOf(APP_URL) !== -1) {
appStatus = true;
} else {
appStatus = false;
}
button.editProperties({
isActive: appStatus
});
}
function cleanup() {
if (appStatus) {
tablet.gotoHomeScreen();
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
}
tablet.screenChanged.disconnect(onScreenChanged);
tablet.removeButton(button);
}
function loadDataFromSettings() {
var settings = Settings.getValue(SETTING_NOTES, {"mode": "light", "notes": ""});
mode = settings.mode;
notes = settings.notes;
}
function saveDataToSetting() {
var data = {
"mode": mode,
"notes": notes
};
Settings.setValue(SETTING_NOTES, data);
}
Script.scriptEnding.connect(cleanup);
}());

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

4
applications/notes/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,272 @@
<!DOCTYPE html>
<!--
notes.html
Created by Alezia Kurdis, May 27th 2022.
Copyright 2022 Overte e.V.
UI for a simple application to take notes online, mainly for when we are in HMD mode.
Distributed under the Apache License, Version 2.0.
See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
-->
<html>
<head>
<meta charset="UTF-8">
<script src='jquery.min.js'></script>
<script>
//Parameters
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
var mode = findGetParameter("mode");
if(mode === null){mode = "light";}
//Paths
var thisPageName = "notes.html";
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
var ROOTPATH = currentPath.replace(thisPageName, "");
var channel = "overte.application.ak.notes";
//LISTENER FROM JS FILE:
EventBridge.scriptEventReceived.connect(function(message){
var messageObj = JSON.parse(message);
if (messageObj.channel === channel && messageObj.action === "loadText") {
document.getElementById("page").value = messageObj.notes;
}
});
</script>
<style>
@font-face {
font-family: FiraSans-SemiBold;
src: url(FiraSans-SemiBold.ttf);
}
html {
width: 100%;
height: 100%;
}
body {
background-color: #21293d;
font-family: FiraSans-SemiBold;
font-size: 12px;
color: #FFFFFF;
font-weight: 600;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: none;
width: 100%;
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
div.container {
height: 95%;
width: 100%;
overflow: hidden;
}
textarea.light {
font-family: FiraSans-SemiBold;
font-size: 14px;
resize: none;
outline: none;
width: 100%;
height: 100%;
overflow-y: auto;
background-color: #ffffff;
color: #000000;
border: 0px;
}
textarea.dark {
font-family: FiraSans-SemiBold;
font-size: 14px;
resize: none;
outline: none;
width: 100%;
height: 100%;
overflow-y: auto;
background-color: #000000;
color: #AAAAAA;
border: 0px;
}
#mode {
margin: 3px;
background: #ebebeb;
background-image: linear-gradient(to bottom, #ebebeb, #999999);
border-radius: 7px;
font-family: FiraSans-SemiBold;
color: #000000;
font-size: 20px;
padding: 0px 5px 0px 5px;
border: solid #000000 0px;
text-decoration: none;
height: 24px;
}
#mode:hover {
background: #f2f2f2;
background-image: linear-gradient(to bottom, #f2f2f2, #5c5c5c);
text-decoration: none;
}
#mode:focus {
outline: none;
}
#clear {
margin: 3px;
background: #ebebeb;
background-image: linear-gradient(to bottom, #ebebeb, #999999);
border-radius: 7px;
font-family: FiraSans-SemiBold;
color: #000000;
font-size: 16px;
padding: 2px 5px 0px 5px;
border: solid #000000 0px;
text-decoration: none;
height: 24px;
}
#clear:hover {
background: #f2f2f2;
background-image: linear-gradient(to bottom, #f2f2f2, #5c5c5c);
text-decoration: none;
}
#clear:focus {
outline: none;
}
#saveAndClose {
margin: 3px;
background: #ebebeb;
background-image: linear-gradient(to bottom, #ebebeb, #999999);
border-radius: 7px;
font-family: FiraSans-SemiBold;
color: #000000;
font-size: 16px;
padding: 2px 5px 0px 5px;
border: solid #000000 0px;
text-decoration: none;
height: 24px;
}
#saveAndClose:hover {
background: #f2f2f2;
background-image: linear-gradient(to bottom, #f2f2f2, #5c5c5c);
text-decoration: none;
}
#saveAndClose:focus {
outline: none;
}
#copy {
margin: 3px;
background: #ebebeb;
background-image: linear-gradient(to bottom, #ebebeb, #999999);
border-radius: 7px;
font-family: FiraSans-SemiBold;
color: #000000;
font-size: 16px;
padding: 2px 5px 0px 5px;
border: solid #000000 0px;
text-decoration: none;
height: 24px;
}
#copy:hover {
background: #f2f2f2;
background-image: linear-gradient(to bottom, #f2f2f2, #5c5c5c);
text-decoration: none;
}
#copy:focus {
outline: none;
}
</style>
</head>
<body>
<div id="container" class="container">
<textarea id="page" class="light" placeholder="Enter your notes here..."></textarea>
</div>
<div style="width: 100%; display: flex;">
<div style="width: 50%; text-align: left;">
<button id="mode" onClick="toggleMode();">&#9681;</button> <button id="clear" onClick="clearContent();">Clear</button>
</div>
<div style="width: 50%; text-align: right;">
<button id="saveAndClose" onClick="saveAndClose();">Save and Close</button>
</div>
</div>
<script>
function setMode() {
if (mode === "dark") {
document.getElementById("page").className = "dark";
} else {
document.getElementById("page").className = "light";
}
}
function toggleMode() {
if (mode === "dark") {
mode = "light";
} else {
mode = "dark";
}
var dataObj = {
"channel": channel,
"action": "saveMode",
"data": mode
};
EventBridge.emitWebEvent(JSON.stringify(dataObj));
setMode();
}
function clearContent() {
document.getElementById("page").value = "";
}
function saveAndClose() {
var dataObj = {
"channel": channel,
"action": "saveText",
"data": document.getElementById("page").value
};
EventBridge.emitWebEvent(JSON.stringify(dataObj));
}
function requestData() {
var dataObj = {
"channel": channel,
"action": "requestData"
};
EventBridge.emitWebEvent(JSON.stringify(dataObj));
}
setMode();
requestData();
</script>
</body>
</html>