示例#1
0
int
start_seafile_daemon ()
{
    applet_message ("Starting seaf-daemon ...\n");
    applet_message ("data dir:      %s\n", applet->seafile_dir);
    applet_message ("worktree dir:  %s\n", applet->seafile_worktree);

    char buf[4096];

    char *locale_config_dir = ccnet_locale_from_utf8(applet->config_dir);
    char *locale_seafile_dir = ccnet_locale_from_utf8(applet->seafile_dir);
    char *locale_seafile_worktree = ccnet_locale_from_utf8(applet->seafile_worktree);

    snprintf (buf, sizeof(buf), "seaf-daemon.exe -c \"%s\" -d \"%s\" -w \"%s\"",
              locale_config_dir, locale_seafile_dir, locale_seafile_worktree);

    g_free (locale_config_dir);
    g_free (locale_seafile_dir);
    g_free (locale_seafile_worktree);
    
    if (win32_spawn_process (buf, NULL) < 0) {
        applet_warning ("Failed to start seaf-daemon\n");
        applet_exit(-1);
    }

    return 0;
}
示例#2
0
static void
init_ccnet ()
{
    char *config_dir = applet->config_dir;
    char *config_file;
    
    config_file = g_build_filename (config_dir,
                                    SESSION_CONFIG_FILENAME, NULL);
    
    if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR)
        || !g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) {
        
        if (create_new() < 0) {
            applet_exit(-1);
        }
    }

    applet_log_init(config_dir);
    
    applet_message ("Load config dir %s success\n", config_dir);
    applet_message ("starting seafile-applet "PACKAGE_VERSION"\n");
    g_setenv("CCNET_CONF_DIR", config_dir, 1);
    
    g_free (config_file);
}
示例#3
0
int
main (int argc, char **argv)
{
    /* init i18n */
    setlocale (LC_ALL, "");
    bindtextdomain(GETTEXT_PACKAGE, SEAFILE_LOCALE_DIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);

    if (count_process("seafile-applet") > 1) {
        fprintf(stderr, _("Seafile is already running\n"));
        exit(1);
    }

    gtk_init (&argc, &argv);
    gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
                                       PKGDATADIR);
    gtk_window_set_default_icon_name ("seafile");

    signal (SIGINT, sigint_handler);

    applet = g_new0 (SeafileApplet, 1);
    seafile_applet_init (applet);
    seafile_applet_start (argc, argv);

    applet_message ("seafile started\n");

    trayicon_set_tip ("Seafile");

    gtk_main ();

    return 0;
}
示例#4
0
void
start_heartbeat_monitor_timer (int timeout_ms, void *data)
{
    applet_message ("[hearbeat mon] started.\n");
    applet->heartbeat_monitor_on = TRUE;
    g_timeout_add (timeout_ms, heartbeat_monitor, NULL);
}
示例#5
0
void
start_heartbeat_monitor_timer (int timeout_ms, void *data)
{
    applet_message ("[heartbeat mon] started.\n");
    applet->heartbeat_monitor_on = TRUE;
    SetTimer (NULL, HEARTBEAT_MONITOR_TIMER_ID, timeout_ms,
              heartbeat_monitor_wrapper);
}
示例#6
0
static LRESULT CALLBACK
WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    SeafileTrayIcon *icon = applet->icon;
    if (!icon)
        return DefWindowProc (hWnd, message, wParam, lParam);

    switch(message) {
    case WM_CLOSE:
        applet_message ("WM_CLOSE received, now exit\n");
        applet_exit(0);
        break;

    case WM_TRAYNOTIFY:
        if(wParam != icon->nid.uID)
            return S_FALSE;
        return tray_notify_cb(message, wParam, lParam);
        break;

    case WM_COMMAND:
        return tray_command_cb(message, wParam, lParam);
        break;

    case WM_SOCKET:
        return tray_socket_cb(message, wParam, lParam);
        break;

    default:
        if (message == applet->WM_TASKBARCREATED) {
            /* Restore applet trayicon when taskbar is re-created. This normally
             * happens when explorer is restarted.
             */
            applet_message ("WM_TASKBARCREATED received\n");
            trayicon_init (applet->icon);
        }
        break;
    }


    return DefWindowProc (hWnd, message, wParam, lParam);
}
示例#7
0
static void CALLBACK
TestWebServer (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
    if (test_web_server()) {
        KillTimer(hwnd, iTimerID);

        applet_message ("Web server is up.\n");

        applet->web_status = WEB_READY;
        trayicon_notify (_("Seafile is started"), _("Click the icon to open admin console"));
    }
}
示例#8
0
int start_web_server ()
{
    applet_message ("Starting web ...\n");

    if (spawn_process("seafile-web start") < 0) {
        applet_warning ("Failed to start seafile web\n");
        applet_exit(-1);
    }

    applet->web_status = WEB_STARTED;

    return 0;
}
示例#9
0
static void
start_ccnet ()
{
    applet_message ("Starting ccnet ...\n");

    if ((ccnet_client_load_confdir(applet->client, applet->config_dir)) < 0 ) {
        applet_warning("Read config dir error\n");
        applet_exit (1);
    }

    if ((ccnet_client_load_confdir(applet->sync_client, applet->config_dir)) < 0 ) {
        applet_warning("Read config dir error\n");
        applet_exit (1);
    }

    if (spawn_ccnet_daemon () < 0) {
        applet_warning ("Failed to start ccnet\n");;
        applet_exit (1);
    }

    applet_message ("ccnet daemon started\n");
}
示例#10
0
gboolean
test_web_server (void)
{
    applet_message ("[web] testing web server ... \n");

    evutil_socket_t test_sockfd = socket (AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in servaddr;

    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(13420);
    inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr);

    int ret = connect (test_sockfd, (struct sockaddr *)&servaddr,
                       sizeof(servaddr));
    evutil_closesocket(test_sockfd) ;

    if (ret == 0) {
        applet_message ("web server now ready\n");
    }
    return (ret == 0) ;
}
示例#11
0
int
start_web_server ()
{
    applet_message ("Starting web ...\n");

    if (win32_spawn_process(STARTWEBSERVER, NULL) < 0) {
        applet_warning ("Failed to start seafile web\n");
        applet_exit(-1);
    }

    applet->web_status = WEB_STARTED;
    return 0;
}
示例#12
0
/* Kill ccnet/seaf/web, and restart them. */
void restart_all (void)
{
    trayicon_set_tip ("Seafile");
    
    applet_message ("Restarting ccnet ...\n");
    stop_open_browser_timer();
    stop_web_server();
    
    if (applet->client->connected) {
        stop_ccnet();
    }
    
    spawn_ccnet_daemon();
    
    start_conn_daemon_timer (1000, NULL);
}
示例#13
0
static void CALLBACK
trayicon_init_retry (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
    if (trayicon_init_retried++ >= 3) {
        applet_exit(1);
    }

    if (_trayicon_init(applet->icon)) {
        applet_message ("trayicon inited succesfully in retry\n");
        KillTimer (hwnd, iTimerID);
    } else {
        applet_warning ("trayicon init failed, retry = %d, GLE=%lu\n",
                        trayicon_init_retried,
                        GetLastError());
    }
}
示例#14
0
gboolean
connect_to_server (gpointer data)
{
    if (connect_to_daemon() < 0) {
        return TRUE;
    }

    applet_message ("Connected to ccnet.\n");

    start_seafile_daemon ();
    applet->auto_sync_disabled = FALSE;
    start_heartbeat_monitor();
    start_web_server();

    start_open_browser_timer (1000, NULL);

    return FALSE;
}
示例#15
0
/*
 *  After spawning the ccnet.exe process;
 *  
 *  1. Connect to daemon
 *  2. spawn seaf-daemon, sefile-web
 *  3. start rpc server & rpc client
 *  4. prompt login, if not finished yet
 *  5. open browser when 13420 port can be connected
 */
