الربط العميق ومعالجات البروتوكولات
اسمح للمستخدمين بتشغيل تطبيق Electron والتنقل فيه من مخططات URL مخصصة، وهو تكامل أساسي مع دورة الحياة يكمل أحداث بدء التشغيل والتحديثات.
الربط العميق ومعالجات البروتوكولات درس مجاني في Electron Desktop App Development على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Electron Desktop App Development، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Electron Desktop App Development 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Launching From a Link
Deep linking lets a URL like myapp://open/project/42 launch or focus your app and jump straight to content.
Custom Protocols
Register a custom URL scheme so the OS knows links of that type belong to your app.
app.setAsDefaultProtocolClient('myapp');Parsing the Deep Link
Extract the path and parameters from the incoming URL to decide where to navigate.
function parseDeepLink(url) {
const u = new URL(url);
return { host: u.host, path: u.pathname };
}
console.log(parseDeepLink('myapp://open/project/42'));Handling Links on macOS
On macOS, deep links arrive via the open-url event, even while the app is running.
app.on('open-url', (event, url) => {
event.preventDefault();
handleLink(url);
});Handling Links on Windows and Linux
On Windows and Linux the URL comes in as a command-line argument, so inspect process.argv on launch.
function urlFromArgv(argv) {
return argv.find(a => a.startsWith('myapp://'));
}
console.log(urlFromArgv(['electron', '.', 'myapp://open/5']));Single Instance Coordination
Use the single instance lock so a second launch forwards its URL to the already-running app instead of starting a new one.
const gotLock = app.requestSingleInstanceLock();
if (!gotLock) app.quit();second-instance Event
The second-instance event delivers the new command line, where the deep link lives, and lets you focus the main window.
app.on('second-instance', (e, argv) => {
const url = urlFromArgv(argv);
if (url) handleLink(url);
});Cold Start vs Warm Start
Handle both cases: the app launched fresh by the link (cold) and the app already open (warm). Route both to the same handler.
Validating the Link
Never trust a deep link blindly. Validate the path and parameters before acting on them to avoid abuse.
Testing Deep Links
Test by typing the URL into a browser or terminal. During development the scheme must point at your packaged or running app.
Use Cases
Deep links power OAuth callbacks, sharing, and notifications that jump straight to relevant content, tying nicely into the app lifecycle.
Quick Check
Test your deep linking knowledge.
Recap
You learned to register a custom protocol, parse deep links, handle them across platforms, coordinate with the single-instance lock, and validate input, enabling URL-driven app navigation.
الأسئلة الشائعة
هل درس «الربط العميق ومعالجات البروتوكولات» مجاني؟
نعم — نص درس «الربط العميق ومعالجات البروتوكولات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Electron Desktop App Development، انتقل إلى CoddyKit PRO. تتضمن دورة Electron Desktop App Development 4 دروس في المجموع.
ماذا ستتعلم في «الربط العميق ومعالجات البروتوكولات»؟
اسمح للمستخدمين بتشغيل تطبيق Electron والتنقل فيه من مخططات URL مخصصة، وهو تكامل أساسي مع دورة الحياة يكمل أحداث بدء التشغيل والتحديثات. تتمرن على Electron Desktop App Development مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Electron Desktop App Development؟
لا تُشترط خبرة سابقة. Electron Desktop App Development على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الربط العميق ومعالجات البروتوكولات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Electron Desktop App Development هذا؟
نعم. كل درس في Electron Desktop App Development يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إدارة أحداث دورة حياة التطبيق
- تطبيق التحديثات التلقائية
- الإبلاغ عن الأعطال
- الربط العميق ومعالجات البروتوكولات