Perhaps I'm being stupid but I can't seem to find any documentation on how to get the startup arguments for an electron app. My scenario is something like this:
Right-click file in Windows Explorer
Open with -> My electron app
Electron app opens and can work with the file
I can get the electron app to open, but how do I work with the file that was right-clicked?
Assuming that you have the "Open with" portion working, Windows will pass the filename as a command line argument. So just get the file name/path from process.argv
if(process.argv.length >= 2) {
let filePath = process.argv[1];
//open, read, handle file
}
try {
var electron = require('electron');
var app = electron.remote;
if (app.process.platform == 'win32' && app.process.argv.length >= 2) {
var openFilePath = app.process.argv[1];
if (openFilePath !== "") {
console.log(openFilePath);
}
}
} catch (e) {
}
Related
Context:
Hello, I am working on a Ionic application (made in Typescript). In this application, I control a wifi camera via HTTP Request to the IP (http://192.72.1.1/myCommand to be precise).
Main actions I do with the camera:
Start recording
Stop recording
Get videos list
Download a video
When I use the Ionic DevApp:
With the Ionic DevApp, everything works perfectly, I can do all mains actions without a problem.
When I compile the application on IOS:
I compile with the command ionic cordova build ios --prod, then I archive with Xcode and send it to the AppStore to test it with Test Flight.
I got no errors while compiling / archive the application. But when I try it on my iPhone, I can start / stop recording, but can't download the video.
Problem:
Some commands are not working, but I don't know if it is getting the list or downloading the video, I have no logs. I don't understand why some commands are working but others no.
IOS is blocking download requests? How to solve my problem?
Notes:
I already tried all basic things like delete the IOS platform, recompile, uninstall, ...
I tried different Ionic HTTP plugins, same problem with all of them.
Some code:
Start / Stop the camera: (it is the same command to start / stop).
startCamera(){
var url = "http://192.72.1.1/changeRecordStatus";
var result = this.http.get(url);
result.subscribe(data => {
console.log("Works");
},
err => {
console.log("Error" + err);
}
);
}
Getting the name of the last video:
getLastVideo(){
var url = "http://192.72.1.1/listVideos";
this.http.get(url, {}, {})
.then(data => {
var xml = data.data
var xmlDOM = new DOMParser().parseFromString(xml, 'text/xml');
var temp = this.xmlToJson(xmlDOM); // function that convert XML to JSON
var resultArray = Object.keys(temp).map(function(i){
let ite = temp[i];
return ite;
});
resultArray = resultArray[0]['file'].reverse();
this.lastVideo = resultArray[0]['name']; // lastVideo is a global variable
},
(error) =>{
console.log("Error while getting the name of the last video" + error);
});
}
Downloading the file from the camera:
downloadFileFromCamera() {
this.getLastVideo();
var basename_file = this.lastVideo;
var url = "http://192.72.1.1" + basename_file;
this.fileTransfer.download(encodeURI(url), this.file.dataDirectory + '/videos/' + basename_file, true).then((entry) => {
this.video[this.counterVideos] = entry; // video is a global array
this.counterVideos +=1;
}, (error) => {
console.log("Error while downloading the last video" + error);
});
}
If someone knows how to solve my problem, I would be so grateful! Thanks in advance.
I am working on Xamarin.Forms app and it's working perfectly fine on Android device. Anyway, when I am trying to run it on iPhone simulator it's just showing the main screen of the app, but none of the features are working.
The main screen consists of two parts of which one is to browse and open files and the other is to open a menu. The layout consists of Browse, process and exit buttons and when I click on the browse button to open file explorer an alert is displayed, that something went wrong.
I enabled breakpoints and tried debugging it, but the control is going to catch exception part directly.
Here is the code for it can anyone please help me with this part? I am using Xamarin.Plugin.Filepicker NuGet package. When I place the cursor on the Exception I can see that
System.NotImplemented Exception:This functionality is not implemented in the portable version of this assembly,you should reference the NuGet Package from your main application project in order to reference the platform specific
and the code is
private Plugin.FilePicker.Abstractions.FileData file =
default(Plugin.FilePicker.Abstractions.FileData);
public async void OnBrowse(object o, EventArgs args)
{
try
{
// var file_path =
this.file = await CrossFilePicker.Current.PickFile();
if (this.file == null)
{
return;
}
string extensionType = this.file.FileName.Substring(
this.file.FileName.LastIndexOf(".",
StringComparison.Ordinal) + 1,
this.file.FileName.Length -
this.file.FileName.LastIndexOf(".", StringComparison.Ordinal) -
1).ToLower();
fileName = this.file.FileName;
if (extensionType.Equals("csv"))
{
csv_file.Text = (fileName);
}
else
{
await this.DisplayAlert("Name of the file:" + file.FileName, "File info", "OK");
}
if (SettingsPage.loggingEnabled)
{
LogUtilPage.Initialize("/storage/emulated/0");
}
}
catch (Exception e)
{
await DisplayAlert("Alert", "Something went wrong", "OK");
if (SettingsPage.loggingEnabled)
{
LogUtilPage.Log(e.Message);
}
}
}
I can't get the cordova media plugin to work, I get error code 1 which signals that the file is not getting loaded. I've tried a number of variations, but can't figure out which path is correct.
Currently my code looks like this:
function onDeviceMediaReady () {
var path = window.cordova.file.applicationDirectory + 'why.mp3';
console.log(path);
narrative = new Media(path, // success callback
function() {
console.log("playAudio():Audio Success");
},
// error callback
function(err) {
console.log("playAudio():Audio Error: "+ err.code);
});
}
this gives me a path that's file://var/cotainers/Bundle/Application/[GUID]/Cordova400.app/why.mp3
I don't get why I can't find it. the file is in the telerik appbuilder root directory.
Inside your 'WWW' folder place the file inside 'sound' folder & try following
var srcBookmark = "sound/yes.mp3"; //ios
var iOSPlayOptions = {
numberOfLoops: 1,
playAudioWhenScreenIsLocked : false
}
var media = $cordovaMedia.newMedia(srcBookmark);
//media.play(); //android
media.play(iOSPlayOptions); //ios
$timeout(function(){
media.stop();
media.release()
}, 500);
If you're using appBuilder to test your app te aplication folder is the telerik folder, you must deploy your app as APK and test the folder
Completely related to How to check a file's existence in phone directory with phonegap,
This is what I have in Android 4.0.4:
function checkIfFileExists(path, fileExists, fileDoesNotExist) {
var getFSSuccess = function(fileSystem) {
fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);
};
var getFSFail = function(evt) {
console.log(evt.target.error.code);
};
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, getFSSuccess, getFSFail); //of requestFileSystem
};
fileExists and fileDoesNotExist are basically alerts so I know what is happening.
What is happening is that even if the file exists, fileDoesNotExist is being executed.
path is something like "file:///mnt/sdcard/DCIM/Camera/14112312312.jpg", and the error I am getting is ENCODING_ERR.
UPDATE: Removing "file://" from the name worked. I added, at the beginning of getFSSuccess,
if (path.indexOf("file://") > -1) {
path = path.substring(7, path.length);
}
and that solved the problem.
Question is: why and what would be the solution for iOS? I am updating tag's src attribute with the full name ("file:///mnt/sdcard/DCIM/Camera/14112312312.jpg") and works perfect...
UPDATE: If the file is a video, the fix doesn't work. Should I remove everything before DCIM folder?
Totally related to PhoneGap FileAPI Error Code 5 finding video in storage/emulated I think.
UPDATE: Looks like this
if (isAndroid() && path.indexOf("file://") > -1) {
path = path.substring(7, path.length);
} else if (isAndroid() && path.indexOf("file:") > -1) {
path = path.substring(5, path.length);
}
solved the problem. But my question is, still, why? And, would I need to do something similar for iOS?
I want to call a polymer webapp directly via command line or via 'Process' in a dart file.
I know when running it via the dart editor, a server on port 8080 is created and listening to requests for the /web folder.
but when launching
dartium/chrome.exe path/To/Index.html
from console its simply loading the files inside the browser but wont start a server for the client.
via
file:://path/to/file.html [no 'dart is not runnning' warning, but no polymer content]
or
127.x.x.x.x.x.x.x.x:xxxxxxxx/app/index.html will obviously tell me
'This webpage is not available'
DartEditor lauches pub serve. You can do this manually without Darteditor (since Dart 1.5 AFAIK). Just launch
pub serve
from within your Polymer app package directory.
Inside your console app launch the browser with the URL that loads the page from this server.
You could also include web server functionality into your console application that serves the Polymer app to your browser.
pub help serve
lists the available options.
You can try this script as an example how to call a polymer webapp directly via 'Process' in a dart file.
This example also includes launch of default browser.
import "dart:async";
import "dart:io";
import "package:path/path.dart" as pathos;
void main(List<String> args) {
String app;
String file;
switch (args.length) {
case 1:
app = args[0];
break;
case 2:
app = args[0];
file = args[1];
break;
default:
print("Usage: pubserve.dart app_path [file_name]");
exit(0);
}
if(!new Directory(app).existsSync()) {
print("Directory not exists: $app");
exit(-1);
}
pubServe(app, file).then((exitCode) {
exit(exitCode);
});
}
Future<int> pubServe(String app, String file) {
var sdk = Platform.environment["DART_SDK"];
if (sdk == null) {
print("Dart SDK not found");
return new Future(() => -1);
}
var executable = pathos.join(sdk, "bin", "pub");
var pattern = r"^Serving (?:.*) web on (.*)$";
var regexp = new RegExp(pattern);
return Process.start(executable, ["serve"], runInShell: true,
workingDirectory: app).then((process) {
process.stdout.listen((data) {
var string = new String.fromCharCodes(data);
for (var c in data) {
stdout.writeCharCode(c);
}
var match = regexp.matchAsPrefix(string);
if (match != null) {
var url = match.group(1);
if (file != null) {
url += "/$file";
}
Timer.run(() => runBrowser(url));
}
});
process.stderr.pipe(stderr);
stdin.pipe(process.stdin);
return process.exitCode.then((exitCode) {
return exitCode;
});
});
}
void runBrowser(String url) {
var fail = false;
switch (Platform.operatingSystem) {
case "linux":
Process.run("x-www-browser", [url]);
break;
case "macos":
Process.run("open", [url]);
break;
case "windows":
Process.run("explorer", [url]);
break;
default:
fail = true;
break;
}
if (!fail) {
//print("Start browsing...");
}
}
P.S.
NOTE:
If you run this script from Dart Editor, Editor will never stops execution of subprocess (pub serve in our case) when you stop current script in Dart Editor.
This is not related only to this script. Editor always keep subprocesses alive.
If you run it from cmd-line it terminates pub serve correctly.