Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
JavaScript: Use two seperate dialogues in the same nodeJS electron controller (CLOSED)

I want to create two seperate electron dialogs, one for APK file selection, and one for Directory selection so I can select a decompiled APK folder.

Using one dialog for both File Selection and Directory Selection at the same time, cannot be done on both Linux & Windows, unlike how it can on MacOS.

So after some time talking with the devs over at github.com/electron/electron, they have told me that it is possible to use 2 seperate dialogs in the same JavaScript file that I use as the main controller to my Linux desktop app, as a workaround to this for Linux & Windows.

The devs pointed me to this page here at electronjs.org, but unfortunately I am having trouble understanding some of it, so I've ended up here at stackoverflow.

The code I've managed to produce so far is below, any help on this would be appreciated.

// First dialog for File Selection | This works fine
$appCtrl.BrowseApk = () => {
    dialog.showOpenDialog({'File browser'}, {

        properties: ['openFile']
    }).then(result => {

        if(result.canceled) {

            $appCtrl.Log("No file selected");
        } else {

            $appCtrl.Log("File selected" + result.filePaths[0]);
            readFile(result.filePaths[0]);
        }
    }).catch(() => {
        $appCtrl.Log("No file selected");
    })

    function readFile(filepath) {
        $appCtrl.filePath = filepath;
        $appCtrl.$apply();
    })
            

    // Second Dialog for Folder Selection | This breaks my electron UI
    $appCtrl.BrowseFolder = () => {
    dialog.showOpenDialog({'Folder browser'}, {

        properties: ['openDirectory']
    }).then(result => {

        if(result.canceled) {

            $appCtrl.Log("No directory selected");
        } else {

            $appCtrl.Log("Directory selected" + result.filePaths);
            readFile(result.filePaths);
        }
    }).catch(() => {
        $appCtrl.Log("No directory selected");
    })

    function readFile(filepath) {
        $appCtrl.filePath = filepath;
        $appCtrl.$apply();
    })     
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Problem solved! all I had to do was the following below.

//function to open the dialog and an choose apk file
  $appCtrl.BrowseApk = () => {
      dialog.showOpenDialog({ 
          properties: ['openFile'], 
          title: 'Choose APK to bind', 
          buttonLabel: 'Select APK',
          filters: [
              { name: 'Android APK', extensions: ['apk'] } // only select apk files
          ]
      }).then(result => { 
          if(result.canceled) {
              $appCtrl.Log("No file selected"); //if user cancels the dialog
          } else {
              $appCtrl.Log("File choosen  " + result.filePaths[0]); //if user selects an APK file
              readFile(result.filePaths[0]); 
          }
      }).catch(() => { 
          $appCtrl.Log("No file selected"); 
      })

      function readFile(filepath) {
          $appCtrl.filePath = filepath;
          $appCtrl.$apply();
      }
  }
  // function to select decompiled APK folder
  $appCtrl.BrowseFolder = () => { 
      dialog.showOpenDialog({
          properties: ['openDirectory'],
          title: 'Choose decompiled APK folder',
          buttonLabel: 'Select Folder',
          filters: [
              { name: 'Folders', extensions: ['*'] }
          ]
      }).then(result => {
          if(result.canceled) {
              $appCtrl.Log("No folder selected");
          } else {
              $appCtrl.Log("Folder choosen " + result.filePaths[0]); //if user selects a Decompiled APK file
              readFile(result.filePaths[0]);
          }
      }).catch(() => {
          $appCtrl.Log("No folder selected");
      })
      
      function readFile(filepath) {
        $appCtrl.filePath = filepath;
        $appCtrl.$apply();
    }

  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!