Enough glue to load a web page from our web server in the iOS simulator. Next challenge is uv_spawn: permission denied.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4519 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
84eaa3e2fd
commit
8bd0027e71
17
Makefile
17
Makefile
@ -643,6 +643,23 @@ apkgo: out/TildeFriends-release.apk
|
|||||||
@adb shell am start com.unprompted.tildefriends/.MainActivity
|
@adb shell am start com.unprompted.tildefriends/.MainActivity
|
||||||
.PHONY: apkgo
|
.PHONY: apkgo
|
||||||
|
|
||||||
|
# iOS Support
|
||||||
|
out/%.app/Info.plist: src/ios/Info.plist
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
cp -v $< $@
|
||||||
|
|
||||||
|
out/%.app/data.zip: $(RAW_FILES)
|
||||||
|
@zip -u $@ -q -9 -x '*.map' -r $(PACKAGE_DIRS) $(RAW_FILES)
|
||||||
|
|
||||||
|
out/tildefriends-iossimdebug.app/tildefriends: out/iossimdebug/tildefriends out/tildefriends-iossimdebug.app/Info.plist out/tildefriends-iossimdebug.app/data.zip
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
cp out/iossimdebug/tildefriends $@
|
||||||
|
|
||||||
|
iossimdebuggo: out/tildefriends-iossimdebug.app/tildefriends
|
||||||
|
xcrun simctl install booted out/tildefriends-iossimdebug.app/
|
||||||
|
xcrun simctl launch booted com.unprompted.tildefriends
|
||||||
|
.PHONEY: iossimdebuggo
|
||||||
|
|
||||||
apklog:
|
apklog:
|
||||||
@adb logcat *:S tildefriends
|
@adb logcat *:S tildefriends
|
||||||
.PHONY: apklog
|
.PHONY: apklog
|
||||||
|
@ -445,7 +445,7 @@ function handleConnection(client) {
|
|||||||
if (result == -2) {
|
if (result == -2) {
|
||||||
/* More. */
|
/* More. */
|
||||||
} else {
|
} else {
|
||||||
badRequest(client, 'Bad request.');
|
badRequest(client, `Bad request(parse=${result}, length=${inputBuffer.length - data.length}).`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (typeof result === 'object') {
|
} else if (typeof result === 'object') {
|
||||||
|
17
src/ios.m
17
src/ios.m
@ -1,7 +1,14 @@
|
|||||||
|
#include "log.h"
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <WebKit/WKWebView.h>
|
#import <WebKit/WKWebView.h>
|
||||||
#import <WebKit/WKWebViewConfiguration.h>
|
#import <WebKit/WKWebViewConfiguration.h>
|
||||||
|
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void tf_run_thread_start(const char* zip_path);
|
||||||
|
|
||||||
@interface ViewController : UIViewController
|
@interface ViewController : UIViewController
|
||||||
@property(strong, nonatomic) WKWebView* web_view;
|
@property(strong, nonatomic) WKWebView* web_view;
|
||||||
@end
|
@end
|
||||||
@ -12,7 +19,7 @@
|
|||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
||||||
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
|
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
|
||||||
[self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.tildefriends.net/"]]];
|
[self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]];
|
||||||
[self.view addSubview:self.web_view];
|
[self.view addSubview:self.web_view];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
@ -35,5 +42,13 @@
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||||
|
NSString* library_directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
||||||
|
[file_manager changeCurrentDirectoryPath:library_directory];
|
||||||
|
size_t path_length = strlen(argv[0]) - strlen(basename(argv[0]));
|
||||||
|
size_t length = path_length + strlen("data.zip");
|
||||||
|
char* zip_path = alloca(length + 1);
|
||||||
|
snprintf(zip_path, length + 1, "%.*sdata.zip", (int)path_length, argv[0]);
|
||||||
|
tf_run_thread_start(zip_path);
|
||||||
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
|
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,21 @@
|
|||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>cory</string>
|
<string>tildefriends</string>
|
||||||
<key>CFBundleSupportedPlatforms</key>
|
<key>CFBundleSupportedPlatforms</key>
|
||||||
<array>
|
<array>
|
||||||
<string>iPhoneOS</string>
|
<string>iPhoneOS</string>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>cory</string>
|
<string>tildefriends</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>cory</string>
|
<string>com.unprompted.tildefriends</string>
|
||||||
<key>CFBundleResourceSpecification</key>
|
<key>CFBundleResourceSpecification</key>
|
||||||
<string>ResourceRules.plist</string>
|
<string>ResourceRules.plist</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>cory</string>
|
<string>Tilde Friends</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#define tf_printf(...) __android_log_print(ANDROID_LOG_INFO, "tildefriends", __VA_ARGS__)
|
#define tf_printf(...) __android_log_print(ANDROID_LOG_INFO, "tildefriends", __VA_ARGS__)
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <os/log.h>
|
||||||
|
#define tf_printf(...) os_log(OS_LOG_DEFAULT, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define tf_printf printf
|
#define tf_printf printf
|
||||||
|
38
src/main.c
38
src/main.c
@ -36,7 +36,8 @@
|
|||||||
|
|
||||||
struct backtrace_state* g_backtrace_state;
|
struct backtrace_state* g_backtrace_state;
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
const char* k_db_path_default = "db.sqlite";
|
||||||
|
|
||||||
#define XOPT_PARSE(name, flags, options, config_ptr, argc, argv, extrac_ptr, extrav_ptr, err_ptr, autohelp_file, autohelp_usage, autohelp_prefix, autohelp_suffix, autohelp_spacer) do { \
|
#define XOPT_PARSE(name, flags, options, config_ptr, argc, argv, extrac_ptr, extrav_ptr, err_ptr, autohelp_file, autohelp_usage, autohelp_prefix, autohelp_suffix, autohelp_spacer) do { \
|
||||||
xoptContext *_xopt_ctx; \
|
xoptContext *_xopt_ctx; \
|
||||||
*(err_ptr) = NULL; \
|
*(err_ptr) = NULL; \
|
||||||
@ -65,6 +66,7 @@ struct backtrace_state* g_backtrace_state;
|
|||||||
break; \
|
break; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
#if !TARGET_OS_IPHONE
|
||||||
static int _tf_command_test(const char* file, int argc, char* argv[]);
|
static int _tf_command_test(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_import(const char* file, int argc, char* argv[]);
|
static int _tf_command_import(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_export(const char* file, int argc, char* argv[]);
|
static int _tf_command_export(const char* file, int argc, char* argv[]);
|
||||||
@ -88,8 +90,6 @@ const command_t k_commands[] = {
|
|||||||
{ "check", _tf_command_check, "Validate messages in the SSB database." },
|
{ "check", _tf_command_check, "Validate messages in the SSB database." },
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* k_db_path_default = "db.sqlite";
|
|
||||||
|
|
||||||
void shedPrivileges()
|
void shedPrivileges()
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
@ -309,6 +309,7 @@ xopt_help:
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct tf_run_args_t {
|
typedef struct tf_run_args_t {
|
||||||
const char* script;
|
const char* script;
|
||||||
@ -373,6 +374,7 @@ static void _tf_run_task_thread(void* data)
|
|||||||
info->result = _tf_run_task(&info->args, info->index);
|
info->result = _tf_run_task(&info->args, info->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TARGET_OS_IPHONE
|
||||||
static int _tf_command_run(const char* file, int argc, char* argv[])
|
static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||||
{
|
{
|
||||||
xoptOption options[] = {
|
xoptOption options[] = {
|
||||||
@ -654,3 +656,33 @@ done:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void tf_run_thread_start(const char* zip_path)
|
||||||
|
{
|
||||||
|
uv_thread_t* thread = tf_malloc(sizeof(uv_thread_t));
|
||||||
|
tf_run_thread_data_t* data = tf_malloc(sizeof(tf_run_thread_data_t));
|
||||||
|
tf_run_args_t args =
|
||||||
|
{
|
||||||
|
.count = 1,
|
||||||
|
.script = "core/core.js",
|
||||||
|
.http_port = 12345,
|
||||||
|
.https_port = 12346,
|
||||||
|
.ssb_port = 8008,
|
||||||
|
.db_path = k_db_path_default,
|
||||||
|
.zip = zip_path,
|
||||||
|
};
|
||||||
|
*data = (tf_run_thread_data_t)
|
||||||
|
{
|
||||||
|
.args = args,
|
||||||
|
};
|
||||||
|
uv_thread_create(thread, _tf_run_task_thread, data);
|
||||||
|
#if 0
|
||||||
|
uv_thread_join(&threads[i]);
|
||||||
|
if (data[i].result != 0)
|
||||||
|
{
|
||||||
|
result = data[i].result;
|
||||||
|
}
|
||||||
|
tf_free(data);
|
||||||
|
tf_free(threads);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user