Skip to content

Commit

Permalink
fix error msg when repo wanted to add a new contact at startup, fix i…
Browse files Browse the repository at this point in the history
…nvisible canvas for older Android WebViews
  • Loading branch information
tschudin committed Jul 30, 2024
1 parent b3fdeef commit 95eb0c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
43 changes: 19 additions & 24 deletions android/tinySSB/app/src/main/assets/web/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ var sketch_size_update_timer = null; // reference to size update interval
function chat_openSketch() {
closeOverlay()
// Create a canvas element
let canvas = document.createElement('canvas');
canvas.id = 'sketchCanvas';
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.width = window.innerWidth; // Full screen width
canvas.height = window.innerHeight; // Full screen height
/* on API 26, the canvas is not showing. Perhaps
https://stackoverflow.com/questions/24586530/android-canvas-drawing-not-visible#24586531
canvas.drawARGB(0, 225, 225, 255);
*/
canvas.style.backgroundColor = '#ffffff';
document.body.appendChild(canvas);

sketch.canvas = document.getElementById("sketchCanvas")
sketch.canvas.width = window.screen.width;
sketch.canvas.height = window.screen.height;
sketch.canvas.style.display = 'initial';
sketch.canvas.style.backgroundColor = '#ffffff';
sketch.ctx = sketch.canvas.getContext('2d');
sketch.ctx.globalCompositeOperation = "source-over";
sketch.ctx.fillStyle = "white";
sketch.ctx.fillRect(0 , 0, sketch.canvas.width, sketch.canvas.height);

let sizeDiv = document.createElement('div')
sizeDiv.id = 'div:sketch_size'
Expand Down Expand Up @@ -212,10 +209,7 @@ function chat_openSketch() {
eraserSign.onclick = toggleEraser;
document.body.appendChild(eraserSign);

//get the context of the canvas and set initial drawing settings
sketch.ctx = canvas.getContext('2d');
sketch.ctx.fillStyle = "white";
sketch.ctx.fillRect(0 , 0, canvas.width, canvas.height);
// set initial drawing settings
sketch.currSize = 0;
sketch.currentWidNdx = 0;
sketch.strokeColor = '#000000';
Expand All @@ -225,12 +219,12 @@ function chat_openSketch() {
sketch.lastY = 0;
sketch.colChoice = true;
sketch.currentColNdx = 0;
sketch.svg = [1,['s',canvas.width,canvas.height]]
sketch.svg = [1,['s',sketch.canvas.width,sketch.canvas.height]]

canvas.addEventListener('touchstart', startDrawing);
canvas.addEventListener('touchmove', draw);
canvas.addEventListener('touchend', endDrawing);
canvas.addEventListener('touchcancel', endDrawing);
sketch.canvas.addEventListener('touchstart', startDrawing);
sketch.canvas.addEventListener('touchmove', draw);
sketch.canvas.addEventListener('touchend', endDrawing);
sketch.canvas.addEventListener('touchcancel', endDrawing);

//Drawing function when user starts drawing (on touchstart)
function startDrawing(e) {
Expand Down Expand Up @@ -353,8 +347,9 @@ function chat_closeSketch() {
}

// Remove the canvas element
let canvas = document.getElementById('sketchCanvas');
canvas.parentNode.removeChild(canvas);
// let canvas = document.getElementById('sketchCanvas');
// canvas.parentNode.removeChild(canvas);
sketch.canvas.style.display = 'none';

let sizeDiv = document.getElementById('div:sketch_size')
sizeDiv.parentNode.removeChild(sizeDiv)
Expand Down
5 changes: 4 additions & 1 deletion android/tinySSB/app/src/main/assets/web/tremola.html
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,11 @@
<button class="flat passive buttontext" style="background-image: url('img/checked.svg'); width: 100%; height: 30px; margin: 3px;" onclick="members_confirmed();">&nbsp;</button>
</div>

</div>

<canvas id="sketchCanvas" style="display: none; position: fixed; top: 0; left: 0; margin: 0px;">
canvas is here
</canvas>

</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.net.wifi.WifiManager
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.View
import android.view.Window
import android.webkit.WebStorage
import android.webkit.WebView
Expand Down Expand Up @@ -88,6 +89,7 @@ class MainActivity : Activity() {
Log.d("IDENTITY", "is ${idStore.identity.toRef()} (${idStore.identity.verifyKey})")

val webView = findViewById<WebView>(R.id.webView)
webView.setLayerType(View.LAYER_TYPE_SOFTWARE,null); // disable acceleration, needed for older WebViews
wai = WebAppInterface(this, webView)
// upgrades repo filesystem if necessary
tinyRepo.upgrade_repo()
Expand Down Expand Up @@ -425,9 +427,6 @@ class MainActivity : Activity() {
}
*/
}
fun isWaiInitialized(): Boolean {
return this::wai.isInitialized;
}

fun rmSockets() {
try { mc_socket?.leaveGroup(mc_group); mc_socket?.close() } catch (e: Exception) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Repo(val context: MainActivity) {
chnk_offs = Random.nextInt(0, context.tinyGoset.keys.size - 1)
}

if(context.isWaiInitialized())
if(context.wai.frontend_ready) // was: isWaiInitialized()
context.wai.eval("b2f_new_contact(\"@${fid.toBase64()}.ed25519\")") // notify frontend

want_is_valid = false
Expand Down

0 comments on commit 95eb0c0

Please sign in to comment.