void Runtime::runMainScript() { v8::HandleScope scope(v8::Isolate::GetCurrent()); v8::Handle<v8::Context> context = v8::Context::New( v8::Isolate::GetCurrent()); v8::Context::Scope contextScope(context); m_sip = new JsSIPObject(m_sipFactory); m_sip->createObjectInstance(context->Global(), "sip"); v8::TryCatch tryCatch; std::string mainScript; loadMainScript(mainScript); v8::Handle<v8::Script> script = v8::Script::Compile( v8::String::New(mainScript.c_str()), v8::String::New(m_scriptFileName.c_str())); if (script.IsEmpty()) { throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str()); } v8::Handle<v8::Value> result = script->Run(); if (result.IsEmpty()) { // TODO: add log v8::String::Utf8Value stackTrace(tryCatch.StackTrace()); if (stackTrace.length() > 0) { throw Exception(*stackTrace); } throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str()); } }
DlgJsRoboKey::DlgJsRoboKey(QWidget *parent) : QDialog(parent, Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), ui(new Ui::DlgJsRoboKey), m_pjsrobokey(NULL), m_jsengine(NULL), m_mainScriptLoaded(false) { ui->setupUi(this); ui->memoInstaScript->setSuppressCtrlEnter(true); connect(ui->memoInstaScript, SIGNAL(onCtrlEnter()), this, SLOT(on_btnInstaRun_clicked())); m_pjsrobokey = new JsRoboKey(this); JSEdit& editor = *ui->memoInstaScript; editor.setWindowTitle("Insta Run"); editor.setFrameShape(JSEdit::NoFrame); editor.setWordWrapMode(QTextOption::NoWrap); editor.setTabStopWidth(4); //editor.resize(QApplication::desktop()->availableGeometry().size() / 2); QStringList keywords = editor.keywords(); keywords << "const"; keywords << "let"; editor.setKeywords(keywords); // dark color scheme editor.setColor(JSEdit::Background, QColor("#0C152B")); editor.setColor(JSEdit::Normal, QColor("#FFFFFF")); editor.setColor(JSEdit::Comment, QColor("#666666")); editor.setColor(JSEdit::Number, QColor("#DBF76C")); editor.setColor(JSEdit::String, QColor("#5ED363")); editor.setColor(JSEdit::Operator, QColor("#FF7729")); editor.setColor(JSEdit::Identifier, QColor("#FFFFFF")); editor.setColor(JSEdit::Keyword, QColor("#FDE15D")); editor.setColor(JSEdit::BuiltIn, QColor("#9CB6D4")); editor.setColor(JSEdit::Cursor, QColor("#1E346B")); editor.setColor(JSEdit::Marker, QColor("#DBF76C")); editor.setColor(JSEdit::BracketMatch, QColor("#1AB0A6")); editor.setColor(JSEdit::BracketError, QColor("#A82224")); editor.setColor(JSEdit::FoldIndicator, QColor("#555555")); createActions(); createTrayIcon(); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(on_trayMessageClicked())); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); setIcon(1); trayIcon->show(); //initalize the v8 engine initialize(); //Currently the tray icon ALWAYS loads, this is for safety, later on do we allow turning it off via command line argument? bool loadMainScriptFile = true; QStringList args = QApplication::arguments(); for (int i = 1; i < args.length(); ++i){ if (args[i] == "--hidetotray"){ hide(); }else if (args[i] == "--defaulteditor"){ i++; if (i < args.length()){ m_defaultEditor = args[i]; } continue; }else if (args[i] == "--showtraymsg"){ i++; if (i < args.length()){ showTrayMessage("JSRoboKey Loaded", args[i]); } continue; } else if (QFile::exists(args[i])){ //if the file exists, just load it bool scriptError = loadJSFile(args[i]); //TODO: if there was a script error, do we tell the user? //also do not load main script file loadMainScriptFile = false; }else{ //TODO: not an existing file, is it something else like a command line option? } }//end looping through command line arguments if (loadMainScriptFile){ loadMainScript(); } //set the default editor for editing main file #ifdef Q_OS_WIN32 m_defaultEditor = "notepad"; #elif Q_OS_MAC m_defaultEditor = "TextEdit"; #else m_defaultEditor = "gedit"; #endif //TODO: the only REAL way to detect a valid editor is to spawn it and see if it returns false }