Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisM committed Dec 19, 2016
1 parent 1c53f5d commit 0f535a7
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 44 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ once: `npm i -g chokidar-cli`

`npm run watch`


### Todo

- [x] Save installed packages to preferences
- [ ] After downloading package, get actual name of package on FS and return it (bootstrap.js, see node-targz issue #xx for details regarding callback)
- [ ] Add option to reset to default settings and remove all installed packages
- [X] After downloading package, get actual name of package on FS and return it (solved, although a bit nasty)
- [x] Add option to reset to default settings and remove all installed packages
- [ ] Add option to download specific version of documentation
- [ ] Add option to update docsets (including checking if update is available)
- [ ] Make sure paths are cleaned (no traversal attacks)
Expand Down
9 changes: 7 additions & 2 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ webview {
padding-bottom: 14px;
background-color: #e4e4e4 !important;
}
.active {
background-color: #3498db !important;
nav ul li.active {
background-color: #3498db;
height: 100%;
}

.side-nav.fixed a {
overflow: hidden;
}

.reset-button {
margin-top: 30px;
}

/*spinner effects*/
.spinner {
width: 40px;
Expand Down
47 changes: 28 additions & 19 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ const settings = require('electron-settings');
const remote = require('electron').remote;
const app = remote.app;
const ipcRenderer = require("electron").ipcRenderer

var tar = require('tar');
var fstream = require('fstream');
var zlib = require('zlib');
var sqlite3 = require("sqlite3").verbose();
const {dialog} = require('electron').remote;

function getDB(language) {
var file = path.join(app.getPath('userData'), "/docsets/" + language + "/Contents/Resources/docSet.dsidx");
var exists = fs.existsSync(file);
Expand All @@ -31,6 +35,10 @@ let container = document.getElementById('container')
// and keep a reference for communicating with the app
let devination = Elm.Main.fullscreen();

devination.ports.showError.subscribe(function (error) {
dialog.showMessageBox({ type: 'info', buttons: ['Report', 'Cancel'], message: "An error has occured: " + error }, function (buttonIndex) { });
});

devination.ports.search.subscribe(function (options) {
var cb = function (result) {
devination.ports.searchResult.send(result);
Expand All @@ -45,6 +53,7 @@ function getCache(language, term, cb) {
var cache = [];
var query = "";
db.get("SELECT count(*) as zdash FROM sqlite_master WHERE type='table' AND name='searchIndex'", [], function (err, s) {
dialog.showMessageBox({ type: 'info', buttons: ['Report', 'Cancel'], message: "An error has occured: " + err }, function (buttonIndex) { });
if (!s.zdash) {
query = "SELECT ztoken.ztokenname as name, ztokentype.ztypename as kind, zfilepath.zpath as path, ztokenmetainformation.zanchor as id "
+ "FROM ztoken "
Expand All @@ -64,30 +73,30 @@ function getCache(language, term, cb) {
}
}


devination.ports.download.subscribe(function (info) {
var url = info[1]
var language = info[0]
var read = request.get(url);
var write = targz().createWriteStream(path.join(app.getPath('userData'), "/docsets/"));
var i = 0;
var onFileName = function (path) {
var s =
{ name : language
, logo : ""
, fsName : path
// fsName: foundPath
, icon: info[2]
, icon2x: info[3]
}
devination.ports.downloadResult.send(s);
};

write.on('entry', function(entry){
if(i === 0) { onFileName(entry.path) }
i++;
});
var piped = read.pipe(write);
// write.on('end', function() {
// console.log("end")
// // this callback does not work
// // https://github.com/alanhoff/node-tar.gz/issues/40
// // var files = fs.readdirSync("docsets/" + language + "/");
// // var foundPath = files[0];
// })
console.log(url);
console.log(path.join(app.getPath('userData'), "/docsets/"));
var s =
{ name : language
, logo : ""
, fsName : language + ".docset"
// fsName: foundPath
, icon: info[2]
, icon2x: info[3]
}
devination.ports.downloadResult.send(s);
});


Expand Down
15 changes: 12 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const electron = require('electron');
// Module to control application life.
const {app, globalShortcut, autoUpdater} = require('electron')
const {app, globalShortcut, autoUpdater, dialog} = require('electron')
// Module to create native browser window.
const {BrowserWindow} = electron;
const os = require('os');
Expand All @@ -12,8 +12,6 @@ const remote = electron.remote;
// be closed automatically when the JavaScript object is garbage collected.
let win;

const dialog = require('electron').dialog

app.setAsDefaultProtocolClient('devination')

app.on('open-url', function (event, url) {
Expand All @@ -31,6 +29,17 @@ function createWindow() {
win.webContents.openDevTools();
})

win.on('uncaughtException', function (error) {
console.log("asdfasdfasdfasdf", error);
dialog.showMessageBox({ type: 'info', buttons: ['Report', 'Cancel'], message: "An error has occured: " + error }, function (buttonIndex) { });
});

app.on('uncaughtException', function (error) {
console.log("asdfasdfasdfasdf", error);
dialog.showMessageBox({ type: 'info', buttons: ['Report', 'Cancel'], message: "An error has occured: " + error }, function (buttonIndex) { });
});


new AppUpdater(win)

// Open the DevTools.
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devination",
"version": "0.0.1",
"version": "0.0.2",
"description": "a cross plattform offline documentation browser",
"productName": "devination",
"main": "main.js",
Expand Down Expand Up @@ -32,19 +32,19 @@
},
"homepage": "http://devination.gitlab.io/",
"devDependencies": {
"chokidar": "^1.6.0",
"chokidar": "^1.6.1",
"chokidar-cli": "^1.2.0",
"electron-builder": "^10.6.1",
"electron-packager": "^8.3.0",
"electron": "^1.4.10",
"electron-builder": "^10.8.1",
"electron-packager": "^8.4.0",
"electron": "^1.4.12",
"electron-rebuild": "^1.4.0",
"electron-settings": "^2.2.2"
},
"dependencies": {
"electron-auto-updater": "^0.7.0",
"electron-auto-updater": "^0.7.2",
"electron-settings": "^2.2.2",
"materialize-css": "^0.97.6",
"request": "^2.72.0",
"materialize-css": "^0.97.8",
"request": "^2.79.0",
"sqlite3": "https://github.com/mapbox/node-sqlite3/tarball/master#3.15.0",
"tar.gz": "^1.0.5"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ update msg model =
( model, batch [ getSettings "" ] )

FailRequest err ->
( { model | error = Debug.log "error: " <| errorToString err }, Cmd.none )
( { model | error = errorToString err }, batch [ showError (errorToString err) ] )

SettingsResult settings ->
-- ( { model | feeds = [] }, Cmd.none )
Expand Down
13 changes: 6 additions & 7 deletions src/MainView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ functionsBar model =
:: (List.map (nameView model) model.cache)


installedLanguagesSelector : Model -> InstalledLanguage -> Html Msg
installedLanguagesSelector model language =
installedLanguagesSelector : Bool -> Model -> InstalledLanguage -> Html Msg
installedLanguagesSelector isTopbar model language =
Html.li
[ Html.Events.onClick (UpdateSelectedLanguage language), class "collection-item", class <| isLanguageSelected model language ]
[ Html.div [ Html.Attributes.class "icon", Html.Attributes.style [ ( "background", "url(data:image/gif;base64," ++ language.icon2x ++ ")" ) ] ] []
-- , Html.text <| removeDocsetAppendix language.name ]
]
([ Html.div [ Html.Attributes.class "icon", Html.Attributes.style [ ( "background", "url(data:image/gif;base64," ++ language.icon2x ++ ")" ) ] ] []
] ++ if not isTopbar then [ Html.text language.name ] else [])

chooseHeader : Html Msg
chooseHeader =
Expand All @@ -97,7 +96,7 @@ docsView model =
Nothing ->
[ Html.ul
[ class "collection with-header" ]
(chooseHeader :: (List.map (installedLanguagesSelector model) <| Maybe.withDefault [] <| Maybe.map .installedLanguages model.settings ))
(chooseHeader :: (List.map (installedLanguagesSelector False model) <| Maybe.withDefault [] <| Maybe.map .installedLanguages model.settings ))
]


Expand All @@ -121,7 +120,7 @@ topBar model =
[ Html.a [ Html.Events.onClick OpenSettings ] [ Html.text "Settings" ], Html.text model.error ]
, Html.ul
[ class "right" ]
(List.map (installedLanguagesSelector model) <| Maybe.withDefault [] <| Maybe.map .installedLanguages model.settings)
(List.map (installedLanguagesSelector True model) <| Maybe.withDefault [] <| Maybe.map .installedLanguages model.settings)
]
]
]
Expand Down
2 changes: 2 additions & 0 deletions src/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ port resetToDefaults : String -> Cmd msg
port setSettings : (Maybe Settings) -> Cmd msg

port settingsResult : (Settings -> msg) -> Sub msg

port showError : String -> Cmd msg
4 changes: 3 additions & 1 deletion src/SettingsView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ topBar model =

feedsView : Model -> Html Msg
feedsView model =
div [] [ button [ Html.Events.onClick ResetSettings ] [ Html.text "Reset Settings" ] ]
div
[ Html.Attributes.class "reset-button" ]
[ button [ Html.Events.onClick ResetSettings, Html.Attributes.class "btn" ] [ Html.text "Reset Settings" ] ]


settingsView : Model -> Html Msg
Expand Down

0 comments on commit 0f535a7

Please sign in to comment.