Skip to content

Commit

Permalink
Add clipboard feature to web app
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis authored and McGiverGim committed Apr 10, 2024
1 parent e1f5f24 commit 492a744
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/js/Clipboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GUI from './gui.js';
import { isWeb } from "./utils/isWeb";

/**
* Encapsulates the Clipboard logic, depending on web or nw
Expand Down Expand Up @@ -75,6 +76,45 @@ Clipboard._configureClipboardAsCordova = function() {

};

Clipboard._configureClipboardAsWeb = function() {

console.log('Web Clipboard available');

this.available = true;
this.readAvailable = true;
this.writeAvailable = true;

this.writeText = function(text, onSuccess, onError) {

navigator.clipboard.writeText(text).then(
function() {
if (onSuccess) {
onSuccess(text);
}
}, function(err) {
if (onError) {
onError(err);
}
},
);
};

this.readText = function(onSuccess, onError) {

navigator.clipboard.readText().then(
function(text) {
if (onSuccess) {
onSuccess(text);
}
}, function(err) {
if (onError) {
onError(err);
}
},
);
};
};

Clipboard._configureClipboardAsOther = function() {

console.warn('NO Clipboard available');
Expand All @@ -96,6 +136,8 @@ if (GUI.isNWJS()){
Clipboard._configureClipboardAsNwJs(GUI.nwGui);
} else if (GUI.isCordova()) {
Clipboard._configureClipboardAsCordova();
} else if (isWeb()) {
Clipboard._configureClipboardAsWeb();
} else {
Clipboard._configureClipboardAsOther();
}
Expand Down

0 comments on commit 492a744

Please sign in to comment.