static void CALLBACK
ConnDaemonProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
    if (connect_to_daemon() < 0) {
        return;
    }
    applet_message ("Connected to ccnet.\n");

    KillTimer (hwnd, iTimerID);

    start_seafile_daemon ();
    start_heartbeat_monitor ();
    start_web_server ();

    prompt_win7_tip_if_necessary ();

    open_browser_timer_id = SetTimer (NULL, OPEN_BROWSER_TIMER_ID,
                                      1000, TestWebServer);
}
示例#16
0
int
start_seafile_daemon ()
{
    GString *buf = g_string_new (NULL);

    applet_message ("Starting seafile ...\n");
    
    g_string_append_printf (buf, 
        "seaf-daemon -c \"%s\" -d \"%s\" -w \"%s\"",
        applet->config_dir, applet->seafile_dir, applet->seafile_worktree);
    
    if (spawn_process (buf->str) < 0) {
        applet_warning ("Failed to start seaf-daemon\n");
        applet_exit(-1);
    }

    g_string_free (buf, TRUE);
    return 0;
}
示例#17
0
gboolean
on_open_browser_timeout(void)
{
    /* only start the browser after we can successfully connect the
     web server port
     */
    if (test_web_server ()) {
        applet_message ("[web] web server ready, now start browser \n");
        applet->web_status = WEB_READY;

        if (first_use) {
            open_web_browser(SEAF_HTTP_ADDR);
        }

        return FALSE;
    } else {
        //applet_message ("[web] web server not ready, wait for a moment\n");
        return TRUE;
    }
}
示例#18
0
int
connect_to_daemon (void)
{
    applet_message ("connecting ccnet ...\n");

    CcnetClient *client = applet->client;
    CcnetClient *sync_client = applet->sync_client;
    
    if (client->connected && sync_client->connected) {
        return 0;
    }

    if (!client->connected) {
        if (ccnet_client_connect_daemon (client, CCNET_CLIENT_ASYNC) < 0) {
            applet_warning("connect to ccnet daemon fail: %s\n", strerror(errno));
            trayicon_set_ccnet_state (CCNET_STATE_DOWN);
            return -1;
        }
    }

    if (!sync_client->connected) {
        if (ccnet_client_connect_daemon (sync_client, CCNET_CLIENT_SYNC) < 0) {
            applet_warning ("sync_client: connect to ccnet daemon failed: %s\n",
                            strerror(errno));
            applet_exit(1);
        }
    }

    trayicon_set_ccnet_state (CCNET_STATE_UP);
    
    add_client_fd_to_mainloop ();

    applet_init_ccnet_rpc (sync_client);
    applet_init_seafile_rpc (client);

    applet_start_rpc_service(client);
    start_mq_client ();

    return 0;
}
示例#19
0
gboolean heartbeat_monitor (void *data)
{
    if (!applet->heartbeat_monitor_on)
        return FALSE;

    time_t now = time(NULL);

    if (applet->last_heartbeat == 0) {
        applet->last_heartbeat = now;
        return TRUE;
     } else if (now - applet->last_heartbeat > 3 * HEARTBEAT_INTERVAL) {
        /* hearbeat not received */
        if (is_seafile_daemon_running()) {
            return TRUE;
        } else {
            applet_message ("[heartbeat mon] seaf-daemon is down, "
                            "now bring it up..\n");
            applet->auto_sync_disabled = FALSE;
            start_seafile_daemon();
        }
     }
    return TRUE;
}
示例#20
0
void start_heartbeat_monitor (void)
{
    applet_message ("[hearbeat mon] started.\n");
    applet->heartbeat_monitor_on = TRUE;
    start_heartbeat_monitor_timer (2000, NULL);
}
示例#21
0
void stop_heartbeat_monitor (void)
{
    applet_message ("[hearbeat mon] stopped.\n");
    applet->heartbeat_monitor_on = FALSE;
}