Support opening file specified as argument

Moves build to out/ folder and use shell script
to bootstrap loading of libraries
This commit is contained in:
Kevin Sawicki
2012-06-06 11:38:38 -07:00
parent 793140cf47
commit 22ab010d10
6 changed files with 110 additions and 67 deletions

View File

@@ -1,3 +1,3 @@
out/
*.o
atom
console.log

View File

@@ -39,8 +39,6 @@ LDFLAGS := -pthread \
-Wl,-O1 \
-Wl,--as-needed \
-Wl,--gc-sections \
-Wl,-rpath=lib/ \
-Wl,-rpath-link=lib/
LIBS := -lX11 \
-lgtk-x11-2.0 \
@@ -68,7 +66,10 @@ OBJECTS=$(SOURCES:.cpp=.o)
all:
g++ $(CXXFLAGS) -c $(SOURCES)
g++ -o atom $(OBJECTS) $(LDFLAGS) $(LIBS)
mkdir -p out
cp chrome.pak out/
cp -R locales out/
g++ -o out/atom $(OBJECTS) $(LDFLAGS) $(LIBS)
clean:
rm -rf *.o atom
rm -rf out

11
Atom-Linux/atom Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
case $0 in
/* )
root=${0%atom}
;;
* )
root=`pwd`/${0%atom}
;;
esac
export LD_LIBRARY_PATH=$root'lib':$LD_LIBRARY_PATH
$root'out/atom' $@

View File

@@ -4,6 +4,7 @@
#include <gtk/gtk.h>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
#include <string>
#include "cefclient.h"
@@ -13,101 +14,127 @@
#include "include/cef_runnable.h"
#include "client_handler.h"
char szWorkingDir[512]; // The current working directory
char szWorkingDir[512]; // The current working directory
const char* szPath; // The folder the application is in
const char* szPathToOpen; // The file to open
// The global ClientHandler reference.
extern CefRefPtr<ClientHandler> g_handler;
void destroy(void) {
CefQuitMessageLoop();
CefQuitMessageLoop();
}
void TerminationSignalHandler(int signatl) {
destroy();
destroy();
}
// WebViewDelegate::TakeFocus in the test webview delegate.
static gboolean HandleFocus(GtkWidget* widget,
GdkEventFocus* focus) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
// Give focus to the browser window.
g_handler->GetBrowser()->SetFocus(true);
}
static gboolean HandleFocus(GtkWidget* widget, GdkEventFocus* focus) {
if (g_handler.get() && g_handler->GetBrowserHwnd()) {
// Give focus to the browser window.
g_handler->GetBrowser()->SetFocus(true);
}
return TRUE;
return TRUE;
}
int main(int argc, char *argv[]) {
if (!getcwd(szWorkingDir, sizeof (szWorkingDir)))
return -1;
if (!getcwd(szWorkingDir, sizeof(szWorkingDir)))
return -1;
GtkWidget* window;
std::string fullPath = argv[0];
fullPath = fullPath.substr(0, fullPath.length() - 5);
szPath = fullPath.c_str();
gtk_init(&argc, &argv);
std::string pathToOpen;
if (argc >= 2) {
if (argv[1][0] != '/') {
pathToOpen.append(szWorkingDir);
pathToOpen.append("/");
pathToOpen.append(argv[1]);
} else
szPathToOpen = argv[1];
} else
pathToOpen.append(szWorkingDir);
szPathToOpen = pathToOpen.c_str();
CefSettings settings;
CefRefPtr<CefApp> app;
GtkWidget* window;
// Initialize CEF.
CefInitialize(settings, app);
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Atom");
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
CefSettings settings;
CefRefPtr<CefApp> app;
g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL);
// Initialize CEF.
CefInitialize(settings, app);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Atom");
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
gtk_box_pack_start(GTK_BOX(vbox), NULL, FALSE, FALSE, 0);
g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_widget_destroyed), &window);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(destroy), NULL);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
// Create the handler.
g_handler = new ClientHandler();
g_handler->SetMainHwnd(vbox);
gtk_box_pack_start(GTK_BOX(vbox), NULL, FALSE, FALSE, 0);
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings browserSettings;
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_widget_destroyed), &window);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
window_info.SetAsChild(vbox);
std::string path;
path.append("file://");
path.append(szWorkingDir);
path.append("/../index.html");
// Create the handler.
g_handler = new ClientHandler();
g_handler->SetMainHwnd(vbox);
CefBrowser::CreateBrowserSync(window_info,
static_cast<CefRefPtr<CefClient> >(g_handler),
path, browserSettings);
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings browserSettings;
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(GTK_WIDGET(window));
window_info.SetAsChild(vbox);
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_file("atom.ico", &error);
if (pixbuf)
gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
std::string path;
path.append("file://");
path.append(szPath);
path.append("/../../index.html");
// Install an signal handler so we clean up after ourselves.
signal(SIGINT, TerminationSignalHandler);
signal(SIGTERM, TerminationSignalHandler);
CefBrowser::CreateBrowserSync(window_info,
static_cast<CefRefPtr<CefClient> >(g_handler), path,
browserSettings);
CefRunMessageLoop();
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(GTK_WIDGET(window));
CefShutdown();
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_file("atom.ico", &error);
if (pixbuf)
gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
return 0;
// Install an signal handler so we clean up after ourselves.
signal(SIGINT, TerminationSignalHandler);
signal(SIGTERM, TerminationSignalHandler);
CefRunMessageLoop();
CefShutdown();
return 0;
}
// Global functions
std::string AppGetWorkingDirectory() {
return szWorkingDir;
return szWorkingDir;
}
std::string AppPath() {
return szPath;
}
std::string PathToOpen() {
return szPathToOpen;
}

View File

@@ -22,6 +22,12 @@ CefWindowHandle AppGetMainHwnd();
// Returns the application working directory.
std::string AppGetWorkingDirectory();
// Returns the application's path.
std::string AppPath();
// Returns the initial path to open.
std::string PathToOpen();
// Initialize the application command line.
void AppInitCommandLine(int argc, const char* const* argv);

View File

@@ -85,10 +85,8 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
std::string path;
if (m_nativeHandler)
path = m_nativeHandler->path;
else {
path.append(AppGetWorkingDirectory());
path.append("/../src/app/atom.coffee");
}
else
path.append(PathToOpen());
CefRefPtr<CefV8Value> pathToOpen = CefV8Value::CreateString(path);
global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE);
@@ -102,7 +100,7 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefV8Value> atom = CefV8Value::CreateObject(NULL, NULL);
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(AppGetWorkingDirectory() + "/..");
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(AppPath() + "/../..");
atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> bootstrapScript = CefV8Value::CreateString("window-bootstrap");