Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
C0Newb committed Apr 25, 2023
1 parent 2071c10 commit a586975
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 84 deletions.
4 changes: 2 additions & 2 deletions Client/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.neptune.app"
minSdk 23
targetSdk 32
versionCode 3
versionName "0.9"
versionCode 4
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions Client/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<activity
android:name=".AddDeviceActivity"
android:exported="false"
android:parentActivityName=".MainActivity"
android:label="Add device" />
<activity
android:name=".NotificationsActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

Expand Down Expand Up @@ -42,6 +43,11 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_device);

ActionBar actionBar = getSupportActionBar();
if(actionBar!=null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

serverList = findViewById(R.id.container);
searchingProgressBar = findViewById(R.id.searching_progress_bar);

Expand Down Expand Up @@ -90,6 +96,12 @@ protected void onCreate(Bundle savedInstanceState) {
buildAddDialog();
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
protected void onDestroy() {
// Stop service discovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,27 @@ private ICallback getCommandListener() {
response.addProperty("status", "failed");
response.addProperty("errorMessage", "No clipboard data");
this.connectionManager.sendRequestAsync("/api/v1/client/clipboard/uploadStatus", response);
} else if (Clipboard.setClipboard(data.getAsJsonObject("data")) && isResponse) {
response.addProperty("status", "success");
this.connectionManager.sendRequestAsync("/api/v1/client/clipboard/uploadStatus", response);
} else if (isResponse) {
response.addProperty("status", "failed");
response.addProperty("errorMessage", "Unknown client error");
this.connectionManager.sendRequestAsync("/api/v1/client/clipboard/uploadStatus", response);
} else {
boolean allow = false;
if (data.has("status")) {
String status = data.get("status").getAsString();
if (status.equalsIgnoreCase("getBlocked")) {
allow = false;
} else {
allow = true;
}
}

if (!data.has("data")) {
// failed!
} else if ( Clipboard.setClipboard(data.getAsJsonObject("data")) && isResponse) {
response.addProperty("status", "success");
this.connectionManager.sendRequestAsync("/api/v1/client/clipboard/uploadStatus", response);
} else if (isResponse) {
response.addProperty("status", "failed");
response.addProperty("errorMessage", "Unknown client error");
this.connectionManager.sendRequestAsync("/api/v1/client/clipboard/uploadStatus", response);
}
}

} else if (isResponse) {
Expand Down Expand Up @@ -280,6 +294,9 @@ private ICallback getCommandListener() {

// File stuff
} else if (command.equals("/api/v1/client/filesharing/receive") && apiDataPackage.isJsonObject()) {
if (!filesharingSettings.allowServerToUpload)
return;

// Download a file! (preferably in a new thread!)
JsonObject data = apiDataPackage.jsonObject();
if (data.has("fileUUID")
Expand Down Expand Up @@ -798,7 +815,7 @@ public void downloadFile(String fileUUID, String authenticationCode, String file
if (filesharingSettings.notifyOnServerUpload) {
NotificationCompat.Builder notification = MainActivity.createBaseNotification(Constants.INCOMING_FILES_NOTIFICATION_CHANNEL_ID,
"Received file",
fileName + " has been ");
fileName + " has been downloaded.");

notification.setSubText(friendlyName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
);

if(server.filesharingSettings.receivedFilesDirectory==null) {
if(this.server.filesharingSettings.receivedFilesDirectory == null || !isValidContentUri(Uri.parse(this.server.filesharingSettings.receivedFilesDirectory))) {
Intent chooseFileDestination = new Intent(ServerSettingsActivity.this, ChooseFileDestinationActivity.class);
chooseFileDestination.putExtra(Constants.EXTRA_SERVER_ID, serverId);
firstTimeFolderPickerLauncher.launch(chooseFileDestination);
Expand Down Expand Up @@ -192,34 +192,36 @@ protected void onCreate(Bundle savedInstanceState) {
filePickerLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
Intent data = result.getData();
if (result.getResultCode() != Activity.RESULT_OK) {
Log.d(TAG, "openFilePickerToSendFileToServer: user canceled");
Toast.makeText(this, "File upload canceled.", Toast.LENGTH_SHORT).show();
return;
}
new Thread(() -> {
Intent data = result.getData();
if (result.getResultCode() != Activity.RESULT_OK) {
Log.d(TAG, "openFilePickerToSendFileToServer: user canceled");
runOnUiThread(() -> Toast.makeText(this, "File upload canceled.", Toast.LENGTH_SHORT).show());
return;
}

if (data == null) {
Log.w(TAG, "openFilePickerToSendFileToServer: no intent data");
Toast.makeText(this, "File upload failed, no selected file.", Toast.LENGTH_SHORT).show();
return;
}
if (data == null) {
Log.w(TAG, "openFilePickerToSendFileToServer: no intent data");
runOnUiThread(() -> Toast.makeText(this, "File upload failed, no selected file.", Toast.LENGTH_SHORT).show());
return;
}

if (null != data.getClipData()) {
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
Uri uri = data.getClipData().getItemAt(i).getUri();
if (null != data.getClipData()) {
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
Uri uri = data.getClipData().getItemAt(i).getUri();
if (uri != null) {
String name = getFriendlyNameFromUri(uri);
runOnUiThread(() -> Toast.makeText(this, "Sending \"" + name + "\".", Toast.LENGTH_SHORT).show());
new Thread(() -> server.sendFile(uri)).start();
}
}
} else {
Uri uri = data.getData();
if (uri != null) {
String name = getFriendlyNameFromUri(uri);
Toast.makeText(this, "Sending \"" + name + "\".", Toast.LENGTH_SHORT).show();
server.sendFile(uri);
}
}
} else {
Uri uri = data.getData();
if (uri != null) {
server.sendFile(uri);
}
}
}).start();
}
);
folderPickerLauncher = registerForActivityResult(
Expand Down Expand Up @@ -446,7 +448,7 @@ private void pullSettings() {
updateClipboardSettings();

chkFileSharingEnable.setChecked(this.server.filesharingSettings.enabled);
chkFileSharingAutoAcceptFiles.setChecked(!this.server.filesharingSettings.requireConfirmationOnServerUploads);
chkFileSharingAutoAcceptFiles.setChecked(this.server.filesharingSettings.requireConfirmationOnServerUploads == false);
chkFileSharingNotifyOnReceive.setChecked(this.server.filesharingSettings.notifyOnServerUpload);
chkFileSharingServerSet.setChecked(this.server.filesharingSettings.allowServerToUpload);
updateFileSharingSettings();
Expand All @@ -472,6 +474,8 @@ private void pullSettings() {


updateDetailsText();

runOnUiThread(() -> Toast.makeText(this, "Settings loaded", Toast.LENGTH_SHORT).show());
} catch (Exception e) {
Log.e(TAG, "pullSettings: error occurred while pulling server settings", e);
showErrorMessage("Unexpected error", "We're having trouble reading the server's settings. You may have to delete the server and repair.");
Expand All @@ -490,7 +494,7 @@ private void saveSettings() {
this.server.clipboardSettings.allowServerToGet = chkClipboardServerGet.isChecked();

this.server.filesharingSettings.enabled = chkFileSharingEnable.isChecked();
this.server.filesharingSettings.requireConfirmationOnServerUploads = !chkFileSharingAutoAcceptFiles.isChecked();
this.server.filesharingSettings.requireConfirmationOnServerUploads = (chkFileSharingAutoAcceptFiles.isChecked() == false);
this.server.filesharingSettings.notifyOnServerUpload = chkFileSharingNotifyOnReceive.isChecked();
this.server.filesharingSettings.allowServerToUpload = chkFileSharingServerSet.isChecked();
this.server.filesharingSettings.receivedFilesDirectory = incomingFilesDirectoryUri.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
android:id="@+id/add_server_by_ip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:layout_marginEnd="16dp"
android:text="@string/add_via_ip_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:id="@+id/notifDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Notifications will be synched for the selected apps"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -20,9 +21,11 @@

<ScrollView
android:id="@+id/mainScroller"
android:layout_width="410dp"
android:layout_height="631dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/btnCheckAlll"
Expand All @@ -33,8 +36,8 @@

<LinearLayout
android:id="@+id/appList"
android:layout_width="414dp"
android:layout_height="630dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="7dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/btnUncheckAll"
Expand Down
75 changes: 51 additions & 24 deletions Client/Android/app/src/main/res/layout/app_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,73 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:minHeight="58dp"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.cardview.widget.CardView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardCornerRadius="10dp"
app:cardElevation="10dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
android:minHeight="58dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/appIcon"
app:layout_constraintTop_toTopOf="parent">

<CheckBox
android:id="@+id/appName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:layout_width="300dp"
android:layout_height="23dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="1dp"
android:layout_marginEnd="27dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TouchTargetSizeCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>

<ImageView
android:id="@+id/appIcon"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_launcher_foreground" />


<!-- Sync indicator -->

<ImageView
android:id="@+id/appIcon"
android:layout_width="35dp"
android:layout_height="35dp"
app:srcCompat="@drawable/ic_launcher_foreground" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>

</RelativeLayout>
<Space
android:layout_width="0dp"
android:layout_height="8dp"
app:layout_constraintEnd_toEndOf="@+id/cardView"
app:layout_constraintStart_toStartOf="@+id/cardView"
app:layout_constraintTop_toBottomOf="@+id/cardView" />

</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 3 additions & 5 deletions Server/src/Classes/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class Client extends ClientConfig {
if (this.clipboardSettings.enabled) {
if (this.clipboardSettings.allowClientToSet || isReponse) { // Allowed to set?
this.clipboardModificationsLocked = true; // DO NOT SEND WHAT WE JUST GOT! RACE CONDITION!
let maybeThis = this;
setTimeout(() => { maybeThis.clipboardModificationsLocked = false }, 1000);

this.log.silly(data);
Clipboard.setStandardizedClipboardData(data).then((success) => {
if (success)
Expand All @@ -307,11 +310,6 @@ class Client extends ClientConfig {
});
}
});

if (isReponse) {
let maybeThis = this;
setTimeout(() => { maybeThis.clipboardModificationsLocked = false }, 1000);
}
} else {
if (!isReponse)
this.sendRequest("/api/v1/server/clipboard/uploadStatus", { status: "setBlocked" });
Expand Down
14 changes: 7 additions & 7 deletions Server/src/Classes/ExpressApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ app.post('/api/v1/server/socket/:socketUUID/filesharing/:fileUUID/upload', uploa
contents: {
text: 'Received a file: ' + fileName,
subtext: "File received",
actions: [
{
"id": "showme",
"type": "button",
"contents": actionButtonContents
},
]
// actions: [
// {
// "id": "showme",
// "type": "button",
// "contents": actionButtonContents
// },
// ]
},

onlyAlertOnce: true,
Expand Down
Loading

0 comments on commit a586975

Please sign in to comment.