environment: move more init stuff here from main.js
Move some more environment-initializationy stuff from main.js to environment.js, and be more careful about not importing shell JS modules until after the environment has been fully patched. Change gnome-shell-plugin to call Environment.init() before Main.start(); this means that Environment.init() now runs before any shell JS modules (besides environment itself) have been imported. Make run-js-test create a ShellGlobal and use its js_context, so that the shell_global_set_property_mutable() stuff in Environment.init() will work correctly in tests as well. https://bugzilla.gnome.org/show_bug.cgi?id=649203
This commit is contained in:
parent
0e42de9149
commit
7921954a31
@ -1,14 +1,21 @@
|
|||||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
|
imports.gi.versions.Clutter = '1.0';
|
||||||
|
imports.gi.versions.Gio = '2.0';
|
||||||
|
imports.gi.versions.Gdk = '3.0';
|
||||||
|
imports.gi.versions.GdkPixbuf = '2.0';
|
||||||
|
imports.gi.versions.Gtk = '3.0';
|
||||||
|
|
||||||
const Clutter = imports.gi.Clutter;;
|
const Clutter = imports.gi.Clutter;;
|
||||||
const GLib = imports.gi.GLib;
|
const GLib = imports.gi.GLib;
|
||||||
|
const Gtk = imports.gi.Gtk;
|
||||||
const Shell = imports.gi.Shell;
|
const Shell = imports.gi.Shell;
|
||||||
const St = imports.gi.St;
|
const St = imports.gi.St;
|
||||||
const Gettext_gtk30 = imports.gettext.domain('gtk30');
|
|
||||||
|
|
||||||
const Tweener = imports.ui.tweener;
|
// We can't import shell JS modules yet, because they may have
|
||||||
|
// variable initializations, etc, that depend on init() already having
|
||||||
|
// been run.
|
||||||
|
|
||||||
const Format = imports.misc.format;
|
|
||||||
|
|
||||||
// "monkey patch" in some varargs ClutterContainer methods; we need
|
// "monkey patch" in some varargs ClutterContainer methods; we need
|
||||||
// to do this per-container class since there is no representation
|
// to do this per-container class since there is no representation
|
||||||
@ -61,26 +68,16 @@ function _blockMethod(method, replacement, reason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
Tweener.init();
|
// Add some bindings to the global JS namespace; (gjs keeps the web
|
||||||
String.prototype.format = Format.format;
|
// browser convention of having that namespace be called 'window'.)
|
||||||
|
window.global = Shell.Global.get();
|
||||||
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783
|
|
||||||
Date.prototype.toLocaleFormat = function(format) {
|
|
||||||
return Shell.util_format_date(format, this.getTime());
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set the default direction for St widgets (this needs to be done before any use of St)
|
// Set the default direction for St widgets (this needs to be done before any use of St)
|
||||||
if (Gettext_gtk30.gettext('default:LTR') == 'default:RTL') {
|
if (Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL) {
|
||||||
St.Widget.set_default_direction(St.TextDirection.RTL);
|
St.Widget.set_default_direction(St.TextDirection.RTL);
|
||||||
}
|
}
|
||||||
|
|
||||||
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
// Miscellaneous monkeypatching
|
||||||
if (slowdownEnv) {
|
|
||||||
let factor = parseFloat(slowdownEnv);
|
|
||||||
if (!isNaN(factor) && factor > 0.0)
|
|
||||||
St.set_slow_down_factor(factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
_patchContainerClass(St.BoxLayout);
|
_patchContainerClass(St.BoxLayout);
|
||||||
_patchContainerClass(St.Table);
|
_patchContainerClass(St.Table);
|
||||||
|
|
||||||
@ -97,9 +94,6 @@ function init() {
|
|||||||
return base;
|
return base;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.global === undefined) // test environment
|
|
||||||
return;
|
|
||||||
|
|
||||||
_blockMethod('Clutter.Event.get_state', 'Shell.get_event_state',
|
_blockMethod('Clutter.Event.get_state', 'Shell.get_event_state',
|
||||||
'gjs\'s handling of Clutter.ModifierType is broken. See bug 597292.');
|
'gjs\'s handling of Clutter.ModifierType is broken. See bug 597292.');
|
||||||
_blockMethod('Gdk.Window.get_device_position', 'global.get_pointer',
|
_blockMethod('Gdk.Window.get_device_position', 'global.get_pointer',
|
||||||
@ -110,4 +104,23 @@ function init() {
|
|||||||
// Shell.Global.prototype itself is read-only.
|
// Shell.Global.prototype itself is read-only.
|
||||||
global.set_property_mutable('imports.gi.Shell.Global.prototype', 'set_property_mutable', true);
|
global.set_property_mutable('imports.gi.Shell.Global.prototype', 'set_property_mutable', true);
|
||||||
Shell.Global.prototype.set_property_mutable = undefined;
|
Shell.Global.prototype.set_property_mutable = undefined;
|
||||||
|
|
||||||
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783
|
||||||
|
Date.prototype.toLocaleFormat = function(format) {
|
||||||
|
return Shell.util_format_date(format, this.getTime());
|
||||||
|
};
|
||||||
|
|
||||||
|
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
||||||
|
if (slowdownEnv) {
|
||||||
|
let factor = parseFloat(slowdownEnv);
|
||||||
|
if (!isNaN(factor) && factor > 0.0)
|
||||||
|
St.set_slow_down_factor(factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OK, now things are initialized enough that we can import shell JS
|
||||||
|
const Format = imports.misc.format;
|
||||||
|
const Tweener = imports.ui.tweener;
|
||||||
|
|
||||||
|
Tweener.init();
|
||||||
|
String.prototype.format = Format.format;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
imports.gi.versions.Clutter = '1.0';
|
|
||||||
imports.gi.versions.Gio = '2.0';
|
|
||||||
imports.gi.versions.Gdk = '3.0';
|
|
||||||
imports.gi.versions.GdkPixbuf = '2.0';
|
|
||||||
imports.gi.versions.Gtk = '3.0';
|
|
||||||
|
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
const DBus = imports.dbus;
|
const DBus = imports.dbus;
|
||||||
const Gdk = imports.gi.Gdk;
|
const Gdk = imports.gi.Gdk;
|
||||||
@ -75,12 +69,7 @@ let _cssStylesheet = null;
|
|||||||
let background = null;
|
let background = null;
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
// Add a binding for 'global' in the global JS namespace; (gjs
|
// Monkey patch utility functions into the global proxy;
|
||||||
// keeps the web browser convention of having that namespace be
|
|
||||||
// called 'window'.)
|
|
||||||
window.global = Shell.Global.get();
|
|
||||||
|
|
||||||
// Now monkey patch utility functions into the global proxy;
|
|
||||||
// This is easier and faster than indirecting down into global
|
// This is easier and faster than indirecting down into global
|
||||||
// if we want to call back up into JS.
|
// if we want to call back up into JS.
|
||||||
global.logError = _logError;
|
global.logError = _logError;
|
||||||
@ -102,8 +91,6 @@ function start() {
|
|||||||
// not loading any events until the user presses the clock
|
// not loading any events until the user presses the clock
|
||||||
global.launch_calendar_server();
|
global.launch_calendar_server();
|
||||||
|
|
||||||
Environment.init();
|
|
||||||
|
|
||||||
// Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
|
// Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
|
||||||
// also initialize ShellAppSystem first. ShellAppSystem
|
// also initialize ShellAppSystem first. ShellAppSystem
|
||||||
// needs to load all the .desktop files, and ShellWindowTracker
|
// needs to load all the .desktop files, and ShellWindowTracker
|
||||||
|
@ -178,7 +178,8 @@ gnome_shell_plugin_start (MetaPlugin *plugin)
|
|||||||
gjs_context = _shell_global_get_gjs_context (shell_plugin->global);
|
gjs_context = _shell_global_get_gjs_context (shell_plugin->global);
|
||||||
|
|
||||||
if (!gjs_context_eval (gjs_context,
|
if (!gjs_context_eval (gjs_context,
|
||||||
"const Main = imports.ui.main; Main.start();",
|
"imports.ui.environment.init();"
|
||||||
|
"imports.ui.main.start();",
|
||||||
-1,
|
-1,
|
||||||
"<main>",
|
"<main>",
|
||||||
&status,
|
&status,
|
||||||
|
@ -24,15 +24,19 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <gdk/gdkx.h>
|
|
||||||
#include <clutter/x11/clutter-x11.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <clutter/x11/clutter-x11.h>
|
||||||
|
#include <gdk/gdkx.h>
|
||||||
#include <gjs/gjs.h>
|
#include <gjs/gjs.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "shell-global.h"
|
||||||
|
#include "shell-global-private.h"
|
||||||
|
|
||||||
static char **include_path = NULL;
|
static char **include_path = NULL;
|
||||||
static char *command = NULL;
|
static char *command = NULL;
|
||||||
@ -59,10 +63,10 @@ event_filter (GdkXEvent *xevent,
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *command_line;
|
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
ClutterActor *stage;
|
ClutterActor *stage;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
ShellGlobal *global;
|
||||||
GjsContext *js_context;
|
GjsContext *js_context;
|
||||||
char *script;
|
char *script;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
@ -94,12 +98,8 @@ main(int argc, char **argv)
|
|||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
command_line = g_strjoinv (" ", argv);
|
global = shell_global_get ();
|
||||||
g_debug ("Command line: %s", command_line);
|
js_context = _shell_global_get_gjs_context (global);
|
||||||
g_free (command_line);
|
|
||||||
|
|
||||||
g_debug ("Creating new context to eval console script");
|
|
||||||
js_context = gjs_context_new_with_search_path (include_path);
|
|
||||||
|
|
||||||
/* prepare command line arguments */
|
/* prepare command line arguments */
|
||||||
if (!gjs_context_define_string_array (js_context, "ARGV",
|
if (!gjs_context_define_string_array (js_context, "ARGV",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user