nx: check version

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/672/head
Varun Patil 2023-05-17 23:16:11 -07:00
parent 554e91d447
commit 662397c320
4 changed files with 26 additions and 5 deletions

View File

@ -3,9 +3,11 @@
namespace OCA\Memories\Controller; namespace OCA\Memories\Controller;
use OCA\Files\Event\LoadSidebar; use OCA\Files\Event\LoadSidebar;
use OCA\Memories\Service\BinExt;
use OCA\Memories\Util; use OCA\Memories\Util;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest; use OCP\IRequest;
@ -40,9 +42,10 @@ class PageController extends Controller
*/ */
public function main() public function main()
{ {
$user = $this->userSession->getUser(); // Check native version if available
if (null === $user) { $nativeVer = Util::callerNativeVersion();
return null; if (null !== $nativeVer && version_compare($nativeVer, BinExt::NX_VER_MIN, '<')) {
return new PublicTemplateResponse($this->appName, 'native-old');
} }
// Scripts // Scripts

View File

@ -10,6 +10,7 @@ class BinExt
{ {
public const EXIFTOOL_VER = '12.60'; public const EXIFTOOL_VER = '12.60';
public const GOVOD_VER = '0.1.5'; public const GOVOD_VER = '0.1.5';
public const NX_VER_MIN = '1.0';
/** Copy a binary to temp dir for execution */ /** Copy a binary to temp dir for execution */
public static function getTempBin(string $path, string $name, bool $copy = true): string public static function getTempBin(string $path, string $name, bool $copy = true): string

View File

@ -404,12 +404,26 @@ class Util
*/ */
public static function callerIsNative(): bool public static function callerIsNative(): bool
{ {
$request = \OC::$server->get(\OCP\IRequest::class); $userAgent = \OC::$server->get(\OCP\IRequest::class)->getHeader('User-Agent');
$userAgent = $request->getHeader('User-Agent');
return false !== strpos($userAgent, 'MemoriesNative'); return false !== strpos($userAgent, 'MemoriesNative');
} }
/**
* Get the version of the native caller.
*/
public static function callerNativeVersion(): ?string
{
$userAgent = \OC::$server->get(\OCP\IRequest::class)->getHeader('User-Agent');
$matches = [];
if (preg_match('/MemoriesNative\/([0-9.]+)/', $userAgent, $matches)) {
return $matches[1];
}
return null;
}
/** /**
* Kill all instances of a process by name. * Kill all instances of a process by name.
* Similar to pkill, which may not be available on all systems. * Similar to pkill, which may not be available on all systems.

View File

@ -0,0 +1,3 @@
<div id="app-content" style="padding: 20px;">
Your native app version is too old! Please update to the latest version.
</div>