Recognize different instances for different config dirs
If Midori is built with support for multiple instances and a config folder is specified a new instance bound to that folder is created. The new "name" property in MidoriApp implements this.
This commit is contained in:
parent
ddf2f60e3f
commit
07aed45bd9
2 changed files with 82 additions and 31 deletions
|
@ -1412,14 +1412,6 @@ main (int argc,
|
||||||
if (run)
|
if (run)
|
||||||
return midori_run_script (uris ? *uris : NULL);
|
return midori_run_script (uris ? *uris : NULL);
|
||||||
|
|
||||||
if (config && !g_path_is_absolute (config))
|
|
||||||
{
|
|
||||||
g_critical (_("The specified configuration folder is invalid."));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
sokoke_set_config_dir (config);
|
|
||||||
g_free (config);
|
|
||||||
|
|
||||||
#if HAVE_HILDON
|
#if HAVE_HILDON
|
||||||
osso_context = osso_initialize (PACKAGE_NAME, PACKAGE_VERSION, FALSE, NULL);
|
osso_context = osso_initialize (PACKAGE_NAME, PACKAGE_VERSION, FALSE, NULL);
|
||||||
|
|
||||||
|
@ -1430,7 +1422,26 @@ main (int argc,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
app = midori_app_new ();
|
if (config && !g_path_is_absolute (config))
|
||||||
|
{
|
||||||
|
g_critical (_("The specified configuration folder is invalid."));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
sokoke_set_config_dir (config);
|
||||||
|
if (config)
|
||||||
|
{
|
||||||
|
gchar* name_hash;
|
||||||
|
gchar* app_name;
|
||||||
|
name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
|
||||||
|
app_name = g_strconcat ("midori", "_", name_hash, NULL);
|
||||||
|
g_free (name_hash);
|
||||||
|
app = g_object_new (MIDORI_TYPE_APP, "name", app_name, NULL);
|
||||||
|
g_free (app_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
app = midori_app_new ();
|
||||||
|
g_free (config);
|
||||||
|
|
||||||
/* FIXME: The app might be 'running' but actually showing a dialog
|
/* FIXME: The app might be 'running' but actually showing a dialog
|
||||||
after a crash, so running a new window isn't a good idea. */
|
after a crash, so running a new window isn't a good idea. */
|
||||||
if (midori_app_instance_is_running (app))
|
if (midori_app_instance_is_running (app))
|
||||||
|
|
|
@ -30,6 +30,7 @@ struct _MidoriApp
|
||||||
MidoriBrowser* browser;
|
MidoriBrowser* browser;
|
||||||
GtkAccelGroup* accel_group;
|
GtkAccelGroup* accel_group;
|
||||||
|
|
||||||
|
gchar* name;
|
||||||
MidoriWebSettings* settings;
|
MidoriWebSettings* settings;
|
||||||
KatzeArray* bookmarks;
|
KatzeArray* bookmarks;
|
||||||
KatzeArray* trash;
|
KatzeArray* trash;
|
||||||
|
@ -59,6 +60,7 @@ enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
|
||||||
|
PROP_NAME,
|
||||||
PROP_SETTINGS,
|
PROP_SETTINGS,
|
||||||
PROP_BOOKMARKS,
|
PROP_BOOKMARKS,
|
||||||
PROP_TRASH,
|
PROP_TRASH,
|
||||||
|
@ -206,6 +208,23 @@ midori_app_class_init (MidoriAppClass* class)
|
||||||
class->add_browser = _midori_app_add_browser;
|
class->add_browser = _midori_app_add_browser;
|
||||||
class->quit = _midori_app_quit;
|
class->quit = _midori_app_quit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MidoriApp:name:
|
||||||
|
*
|
||||||
|
* The name of the instance.
|
||||||
|
*
|
||||||
|
* Since: 0.1.6
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_NAME,
|
||||||
|
g_param_spec_string (
|
||||||
|
"name",
|
||||||
|
"Name",
|
||||||
|
"The name of the instance",
|
||||||
|
"midori",
|
||||||
|
G_PARAM_CONSTRUCT_ONLY |
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_SETTINGS,
|
PROP_SETTINGS,
|
||||||
g_param_spec_object (
|
g_param_spec_object (
|
||||||
|
@ -389,16 +408,45 @@ midori_browser_message_received_cb (UniqueApp* instance,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static gpointer
|
||||||
midori_app_init (MidoriApp* app)
|
midori_app_create_instance (MidoriApp* app,
|
||||||
|
const gchar* name)
|
||||||
{
|
{
|
||||||
#if HAVE_UNIQUE
|
#if HAVE_UNIQUE
|
||||||
|
gpointer instance;
|
||||||
GdkDisplay* display;
|
GdkDisplay* display;
|
||||||
gchar* display_name;
|
gchar* display_name;
|
||||||
gchar* instance_name;
|
gchar* instance_name;
|
||||||
guint i, n;
|
guint i, n;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
name = "midori";
|
||||||
|
|
||||||
|
#if HAVE_UNIQUE
|
||||||
|
if (!(display = gdk_display_get_default ()))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
display_name = g_strdup (gdk_display_get_name (display));
|
||||||
|
n = strlen (display_name);
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
if (display_name[i] == ':' || display_name[i] == '.')
|
||||||
|
display_name[i] = '_';
|
||||||
|
instance_name = g_strdup_printf ("de.twotoasts.%s_%s", name, display_name);
|
||||||
|
instance = unique_app_new (instance_name, NULL);
|
||||||
|
g_free (instance_name);
|
||||||
|
g_free (display_name);
|
||||||
|
g_signal_connect (instance, "message-received",
|
||||||
|
G_CALLBACK (midori_browser_message_received_cb), app);
|
||||||
|
return instance;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_init (MidoriApp* app)
|
||||||
|
{
|
||||||
app->accel_group = gtk_accel_group_new ();
|
app->accel_group = gtk_accel_group_new ();
|
||||||
|
|
||||||
app->settings = NULL;
|
app->settings = NULL;
|
||||||
|
@ -409,27 +457,7 @@ midori_app_init (MidoriApp* app)
|
||||||
app->extensions = NULL;
|
app->extensions = NULL;
|
||||||
app->browsers = katze_array_new (MIDORI_TYPE_BROWSER);
|
app->browsers = katze_array_new (MIDORI_TYPE_BROWSER);
|
||||||
|
|
||||||
#if HAVE_UNIQUE
|
|
||||||
if (!(display = gdk_display_get_default ()))
|
|
||||||
{
|
|
||||||
app->instance = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
display_name = g_strdup (gdk_display_get_name (display));
|
|
||||||
n = strlen (display_name);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
if (display_name[i] == ':' || display_name[i] == '.')
|
|
||||||
display_name[i] = '_';
|
|
||||||
instance_name = g_strdup_printf ("de.twotoasts.midori_%s", display_name);
|
|
||||||
app->instance = unique_app_new (instance_name, NULL);
|
|
||||||
g_free (instance_name);
|
|
||||||
g_free (display_name);
|
|
||||||
g_signal_connect (app->instance, "message-received",
|
|
||||||
G_CALLBACK (midori_browser_message_received_cb), app);
|
|
||||||
#else
|
|
||||||
app->instance = NULL;
|
app->instance = NULL;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -439,6 +467,7 @@ midori_app_finalize (GObject* object)
|
||||||
|
|
||||||
g_object_unref (app->accel_group);
|
g_object_unref (app->accel_group);
|
||||||
|
|
||||||
|
katze_assign (app->name, NULL);
|
||||||
katze_object_assign (app->settings, NULL);
|
katze_object_assign (app->settings, NULL);
|
||||||
katze_object_assign (app->bookmarks, NULL);
|
katze_object_assign (app->bookmarks, NULL);
|
||||||
katze_object_assign (app->trash, NULL);
|
katze_object_assign (app->trash, NULL);
|
||||||
|
@ -462,6 +491,9 @@ midori_app_set_property (GObject* object,
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
katze_assign (app->name, g_value_dup_string (value));
|
||||||
|
break;
|
||||||
case PROP_SETTINGS:
|
case PROP_SETTINGS:
|
||||||
katze_object_assign (app->settings, g_value_dup_object (value));
|
katze_object_assign (app->settings, g_value_dup_object (value));
|
||||||
/* FIXME: Propagate settings to all browsers */
|
/* FIXME: Propagate settings to all browsers */
|
||||||
|
@ -501,6 +533,9 @@ midori_app_get_property (GObject* object,
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
g_value_set_string (value, app->name);
|
||||||
|
break;
|
||||||
case PROP_SETTINGS:
|
case PROP_SETTINGS:
|
||||||
g_value_set_object (value, app->settings);
|
g_value_set_object (value, app->settings);
|
||||||
break;
|
break;
|
||||||
|
@ -559,6 +594,9 @@ midori_app_new (void)
|
||||||
* Determines whether an instance of Midori is
|
* Determines whether an instance of Midori is
|
||||||
* already running on the default display.
|
* already running on the default display.
|
||||||
*
|
*
|
||||||
|
* Use the "name" property if you want to run more
|
||||||
|
* than one instance.
|
||||||
|
*
|
||||||
* If Midori was built without single instance support
|
* If Midori was built without single instance support
|
||||||
* this function will always return %FALSE.
|
* this function will always return %FALSE.
|
||||||
*
|
*
|
||||||
|
@ -570,6 +608,8 @@ midori_app_instance_is_running (MidoriApp* app)
|
||||||
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
||||||
|
|
||||||
#if HAVE_UNIQUE
|
#if HAVE_UNIQUE
|
||||||
|
if (!app->instance)
|
||||||
|
app->instance = midori_app_create_instance (app, app->name);
|
||||||
if (app->instance)
|
if (app->instance)
|
||||||
return unique_app_is_running (app->instance);
|
return unique_app_is_running (app->instance);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue