Electron Desktop App Development · Ders

Kabuk Entegrasyonu

Electron'un `shell` modülü aracılığıyla işletim sisteminin varsayılan uygulamalarını kullanarak harici bağlantıları, dosyaları ve dizinleri açmayı öğrenin.

3. ders / 411 adım

Kabuk Entegrasyonu, CoddyKit'te ücretsiz bir Electron Desktop App Development dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Electron Desktop App Development öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Electron Desktop App Development kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Intro to Shell Integration

Welcome to Shell Integration! In Electron, your desktop app can interact with the user's operating system (OS) in powerful ways.

This means opening external links, files, or even showing items in the OS file explorer, just like native apps do.

Meet the `shell` Module

Electron provides the built-in shell module to make these OS interactions easy and safe. It's available in both the main and renderer processes.

The shell module lets your app delegate tasks like opening URLs or files to the OS's default applications.

Opening External URLs

The most common use case is opening web links in the user's default browser. You can do this with shell.openExternal(url).

This is crucial for security: instead of rendering external web content inside your app, you hand it off to a trusted browser.

Code: Open an External Link

Here's how you can open an external URL. This code would typically be in your main.js or called from a preload script if triggered by the renderer.

Try running this example:

const { app, shell } = require('electron');

app.whenReady().then(() => {
  // In a real app, this would be triggered by a user action.
  // For this demo, it opens when the app is ready.
  shell.openExternal('https://www.electronjs.org/docs')
    .then(() => console.log('Opened Electron docs!'))
    .catch(err => console.error('Failed to open URL:', err));
  // A real Electron app would also create a BrowserWindow here.
});

Opening Local Files & Folders

Need to open a document, image, or even a directory from your app? Use shell.openPath(path).

This function attempts to open the given file or directory with the OS's default application for that file type.

Code: Open a Local File

This example creates a simple text file and then opens it using the OS's default text editor.

Try running this example:

const { app, shell } = require('electron');
const path = require('path');
const fs = require('fs');

app.whenReady().then(() => {
  const userDataPath = app.getPath('userData');
  const filePath = path.join(userDataPath, 'my-document.txt');

  // Create a dummy file for demonstration
  fs.writeFileSync(filePath, 'Hello from CoddyKit! This is your document.');

  shell.openPath(filePath)
    .then(() => console.log(`Opened: ${filePath}`))
    .catch(err => console.error(`Failed to open path: ${err}`));
});

Showing Items in Explorer/Finder

Sometimes you don't want to open a file, but just show where it is. shell.showItemInFolder(fullPath) does just that.

It reveals the specified file in the user's operating system file manager (e.g., File Explorer on Windows, Finder on macOS), and optionally selects it.

Code: Show Item in Folder

Let's create another file and then show its location to the user.

Try running this example:

const { app, shell } = require('electron');
const path = require('path');
const fs = require('fs');

app.whenReady().then(() => {
  const desktopPath = app.getPath('desktop');
  const fileToShowPath = path.join(desktopPath, 'coddykit_demo_file.txt');

  // Create a dummy file on the desktop
  fs.writeFileSync(fileToShowPath, 'Find me!');

  shell.showItemInFolder(fileToShowPath);
  console.log(`Showing item in folder: ${fileToShowPath}`);
});

Security & Best Practices

When using shell methods, especially with user-provided input, always consider security:

  • Validate URLs: Before calling openExternal(), ensure the URL is safe and intended.
  • Context Isolation: In the renderer process, use a preload script to expose only necessary shell functions securely.
  • Error Handling: Always include .catch() for promise-based methods like openExternal and openPath.

Quick Check on Shell

Which shell module method would you use to open a web link in the user's default browser?

Recap: Shell Integration

Great job! You've learned how Electron's shell module helps your app interact with the native OS:

  • shell.openExternal() for web links.
  • shell.openPath() for local files/folders.
  • shell.showItemInFolder() to reveal items in the file manager.

These methods provide a seamless and secure way to extend your app's functionality to the native environment.

Başlamak ücretsiz

Yapay zeka eğitmeniyle JavaScript öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
47

Sıkça Sorulan Sorular

“Kabuk Entegrasyonu” dersi ücretsiz mi?

Evet — “Kabuk Entegrasyonu” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Electron Desktop App Development kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Electron Desktop App Development kursu toplamda 4 dersten oluşur.

“Kabuk Entegrasyonu” dersinde ne öğreneceğim?

Electron'un `shell` modülü aracılığıyla işletim sisteminin varsayılan uygulamalarını kullanarak harici bağlantıları, dosyaları ve dizinleri açmayı öğrenin. Electron Desktop App Development ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Electron Desktop App Development öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Electron Desktop App Development, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“Kabuk Entegrasyonu” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Electron Desktop App Development dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Electron Desktop App Development dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Yerel Menüler ve Bağlam Menüler
  2. İletişim Kutuları ve Bildirimler
  3. Kabuk Entegrasyonu
  4. Genel Kısayollar ve Pano Erişimi
← Electron Desktop App Development Sayfasına Dön