From b70928f9b7ca924132f298d2a3eb7fc4b51607b4 Mon Sep 17 00:00:00 2001 From: Oliver Eisenhut Date: Thu, 22 Feb 2018 14:02:30 +0100 Subject: [PATCH 1/4] Move renderer.js to typescript --- gulpfile.js | 2 +- src/main.html => main.html | 4 +-- package.json | 3 +- src/ts/main.ts | 4 +-- src/{renderer.js => ts/renderer.ts} | 52 ++++++++++++++++------------- tsconfig.json | 2 +- 6 files changed, 36 insertions(+), 31 deletions(-) rename src/main.html => main.html (94%) rename src/{renderer.js => ts/renderer.ts} (70%) diff --git a/gulpfile.js b/gulpfile.js index dd02dc8ff..036d10b90 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,7 +6,7 @@ const sourceFiles = { } const outputFolders = { - css: './src/styles/css', + css: './dist/styles/css', } gulp.task('styles', () => { diff --git a/src/main.html b/main.html similarity index 94% rename from src/main.html rename to main.html index 464e74cee..6a29edbaf 100644 --- a/src/main.html +++ b/main.html @@ -45,9 +45,7 @@ - - - + \ No newline at end of file diff --git a/package.json b/package.json index 2658208b0..b8ad56fc5 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,13 @@ "url": "https://github.com/oliverschwendener" }, "description": "A cross-platform alt+space launcher", - "main": "src/js/main.js", + "main": "dist/js/main.js", "scripts": { "scss:watch": "./node_modules/.bin/gulp --watch", "tsc:watch": "./node_modules/.bin/tsc --watch", "build": "./node_modules/.bin/tsc && ./node_modules/.bin/gulp build", "start": "./node_modules/.bin/electron .", + "start:dev": "yarn build && yarn start", "dev": "./node_modules/.bin/electron . --enable-logging", "test:unit": "./node_modules/.bin/mocha -r ./node_modules/ts-node/register ./tests/unit/**/*.test.ts", "test:integration": "./node_modules/.bin/mocha -r ./node_modules/ts-node/register ./tests/integration/**/*.test.ts", diff --git a/src/ts/main.ts b/src/ts/main.ts index c959021e8..2d7c2fd8a 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -26,11 +26,11 @@ function createMainWindow(): void { frame: false, show: false, skipTaskbar: true, - resizable: false, + resizable: true, backgroundColor: '#00000000', }); - mainWindow.loadURL(`file://${__dirname}/../main.html`); + mainWindow.loadURL(`file://${__dirname}/../../main.html`); mainWindow.setSize(Config.windowWith, Config.minWindowHeight); mainWindow.on("close", quitApp); diff --git a/src/renderer.js b/src/ts/renderer.ts similarity index 70% rename from src/renderer.js rename to src/ts/renderer.ts index 8edafb085..98c2201cc 100644 --- a/src/renderer.js +++ b/src/ts/renderer.ts @@ -1,21 +1,23 @@ -let os = require('os'); -let ipcRenderer = require('electron').ipcRenderer; -let delayOnExecution = 50; // in milliseconds +const Vue = require("vue/dist/vue.min.js") +const os = require("os") +const ipcRenderer = require("electron").ipcRenderer +const delayOnExecution = 50; // in milliseconds document.addEventListener('keyup', handleGlobalKeyPress); +console.log(__dirname) -let vue = new Vue({ +const vue = new Vue({ el: '#vue-root', data: { - stylesheetPath: os.platform() === 'win32' ? './styles/css/windows.css' : './styles/css/mac.css', + stylesheetPath: os.platform() === 'win32' ? __dirname + '/dist/styles/css/windows.css' : __dirname + '/dist/styles/css/mac.css', userInput: '', autoFocus: true, searchIcon: '', - searchResults: [], - commandLineOutput: [] + searchResults: Array(), + commandLineOutput: Array() }, methods: { - handleKeyPress: (event) => { + handleKeyPress: (event: KeyboardEvent) => { if (event.key === 'Enter') { handleEnterPress(); } @@ -40,35 +42,35 @@ let vue = new Vue({ } }, watch: { - userInput: (val) => { + userInput: (val:any) => { vue.commandLineOutput = []; ipcRenderer.send('get-search', val); } } }); -ipcRenderer.on('get-search-response', (event, arg) => { +ipcRenderer.on('get-search-response', (event: Electron.Event, arg: any) => { updateSearchResults(arg); }); ipcRenderer.send('get-search-icon'); -ipcRenderer.on('get-search-icon-response', (event, arg) => { +ipcRenderer.on('get-search-icon-response', (event: Electron.Event, arg: any) => { vue.searchIcon = arg; }); -ipcRenderer.on("auto-complete-response", (event, arg) => { +ipcRenderer.on("auto-complete-response", (event: Electron.Event, arg: any) => { vue.userInput = arg; }); -ipcRenderer.on('command-line-output', (event, arg) => { +ipcRenderer.on('command-line-output', (event: Electron.Event, arg: any) => { vue.commandLineOutput.push(arg); }); -function updateSearchResults(searchResults) { +function updateSearchResults(searchResults: any) { let idIndex = 0; - searchResults.forEach((s) => { + searchResults.forEach((s: any) => { s.id = `search-result-item-${idIndex}`; s.active = false; idIndex++; @@ -85,7 +87,7 @@ function updateSearchResults(searchResults) { } } -function changeActiveItem(direction) { +function changeActiveItem(direction: any) { if (vue.searchResults.length === 0) { return; } @@ -98,10 +100,11 @@ function changeActiveItem(direction) { } } - vue.searchResults.forEach((s) => { + vue.searchResults.forEach((s:any) => { s.active = false; }); + if (next == undefined) return if (next < 0) { next = vue.searchResults.length - 1; } @@ -113,8 +116,8 @@ function changeActiveItem(direction) { scrollIntoView(vue.searchResults[next]); } -function scrollIntoView(searchResult) { - el = document.getElementById(searchResult.id); +function scrollIntoView(searchResult: any) { + const el = document.getElementById(searchResult.id); if (el !== undefined && el !== null) { el.scrollIntoView(); } @@ -148,7 +151,7 @@ function handleAutoCompletion() { } function getActiveItem() { - let activeSearchResults = vue.searchResults.filter((s) => { + let activeSearchResults = vue.searchResults.filter((s: any) => { return s.active; }); @@ -157,7 +160,7 @@ function getActiveItem() { } } -function execute(executionArgument) { +function execute(executionArgument: any) { ipcRenderer.send('execute', executionArgument); } @@ -165,12 +168,15 @@ function resetUserInput() { vue.userInput = ''; } -function handleGlobalKeyPress(event) { +function handleGlobalKeyPress(event: any) { if (event.key === 'F6' || (event.key === 'l' && event.ctrlKey)) { focusOnInput(); } } function focusOnInput() { - document.getElementById('user-input').focus(); + const userInput = document.getElementById('user-input') + if (userInput != null) { + userInput.focus() + } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 6c8f58949..6fe86c55d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ // "declaration": true, /* Generates corresponding '.d.ts' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./src/js", /* Redirect output structure to the directory. */ + "outDir": "./dist/js", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ From 63aa2b09481d5b64aa38ed4f0df46345f87f9f0d Mon Sep 17 00:00:00 2001 From: Oliver Eisenhut Date: Thu, 22 Feb 2018 16:55:21 +0100 Subject: [PATCH 2/4] Remove debug statement --- src/ts/renderer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ts/renderer.ts b/src/ts/renderer.ts index 98c2201cc..a74d85fab 100644 --- a/src/ts/renderer.ts +++ b/src/ts/renderer.ts @@ -4,7 +4,6 @@ const ipcRenderer = require("electron").ipcRenderer const delayOnExecution = 50; // in milliseconds document.addEventListener('keyup', handleGlobalKeyPress); -console.log(__dirname) const vue = new Vue({ el: '#vue-root', From f4945b1b329b04a108202600d88983ca7d392f9e Mon Sep 17 00:00:00 2001 From: Oliver Eisenhut Date: Thu, 22 Feb 2018 16:59:42 +0100 Subject: [PATCH 3/4] Revert test assignement --- src/ts/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/main.ts b/src/ts/main.ts index 2d7c2fd8a..350983c07 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -26,7 +26,7 @@ function createMainWindow(): void { frame: false, show: false, skipTaskbar: true, - resizable: true, + resizable: false, backgroundColor: '#00000000', }); From fba598385f846045a5c27200fecd45c8808dcb89 Mon Sep 17 00:00:00 2001 From: Oliver Eisenhut Date: Thu, 22 Feb 2018 17:19:36 +0100 Subject: [PATCH 4/4] Use build as out directory --- .gitignore | 7 ++----- gulpfile.js | 2 +- main.html | 2 +- package.json | 2 +- src/ts/renderer.ts | 2 +- tsconfig.json | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 9d1e1490a..249a26a33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ -#Transpiled js files -src/js - -#Compiled css files -src/styles/css +#Compiled files +build/ #Packaged apps dist/ diff --git a/gulpfile.js b/gulpfile.js index 036d10b90..94cb85e33 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,7 +6,7 @@ const sourceFiles = { } const outputFolders = { - css: './dist/styles/css', + css: './build/styles/css', } gulp.task('styles', () => { diff --git a/main.html b/main.html index 6a29edbaf..b93c5b473 100644 --- a/main.html +++ b/main.html @@ -45,7 +45,7 @@ - + \ No newline at end of file diff --git a/package.json b/package.json index b8ad56fc5..63ec20cfb 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/oliverschwendener" }, "description": "A cross-platform alt+space launcher", - "main": "dist/js/main.js", + "main": "./build/js/main.js", "scripts": { "scss:watch": "./node_modules/.bin/gulp --watch", "tsc:watch": "./node_modules/.bin/tsc --watch", diff --git a/src/ts/renderer.ts b/src/ts/renderer.ts index a74d85fab..31ec31865 100644 --- a/src/ts/renderer.ts +++ b/src/ts/renderer.ts @@ -8,7 +8,7 @@ document.addEventListener('keyup', handleGlobalKeyPress); const vue = new Vue({ el: '#vue-root', data: { - stylesheetPath: os.platform() === 'win32' ? __dirname + '/dist/styles/css/windows.css' : __dirname + '/dist/styles/css/mac.css', + stylesheetPath: os.platform() === 'win32' ? __dirname + '/build/styles/css/windows.css' : __dirname + '/build/styles/css/mac.css', userInput: '', autoFocus: true, searchIcon: '', diff --git a/tsconfig.json b/tsconfig.json index 6fe86c55d..975ee2f68 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ // "declaration": true, /* Generates corresponding '.d.ts' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist/js", /* Redirect output structure to the directory. */ + "outDir": "./build/js", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */