I wrote JSNI to detect java version, but it does not work(can not get java version) in the latest browser version such as chrome,IE,Firefox - jsni

I used JSNI and it did not work in the latest browsers version(eg.chrome, IE, Firefox)! I wrote this code below :
public static native boolean detectJavaVersion() /*-{
try {
var javaVersions = $wnd.deployJava.getJREs();
alert("Your windows Java version is : " + javaVersions);
if (javaVersions.length == 0) {
alert("You have not installed any types of Java in your system");
return false;
}
if (javaVersions < "1.8") {
alert("Java version is less than 8");
return false;
} else {
alert("Java version is 8 or more than it");
return true;
}
}
catch
(err) {
var exceptionMsg = err.message;
alert("Exception is : " + exceptionMsg);
}
}-*/;
I tried to fix it over a week!!!
Could someone please gives me an advice.
Thanks a lot.

There is no Java in modern browsers (Chrome, Firefox, Edge, Safari), which is probably why your code fails.
You can still write Java code and let GWT compile it into JavaScript, that way it can run in the browser. The Java features you can use depend on GWT compiler support, not on the browser.

Related

iOS app crashes on iphone device when using httpclient and .net maui

Build environment:
Macbook M1
vscode(1.69.0) as well as vs2022 (17.3)
Steps to reproduce:
create new Maui app
add nuget package "Microsoft.Extensions.Http" Version="6.0.0" to project
Modify MauiProgram.cs:
builder.Services.AddHttpClient<EndPointAHttpClient>(client =>
{
var EndPointA = "https://www.montemagno.com/";
client.BaseAddress = new Uri(EndPointA);
});
public class EndPointAHttpClient
{
public EndPointAHttpClient(HttpClient client)
{
Client = client;
}
public HttpClient Client { get; }
}
Publish:
dotnet publish <project.csproj> -f:net6.0-ios -c:Release /p:ServerAddress=<xxx.xxx.xxx.xxx> /p:ServerUser=user /p:TcpPort=58181 /p:ServerPassword=pwd -p:AotAssemblies=false
Install on iphone using Transporter/TestFlight
CRASHES WHEN OPENING THE APP
Please let me know:
1. Is there any demo code that works
2. Kindly provide advise on how I can use HttpClient in a .net Maui app
Use the code found here. https://github.com/dotnet/maui-samples/tree/main/6.0/WebServices/TodoREST/TodoREST/Services
Grab the RestService, IRestService, HttpsClientHandlerService and IHttpsClientHandlerService.
Get the Contstants file as well.
https://github.com/dotnet/maui-samples/blob/main/6.0/WebServices/TodoREST/TodoREST/Constants.cs
Makes sure you add your Url to the HttpsClientHandlerService like so. I was getting a System.Net.WebException: Error: TrustFailure. The only way I was able to catch what was happening was using Sentry.io. I guessed that this might be the problem.
public bool IsSafeUrl(NSUrlSessionHandler sender, string url, Security.SecTrust trust)
{
if (url.StartsWith("https://localhost") || url.StartsWith("https://yourservice.azurewebsites.net"))
return true;
return false;
}
Then change this line.
var handler = new NSUrlSessionHandler
{
TrustOverrideForUrl = IsSafeUrl
};

On MacOs Electron BrowserWindow.LoadURL not working

i am new to electron.
i used Vue CLI Plugin Electron Builder to create base project.
in window BrowserWindow.LoadURL it work.
but on macos BrowserWindow.LoadURL not working.
macos version 10.10.5,
electron version 11.4.7
try {
//it not working on macos
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
} catch (err) {
//can't catch any err on macos
console.log(`loadURL err, url: ${process.env.WEBPACK_DEV_SERVER_URL}, info: ${err}`)
}
i searched a lot for the answer, but didn't get any answer for this.
can any suggest a solution for this? any help will be appreciated.
run electron
safari loads url
Below the loadURL function...
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
}
Try to add this code block to check if the content of the page is ready or if it has finished loading. If it is, show the window and focus on it.
win.webContents.on('did-finish-load', () => {
if (!win) {
throw new Error('`win` is not defined');
}
if (process.env.START_MINIMIZED) {
win.minimize();
} else {
win.show();
win.focus();
}
});

cordova 2.9.x iOS 8 userAgent bug

I am using Cordova 2.9.0 with phonegap to build an iOS app.
With iOS 8, I am getting error messages of
Deprecated attempt to access property 'geolocation' on a non-Navigator object.
Deprecated attempt to access property 'userAgent' on a non-Navigator object
I tried EddyVerbruggen's solution
https://gist.github.com/EddyVerbruggen/cd02c73162180793513e
But, I am getting those error messages from Cordova
Also, when my application loads completely, I have no problem using
window.navigator.userAgent
Fist of all, it seems just a warning and the apps work fine.
They have been fixed this and I suposse it will be available soon, but for people using cordova 2.9.X, we have to change the replaceNavigator function to be like this on the cordova.js file (the whole else is new)
function replaceNavigator(origNavigator) {
var CordovaNavigator = function() {};
CordovaNavigator.prototype = origNavigator;
var newNavigator = new CordovaNavigator();
// This work-around really only applies to new APIs that are newer than Function.bind.
// Without it, APIs such as getGamepads() break.
if (CordovaNavigator.bind) {
for (var key in origNavigator) {
if (typeof origNavigator[key] == 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
} else {
(function(k) {
Object.defineProperty(newNavigator, k, {
get: function() {
return origNavigator[k];
},
configurable: true,
enumerable: true
});
})(key);
}
}
}
return newNavigator;
}

Cannot Write On Micro SDCard On BlackBerry

I am trying to save some files on micro SDCard. To check the availability of SDCard, I am using the following method;
private boolean isSdCardReady() {
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
if (e.nextElement().toString().equalsIgnoreCase("sdcard/")) {
return true;
}
}
return false;
}
Even if this method returns true, when I try to save files, it gives exception net.rim.device.api.io.file.FileIOException: File system is not ready.
What does this means? If SDCard is not available, then why its listed in FileSystemRegistry.listRoots()?
How can I make sure that SDCard is available for writing?
My development environment:
BlackBerry JDE Eclipse Plugin 1.5.0
BlackBerry OS 4.5
BlackBerry Bold with a 3G card
Usually I had this error when I tried to access SD card on device restart. You have to postpone all operations in app until startup finished:
while (ApplicationManager.getApplicationManager().inStartup()) {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
}
}
I remember one more possible cause mentioned here. You have to close all streams after using.
Solved the problem. I was looking for "sdcard" while rootsEnum.nextElement().toString(); returns "SDCard". Yeah, its case sensitive. Now, instead of using hard-coded "SDCard", I've changed the above method to the following;
private static String getSdCardRootDir() {
Enumeration rootsEnum = FileSystemRegistry.listRoots();
while (rootsEnum.hasMoreElements()) {
String rootDir = rootsEnum.nextElement().toString();
if (rootDir.equalsIgnoreCase("sdcard/")) {
return "file:///" + rootDir;
}
}
return null;
}
Using this, I got the root directory in its system defined case.

Block JS with Firefox Addon

im developing a little firefox addon with the addon-sdk provided by mozilla. The addon should work on only one specific website and it needs to block a js-file from this website. I'm searching for hours on how to block such a request.
Hopefully someone knows the answer
Yeah, you'd have to do this mostly by hand. The SDK isn't going to help you much at all here but it is somewhat possible.
This is along the lines of what you'd need to do. Note that this isn't tested and won't work out of the box but just to give you an idea of what components are involved and where to find more resources.
const { Cc, Ci, Cm, components } = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
const CategoryManager = Cc["#mozilla.org/categorymanager;1"]
.getService(Ci.nsICategoryManager);
function PolicyComponent() { }
PolicyComponent.prototype = {
desc: "My nsIContentPolicy XPCOM Component",
classID: components.ID("{3ffd2f60-3784-11e1-b86c-0800200c9a66}"),
contractID: "#abc.def.com/policycomp;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy]),
shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
if (contentLocation.spec != BLOCKED_JS) { return return Ci.nsIContentPolicy.ACCEPT; }
else { return Ci.nsIContentPolicy.REJECT_REQUEST; }
},
shouldProcess: function() {
return CI.nsIContentPolicy.ACCEPT;
}
}
var pc = new PolicyComponent()
// Register the Interface
Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(pc.uuid, pc.desc, pc.contractID, pc);
// Add the content policy
CategoryManager.addCategoryEntry("content-policy",pc.className,pc.contractID, true, true); // not sure you should replace (last true statement)
See this post for more:
What is missing in my nsIContentPolicy Firefox/IceWeasel extension XPCOMponent implementation for the shouldLoad to be called?
Also take a look at these docs: https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#Content_Policy

Resources