跨平台桌面程式架構 Electron


跨平台桌面程式架構 Cross Platform - Electron


Node.js跟OS如何連結

Node.js C++ Addons

  • node-addons
  • Addons are dynamically-linked shared objects written in C++. The require() function can load Addons as ordinary Node.js modules. Addons provide an interface between JavaScript and C/C++ libraries.
  • There are three options for implementing Addons:

Node.js Foreign Function Interface

  • node-ffi
  • node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code.
  • It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C.

Shell.js - Unix shell commands for Node.js

  • Node Child Process
  • shelljs
    • ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script’s dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts!


Windows桌面API

Windows Native API

  • MS Docs: Choose your app platform
    • Universal Windows Platform (UWMP)
    • WPF (.NET)
    • Windows Form (.NET)
    • Win32
  • MS Docs: GetActiveWindow function
  • MS Docs: GetForegroundWindow function
  • MS Docs: GetWindowThreadProcessId function
  • MS Doc: Platform Invoke (P/Invoke)
  • Getting the Active Process
    • When developing software that monitors running processes, it can be useful to obtain details of the currently active application. The .NET framework does not provide methods to permit this so Platform Invocation Services (P/Invoke) must be used.
    • When using Microsoft Windows, there can only be one active, or foreground, window. This is the window that can receive input from the user and whose owning thread has a slightly higher priority than other open windows. In some situations it can be useful to identify the active process that owns this window.
    • The .NET framework provides a class, named “Process”, that allows you to examine the details of a running process. However, this class cannot be used to identify the program that is currently in use. In order to identify the foreground window and obtain a Process object linked to it, you must use Platform Invocation Services (P/Invoke) to call functions from the Windows API.
  • SO: How to track WinRT applications (in Win32 it was simple)?
    • GetForegroundWindow
    • GetWindowThreadProcessId
    • You see, in WinRT, your application is the top-most application. And when your app is not the top-most application then your threads are suspended and the kernel will not schedule any more operations for your app. End of story.
    • This means what you are wanting to accomplish cannot be done in WinRT. You are thinking more like a resident app or a service with access to the desktop. Those apps have two advantages. 1) they are always running. And, 2) they have the API to do what you are wanting.
    • WinRT intentionally puts apps in a sandbox so that the user’s experience, performance and battery life are protected. Your scenario and scores more like yours underscore the continuing need for desktop apps. (as long as there is a continuing need for those types of apps.

Windows Node API

Windows Electron


macOS桌面API

macOS Native API

  • Apple Dev: Window Layering and Types of Window
    • Key Window. The key window responds to user input, whether from the keyboard, mouse, or alternative input devices, for an application and is the primary recipient of messages from menus and panels. Usually, a window is made key when the user clicks it. Each application can have only one key window at a given time.
    • Main Window. The main window is the standard window where the user is currently working. The main window is not always the key window. There are times when a window other than the main window takes the focus of the input device, while the main window still remains the focus of the user’s attention and of user actions carried out in panels and menus.
  • SO: In OS X, how can I detect when the currently active application changes?

macOS Node API