Skip to content

Updated xdg-open version to support KDE6#198

Open
olivierbourdeau wants to merge 1 commit into
unjs:mainfrom
olivierbourdeau:fix/xdg-open-kde6
Open

Updated xdg-open version to support KDE6#198
olivierbourdeau wants to merge 1 commit into
unjs:mainfrom
olivierbourdeau:fix/xdg-open-kde6

Conversation

@olivierbourdeau

Copy link
Copy Markdown

resolves #197

@pi0

pi0 commented May 21, 2025

Copy link
Copy Markdown
Member

i cannot merge this PR with this changes.

please provide link to upstream source of new binary.

@olivierbourdeau

olivierbourdeau commented May 21, 2025

Copy link
Copy Markdown
Author

@pi0 xdg-open is included in xdg-utils, which is being maintained by this community : https://www.freedesktop.org/wiki/Software/xdg-utils/

Here is the repo : https://gitlab.freedesktop.org/xdg/xdg-utils

The file is scripts/xdg-open.in . I just looked at the file and it seems to be even more recent than the one I sent in the PR. It uses functions from other scripts in xdg-utils, like detectDE, exit_success, exit_failure_operation_failed, exit_failure_syntax, exit_failure_operation_impossible, check_input_file, has_display, first_word, and kfmclient_fix_exit_code. Those functions need to be added into xdg-open, if you want to avoid having to use the entire xdg-utils library.

Edit : Here is an official source for the package. xdg-utils-1.2.1-2.3.noarch.rpm contains a flattened version of the file, which will allow you to grab the entire xdg-open file without having to modify it :

https://software.opensuse.org/package/xdg-utils

Here is the command I used to make the file readable :

rpm2cpio xdg-utils-1.2.1-2.3.noarch.rpm | cpio -idmv ./usr/bin/xdg-open

@pi0

pi0 commented May 21, 2025

Copy link
Copy Markdown
Member

Do you think can you help on writing a mini script to download/vendor binary as js?

@olivierbourdeau

Copy link
Copy Markdown
Author

@pi0 this js script seems to work on my computer (linux), it outputs the xdg-open script into output-xdg-open.txt in the working directory. The link is for the specific version I linked previously.

const https = require('https');
const fs = require('fs');
const { execSync } = require('child_process');
const path = require('path');

const rpmUrl = 'https://download.opensuse.org/repositories/openSUSE:/Factory/standard/noarch/xdg-utils-1.2.1-2.3.noarch.rpm';
const rpmFile = 'xdg-utils.rpm';

function downloadFile(url, dest) {
  return new Promise((resolve, reject) => {
    https.get(url, res => {
      if (res.statusCode === 302 && res.headers.location) {
        return resolve(downloadFile(res.headers.location, dest));
      }

      if (res.statusCode !== 200) {
        return reject(new Error(`Status code ${res.statusCode}`));
      }

      const file = fs.createWriteStream(dest);
      res.pipe(file);
      file.on('finish', () => file.close(resolve));
      file.on('error', reject);
    }).on('error', reject);
  });
}

(async () => {
  try {
    await downloadFile(rpmUrl, rpmFile);
    execSync(`rpm2cpio ${rpmFile} | cpio -idmv`, { stdio: 'inherit' });

    const content = fs.readFileSync('usr/bin/xdg-open', 'utf8');
    fs.writeFileSync('output-xdg-open.txt', content);
    console.log('xdg-open content written to output-xdg-open.txt');
  } catch (err) {
    console.error('Error:', err.message);
  }
})();

If you are on windows, you could try this ( I haven't tested it )

const https = require('https');
const fs = require('fs');
const { Readable } = require('stream');
const RpmParser = require('rpm-parser');
const CpioParser = require('cpio-parser');

const rpmUrl = 'https://download.opensuse.org/repositories/openSUSE:/Factory/standard/noarch/xdg-utils-1.2.1-2.3.noarch.rpm';

function downloadBuffer(url) {
  return new Promise((resolve, reject) => {
    https.get(url, res => {
      if (res.statusCode === 302 && res.headers.location) {
        return resolve(downloadBuffer(res.headers.location));
      }

      if (res.statusCode !== 200) {
        return reject(new Error(`HTTP ${res.statusCode}`));
      }

      const chunks = [];
      res.on('data', chunk => chunks.push(chunk));
      res.on('end', () => resolve(Buffer.concat(chunks)));
      res.on('error', reject);
    }).on('error', reject);
  });
}

(async () => {
  try {
    const rpmBuffer = await downloadBuffer(rpmUrl);
    const rpm = await RpmParser.parse(rpmBuffer);
    const cpioStream = Readable.from(rpm.cpio);

    let found = false;

    cpioStream.pipe(CpioParser()).on('entry', entry => {
      if (entry.path.endsWith('/usr/bin/xdg-open')) {
        found = true;
        const chunks = [];
        entry.on('data', chunk => chunks.push(chunk));
        entry.on('end', () => {
          const content = Buffer.concat(chunks).toString('utf8');
          fs.writeFileSync('output-xdg-open.txt', content);
          console.log('xdg-open content written to output-xdg-open.txt');
        });
      } else {
        entry.resume(); // skip unused entries
      }
    }).on('finish', () => {
      if (!found) console.error('xdg-open not found in RPM.');
    }).on('error', err => console.error('CPIO parse error:', err.message));
  } catch (err) {
    console.error('Error:', err.message);
  }
})();

For the Windows version, you need to install packages :

npm install rpm-parser cpio-parser

@olivierbourdeau

olivierbourdeau commented May 21, 2025

Copy link
Copy Markdown
Author

@pi0 a more simple way, if you want to avoid using the whole new version, would be to do this :

In the xdg-open.ts file from the listhen package, the one I wanted to modify in this pull request, do CTRL+F to find the single occurence of the string 4). Replace it for 4|6), that way version 6 of KDE Plasma will be supported.

@olivierbourdeau

Copy link
Copy Markdown
Author

@pi0 Any update on this ? The issue can be a simple fix, you only need to add two characters so that

open_kde()
{
    if [ -n "${KDE_SESSION_VERSION}" ]; then
      case "${KDE_SESSION_VERSION}" in
        4)
          kde-open "$1"

becomes


open_kde()
{
    if [ -n "${KDE_SESSION_VERSION}" ]; then
      case "${KDE_SESSION_VERSION}" in
        4|6)
          kde-open "$1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outdated version of xdg-open script causes browser to not open on KDE Plasma 6 desktop environments

2 participants