get_platform_configuration_option('push_preference', '0'); $apiKey = Platform::getInstance()->get_platform_configuration_option('push_apikey', ''); // No API key? No push messages are enabled, so no point continuing really... if (empty($apiKey)) { $pushPreference = 0; } // We use a switch in case we add support for more push APIs in the future. The push_preference platform // option will tell us which service to use. In that case we'll have to refactor this class, but the public // API will remain the same. switch ($pushPreference) { default: case 0: $this->enabled = false; break; case 1: try { $this->connector = new Connector($apiKey); $this->connector->getDevices(); } catch (\Exception $e) { Factory::getLog()->warning('Push messages cannot be sent. Error received when trying to establish PushBullet connection:' . $e->getMessage()); $this->enabled = false; } break; } } /** * Sends a push message to all connected devices. The intent is to provide the user with an information message, * e.g. notify them about the progress of the backup. * * @param string $subject The subject of the message, shown in the lock screen. Keep it short. * @param string $details Long(er) description of what the message is about. Plain text (no HTML). * * @return void */ public function message($subject, $details = null) { if (!$this->enabled) { return; } try { $this->connector->pushNote('', $subject, $details); } catch (\Exception $e) { Factory::getLog()->warning('Push messages suspended. Error received when trying to send push message:' . $e->getMessage()); $this->enabled = false; } } /** * Sends a push message, containing a URL/URI, to all connected devices. The URL will be rendered as something * clickable on most devices. * * @param string $url The URL/URI * @param string $subject The subject of the message, shown in the lock screen. Keep it short. * @param string $details Long(er) description of what the message is about. Plain text (no HTML). * * @return void */ public function link($url, $subject, $details = null) { if (!$this->enabled) { return; } try { $this->connector->pushLink('', $subject, $url, $details); } catch (\Exception $e) { Factory::getLog()->warning('Push messages suspended. Error received when trying to send push message with a link:' . $e->getMessage()); $this->enabled = false; } } }