From f5bf46f48042762e0e9ad055a9ceda450700bd1f Mon Sep 17 00:00:00 2001 From: Chhatoi Pritam Baral Date: Thu, 1 Nov 2012 07:45:29 +0530 Subject: [PATCH] JS resource compilation, platform independent. --- appshell.gyp | 59 ++++++++++++++++++++++++++-- appshell/appshell_extensions_gtk.cpp | 55 +++++++++++--------------- appshell/cefclient_gtk.cpp | 12 +++++- appshell/client_app_gtk.cpp | 30 ++++++++------ appshell_paths.gypi | 3 ++ 5 files changed, 108 insertions(+), 51 deletions(-) diff --git a/appshell.gyp b/appshell.gyp index 69db85e12..295faa4ee 100755 --- a/appshell.gyp +++ b/appshell.gyp @@ -6,6 +6,7 @@ 'variables': { 'appname': 'Brackets', 'pkg-config': 'pkg-config', + 'target_arch%': 'environment', 'chromium_code': 1, 'conditions': [ [ 'OS=="mac"', { @@ -165,18 +166,48 @@ ], }], ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', { + 'actions': [ + { + 'action_name': 'appshell_extensions_js', + 'inputs': [ + 'appshell/appshell_extensions.js', + ], + 'outputs': [ + 'appshell_extensions_js.o', + ], + 'action': [ + 'objcopy', + '--input', + 'binary', + '--output', + '<(output_bfd)', + '--binary-architecture', + 'i386', + '<@(_inputs)', + '<@(_outputs)', + ], + 'message': 'compiling js resource' + }, + ], 'cflags': [ ' @@ -65,8 +66,8 @@ class LiveBrowserMgrLin LiveBrowserMgrLin(); virtual ~LiveBrowserMgrLin(); - int m_closeLiveBrowserHeartbeatTimerId; - int m_closeLiveBrowserTimeoutTimerId; + int m_closeLiveBrowserHeartbeatTimerId; + int m_closeLiveBrowserTimeoutTimerId; CefRefPtr m_closeLiveBrowserCallback; CefRefPtr m_browser; @@ -682,18 +683,6 @@ void BringBrowserWindowToFront(CefRefPtr browser) } } -// void ConvertToNativePath(ExtensionString& filename) -// { -// // Convert '/' to '\' -// replace(filename.begin(), filename.end(), '/', '\\'); -// } - -// void ConvertToUnixPath(ExtensionString& filename) -// { -// // Convert '\\' to '/' -// replace(filename.begin(), filename.end(), '\\', '/'); -// } - // // Maps errors from errno.h to the brackets error codes // // found in brackets_extensions.js // int ConvertErrnoCode(int errorCode, bool isReading) @@ -767,22 +756,22 @@ int ShowFolderInOSWindow(ExtensionString pathname) int ConvertLinuxErrorCode(int errorCode, bool isReading) { - // switch (errorCode) { - // case NO_ERROR: - // return NO_ERROR; - // case ENOENT: - // case ERROR_FILE_NOT_FOUND: - // return ERR_NOT_FOUND; - // case EACCESS: - // return isReading ? ERR_CANT_READ : ERR_CANT_WRITE; - // case ERROR_WRITE_PROTECT: - // return ERR_CANT_WRITE; - // case ERROR_HANDLE_DISK_FULL: - // return ERR_OUT_OF_SPACE; - // case ERROR_ALREADY_EXISTS: - // return ERR_FILE_EXISTS; - // default: - // return ERR_UNKNOWN; - // } - return errorCode; -} \ No newline at end of file + switch (errorCode) { + case NO_ERROR: + return NO_ERROR; + case ENOENT: + return ERR_NOT_FOUND; + case EACCES: + return isReading ? ERR_CANT_READ : ERR_CANT_WRITE; + case ENOTDIR: + return ERR_NOT_DIRECTORY; +// case ERROR_WRITE_PROTECT: +// return ERR_CANT_WRITE; +// case ERROR_HANDLE_DISK_FULL: +// return ERR_OUT_OF_SPACE; +// case ERROR_ALREADY_EXISTS: +// return ERR_FILE_EXISTS; + default: + return ERR_UNKNOWN; + } +} diff --git a/appshell/cefclient_gtk.cpp b/appshell/cefclient_gtk.cpp index b2096b457..21b9aee81 100644 --- a/appshell/cefclient_gtk.cpp +++ b/appshell/cefclient_gtk.cpp @@ -31,6 +31,11 @@ void TerminationSignalHandler(int signatl) { destroy(); } +//Callback for File > Exit... menu item. +gboolean ExitActivated(GtkWidget* widget) { + destroy(); +} + // // Callback for Debug > Get Source... menu item. // gboolean GetSourceActivated(GtkWidget* widget) { // if (g_handler.get() && g_handler->GetBrowserId()) @@ -204,7 +209,10 @@ GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) { GtkWidget* CreateMenuBar() { GtkWidget* menu_bar = gtk_menu_bar_new(); - GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests"); + GtkWidget* debug_menu = CreateMenu(menu_bar, "File"); + + AddMenuEntry(debug_menu, "Exit", + G_CALLBACK(ExitActivated)); return menu_bar; } @@ -361,4 +369,4 @@ CefString AppGetCachePath() { cachePath.append("/cef_data"); return CefString(cachePath); -} \ No newline at end of file +} diff --git a/appshell/client_app_gtk.cpp b/appshell/client_app_gtk.cpp index 135b26f9e..051c2e57a 100644 --- a/appshell/client_app_gtk.cpp +++ b/appshell/client_app_gtk.cpp @@ -33,6 +33,7 @@ #include extern time_t g_appStartupTime; +extern char _binary_appshell_appshell_extensions_js_start; CefString ClientApp::GetCurrentLanguage() { @@ -43,22 +44,25 @@ CefString ClientApp::GetCurrentLanguage() std::string ClientApp::GetExtensionJSSource() { - //Another bloody TODO here. - std:: string extensionJSPath(AppGetSupportDirectory()); - extensionJSPath.append("/appshell_extensions.js"); - FILE* file = fopen(extensionJSPath.c_str(),"r"); - if(file == NULL) - { - return ""; - } + //# We objcopy the appshell/appshell_extensions.js file, and link it directly into the binary. + //# See http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967 + const char* p = &_binary_appshell_appshell_extensions_js_start; + std:: string content(p); + // std:: string extensionJSPath(AppGetSupportDirectory()); + // extensionJSPath.append("/appshell_extensions.js"); + // FILE* file = fopen(extensionJSPath.c_str(),"r"); + // if(file == NULL) + // { + // return ""; + // } - fseek(file, 0, SEEK_END); - long int size = ftell(file); - rewind(file); + // fseek(file, 0, SEEK_END); + // long int size = ftell(file); + // rewind(file); - char* content = (char*)calloc(size + 1, 1); + // char* content = (char*)calloc(size + 1, 1); - fread(content,1,size,file); + // fread(content,1,size,file); return content; } diff --git a/appshell_paths.gypi b/appshell_paths.gypi index 2a5e37f6e..7b076c76a 100755 --- a/appshell_paths.gypi +++ b/appshell_paths.gypi @@ -156,5 +156,8 @@ 'appshell_bundle_resources_linux': [ '$(BUILDTYPE)/locales', ], + 'appshell_bundle_libraries_linux': [ + '$(BUILDTYPE)/lib.target/libcef.so', + ], }, }