init from webxdc/hello
using flake to setup dev environment with webxdc-dev
This commit is contained in:
commit
ef6ab83090
7 changed files with 1335 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/**
|
||||
.envrc
|
BIN
dist/myapp.xdc
vendored
Normal file
BIN
dist/myapp.xdc
vendored
Normal file
Binary file not shown.
27
flake.lock
Normal file
27
flake.lock
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1718160348,
|
||||
"narHash": "sha256-9YrUjdztqi4Gz8n3mBuqvCkMo4ojrA6nASwyIKWMpus=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "57d6973abba7ea108bac64ae7629e7431e0199b6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
22
flake.nix
Normal file
22
flake.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
description = "webxdc go application";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
nodejs = pkgs.nodejs-slim;
|
||||
in {
|
||||
devShells = {
|
||||
x86_64-linux = {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [ nodejs ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
1208
package-lock.json
generated
Normal file
1208
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
9
package.json
Normal file
9
package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"webxdc-dev": "^0.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "zip -9 --recurse-paths dist/myapp.xdc src",
|
||||
"webxdc-dev": "webxdc-dev run --port 4000 src"
|
||||
}
|
||||
}
|
67
src/index.html
Normal file
67
src/index.html
Normal file
|
@ -0,0 +1,67 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width"/>
|
||||
<script src="webxdc.js"></script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello</h1>
|
||||
<form>
|
||||
<input id="input" type="text" placeholder="Message" autofocus required />
|
||||
<input type="submit" onclick="sendMsg(); return false;" value="Send" />
|
||||
</form>
|
||||
<p id="output"></p>
|
||||
<p><em><small id="deviceName"></small></em></p>
|
||||
<script>
|
||||
|
||||
var El = function (tag, text) {
|
||||
var el = document.createElement(tag);
|
||||
el.innerText = text || '';
|
||||
return el;
|
||||
};
|
||||
|
||||
// handle past and future state updates
|
||||
window.webxdc.setUpdateListener(function (update) {
|
||||
var output = document.getElementById('output');
|
||||
// when appending content to an element with output.innerHTML +=
|
||||
// that content is implicitly parsed, making it possible for messages
|
||||
// to be interpreted as scripts. Creating elements directly,
|
||||
// injecting content as plain text, and appending them to the DOM
|
||||
// is a much safer practice.
|
||||
[
|
||||
El('strong', update.payload.name + ':'),
|
||||
El('span', update.payload.msg),
|
||||
El('br'),
|
||||
].forEach(function (item) {
|
||||
output.appendChild(item);
|
||||
});
|
||||
});
|
||||
|
||||
function sendMsg() {
|
||||
msg = document.getElementById("input").value;
|
||||
info = 'someone typed "' + msg + '"';
|
||||
document.getElementById("input").value = '';
|
||||
|
||||
// send new updates
|
||||
window.webxdc.sendUpdate({
|
||||
payload: {
|
||||
name: window.webxdc.selfName,
|
||||
msg,
|
||||
},
|
||||
info,
|
||||
}, info);
|
||||
}
|
||||
|
||||
(function () {
|
||||
window.deviceName.innerText = 'this is ' + window.webxdc.selfName;
|
||||
})()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue