// Compiled by ClojureScript 1.9.562 {:target :nodejs}
goog.provide('app.main');
goog.require('cljs.core');
goog.require('weathergen.ipc');
goog.require('weathergen.falcon.install');
app.main.electron = require("electron");
app.main.app = app.main.electron.app;
app.main.path = require("path");
app.main.BrowserWindow = app.main.electron.BrowserWindow;
app.main.ipcMain = app.main.electron.ipcMain;

/** @define {boolean} */
goog.define("app.main.dev_QMARK_",false);
/**
 * When compiling with `:none` the compiled JS that calls .loadURL is
 *   in a different place than it would be when compiling with optimizations
 *   that produce a single artifact (`:whitespace, :simple, :advanced`).
 * 
 *   Because of this we need to dispatch the loading based on the used
 *   optimizations, for this we defined `dev?` above that we can override
 *   at compile time using the `:clojure-defines` compiler option.
 */
app.main.load_page = (function app$main$load_page(window,page){
return window.loadURL([cljs.core.str.cljs$core$IFn$_invoke$arity$1("file://"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(app.main.path.join(app.main.app.getAppPath(),page))].join(''));
});
app.main.app_window = cljs.core.atom.call(null,null);
app.main.mission_windows = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
app.main.installations = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
app.main.mk_window = (function app$main$mk_window(w,h,frame_QMARK_,show_QMARK_){
return (new app.main.BrowserWindow(({"width": w, "height": h, "frame": frame_QMARK_, "show": show_QMARK_, "icon": "images/1stVFW_Insignia.png", "center": true})));
});
/**
 * Kicks off a renderer opening the thing at `path`. `mode` tells us
 *   whether it's a `:briefing` or a `:mission`.
 */
app.main.open = (function app$main$open(path,mode){
var mission_window = app.main.mk_window.call(null,(1300),(800),true,false);
cljs.core.swap_BANG_.call(null,app.main.mission_windows,cljs.core.assoc,mission_window.webContents.id,mission_window);

app.main.load_page.call(null,mission_window,"mission.html");

mission_window.webContents.on("did-finish-load",((function (mission_window){
return (function (){
if(!(((process.env["VMT_DEV_OPEN_WINDOW_EARLY"]) == null))){
mission_window.show();
} else {
}

return weathergen.ipc.send_to_renderer.call(null,mission_window,mode.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"briefing","briefing",-176308969),"open-briefing",new cljs.core.Keyword(null,"mission","mission",1740288522),"open-mission"], null)),cljs.core.deref.call(null,app.main.installations),path);
});})(mission_window))
);

mission_window.webContents.on("new-window",((function (mission_window){
return (function (e,url){
require("electron").shell.openExternal(url);

return e.preventDefault();
});})(mission_window))
);

return mission_window.on("closed",((function (mission_window){
return (function (){
return cljs.core.swap_BANG_.call(null,app.main.mission_windows,cljs.core.dissoc,path);
});})(mission_window))
);
});
cljs.core._add_method.call(null,weathergen.ipc.on_message,"open-mission",(function (_,event,path){
return app.main.open.call(null,path,new cljs.core.Keyword(null,"mission","mission",1740288522));
}));
cljs.core._add_method.call(null,weathergen.ipc.on_message,"open-briefing",(function (_,event,path){
return app.main.open.call(null,path,new cljs.core.Keyword(null,"briefing","briefing",-176308969));
}));
cljs.core._add_method.call(null,weathergen.ipc.on_message,"load-complete",(function (_,event){
cljs.core.get.call(null,cljs.core.deref.call(null,app.main.mission_windows),event.sender.id).show();

return weathergen.ipc.send_to_renderer.call(null,cljs.core.deref.call(null,app.main.app_window),"load-complete");
}));
cljs.core._add_method.call(null,weathergen.ipc.on_message,new cljs.core.Keyword(null,"default","default",-1987822328),(function (msg_name,event,msg){
return weathergen.ipc.send_to_renderer.call(null,cljs.core.deref.call(null,app.main.app_window),msg_name,msg);
}));
app.main.init_browser = (function app$main$init_browser(){
cljs.core.reset_BANG_.call(null,app.main.app_window,app.main.mk_window.call(null,(800),(600),true,false));

if(!(((process.env["VMT_DEV_SHOW_TEST_WINDOW"]) == null))){
var test_window_33086 = app.main.mk_window.call(null,(1300),(800),true,false);
app.main.load_page.call(null,test_window_33086,"test.html");

test_window_33086.webContents.on("did-finish-load",((function (test_window_33086){
return (function (){
return test_window_33086.show();
});})(test_window_33086))
);
} else {
}

app.main.load_page.call(null,cljs.core.deref.call(null,app.main.app_window),"index.html");

cljs.core.deref.call(null,app.main.app_window).webContents.on("did-finish-load",(function (){
return cljs.core.deref.call(null,app.main.app_window).show();
}));

if(cljs.core.truth_(app.main.dev_QMARK_)){
} else {
}

return cljs.core.deref.call(null,app.main.app_window).on("closed",(function (){
return cljs.core.reset_BANG_.call(null,app.main.app_window,null);
}));
});
app.main.init = (function app$main$init(){
app.main.app.on("window-all-closed",(function (){
if(cljs.core._EQ_.call(null,process.platform,"darwin")){
return null;
} else {
return app.main.app.quit();
}
}));

app.main.app.on("ready",(function (){
return weathergen.falcon.install.locate_installations.call(null,(function (installs){
cljs.core.reset_BANG_.call(null,app.main.installations,installs);

return app.main.init_browser.call(null);
}));
}));

return cljs.core._STAR_main_cli_fn_STAR_ = (function (){
return null;
});
});
