Skip to content

Introduction

Business logic layer. It is recommended to export two objects following the example pattern: ExampleService and exampleService

  • exampleService: An instantiated object, avoiding duplicate resource creation and waste, improving resource utilization efficiency
  • ExampleService: The original class, used for inheritance or creating new instances

Example

javascript
/**
 * Example service
 * @class
 */
class ExampleService {

  /**
   * test
   */
  async test (args, event, other) {
    const obj = {
      status:'ok',
      params: args
    }

    // Proactively send a request to the frontend
    // channel is the route monitored by frontend ipc.on()
    const channel = "controller/example/something"
    // event passed from controller
    // IpcMainInvokeEvent
    event.reply(channel, {age:21})
    // IpcMainEvent
    event.sender.send(`${channel}`, {age:21})

    return obj;
  }
}