GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Expose __onLiveSync handler · NativeScript/ios@34ac9aa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • NativeScript
    • NativeScript.h
    • NativeScript.mm
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎NativeScript/NativeScript.h‎

Copy file name to clipboardExpand all lines: NativeScript/NativeScript.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
@interface NativeScript : NSObject
44

55
+ (void)start:(void*)metadataPtr;
6+
+ (bool)liveSync;
67

78
@end
Collapse file

‎NativeScript/NativeScript.mm‎

Copy file name to clipboard
+42-5Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,55 @@
11
#include <Foundation/Foundation.h>
22
#include "NativeScript.h"
33
#include "runtime/Runtime.h"
4+
#include "runtime/Helpers.h"
5+
6+
using namespace v8;
7+
using namespace tns;
48

59
@implementation NativeScript
610

7-
+(void)start:(void*)metadataPtr {
11+
static Runtime* runtime_ = nullptr;
12+
13+
+ (void)start:(void*)metadataPtr {
814
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
915
NSArray* components = [NSArray arrayWithObjects:resourcePath, @"app", nil];
1016
NSString* path = [NSString pathWithComponents:components];
1117
const char* baseDir = [path UTF8String];
1218

13-
tns::Runtime::InitializeMetadata(metadataPtr);
14-
tns::Runtime* runtime = new tns::Runtime();
15-
runtime->InitAndRunMainScript(baseDir);
19+
Runtime::InitializeMetadata(metadataPtr);
20+
runtime_ = new Runtime();
21+
runtime_->InitAndRunMainScript(baseDir);
22+
}
23+
24+
+ (bool)liveSync {
25+
if (runtime_ == nullptr) {
26+
return false;
27+
}
28+
29+
Isolate* isolate = runtime_->GetIsolate();
30+
HandleScope scope(isolate);
31+
Local<Context> context = isolate->GetCurrentContext();
32+
Local<Object> global = context->Global();
33+
Local<Value> value;
34+
bool success = global->Get(context, tns::ToV8String(isolate, "__onLiveSync")).ToLocal(&value);
35+
if (!success || value.IsEmpty() || !value->IsFunction()) {
36+
return false;
37+
}
38+
39+
Local<v8::Function> liveSyncFunc = value.As<v8::Function>();
40+
Local<Value> args[0];
41+
Local<Value> result;
42+
43+
TryCatch tc(isolate);
44+
success = liveSyncFunc->Call(context, v8::Undefined(isolate), 0, args).ToLocal(&result);
45+
if (!success) {
46+
if (tc.HasCaught()) {
47+
printf("%s\n", tns::ToString(isolate, tc.Exception()).c_str());
48+
}
49+
return false;
50+
}
51+
52+
return true;
1653
}
1754

18-
@end
55+
@end

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.