From 6b237dfbbb2253b296bee52315618c649796fa08 Mon Sep 17 00:00:00 2001 From: dtookey Date: Wed, 20 Jan 2021 13:11:46 -0500 Subject: [PATCH 1/3] search will correctly match files based on keyword --- src/ts_source/fileutils.ts | 29 ++++++++++++----------------- src/ts_source/search.ts | 20 +++++++++++++------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/ts_source/fileutils.ts b/src/ts_source/fileutils.ts index be7fafb..af42c14 100644 --- a/src/ts_source/fileutils.ts +++ b/src/ts_source/fileutils.ts @@ -114,27 +114,24 @@ export class DocumentDirectory { private static walkCards(d: DirectoryNode): Map { let cardsByCategory = new Map(); - for (let i = 0, l = d.children.length; i < l; i++) { - let child = d.children[i]; + for (let child of d.children) { if (child instanceof DirectoryNode) { let dir = child as DirectoryNode; if (dir.containsDirectory()) { let childDirectories = dir.getDirectories(); - for (let j = 0, k = childDirectories.length; j < k; j++) { - let dir = childDirectories[j]; + for (let dir of childDirectories) { let subCards = DocumentDirectory.walkCards(dir); this.mergeMaps(cardsByCategory, subCards); } } let sCards = dir.getDocuments(); let category = dir.getCategory(); - for (let sCard in sCards) { - let scrd = sCards[sCard]; + for (let sCard of sCards) { let cards = cardsByCategory.get(category); if (cards === undefined || cards === null) { cards = []; } - cards.push(scrd.toCard()); + cards.push(sCard.toCard()); cardsByCategory.set(category, cards); } } else { @@ -153,8 +150,7 @@ export class DocumentDirectory { private static mergeMaps(a: Map, b: Map) { let keys = Object.keys(b); - for (let z in keys) { - let key = keys[z]; + for (let key of keys) { let sa = a.get(key) if (sa === undefined || sa === null) { sa = []; @@ -213,12 +209,12 @@ export class FileNode { "imagePath": imageName, "urlText": this.filePath, "altText": "", - "fileCard": true + "fileCard": true, + "open": this.open } let altKeys = Object.keys(altProps); - for (let kidx in altKeys) { - let key = altKeys[kidx]; + for (let key of altKeys) { cardObj[key] = altProps[key] } @@ -251,9 +247,9 @@ export class DirectoryNode extends FileNode { let stats = fs.lstatSync(filePath); if (stats.isDirectory()) { let contents = fs.readdirSync(filePath); - for (let i = 0, l = contents.length; i < l; i++) { - if (path.extname(contents[i]) === ".json") continue; - let childPath = path.join(filePath, contents[i]); + for (let fileName of contents) { + if (path.extname(fileName) === ".json") continue; + let childPath = path.join(filePath, fileName); let childStats = fs.lstatSync(childPath); if (childStats.isDirectory()) { this.children.push(new DirectoryNode(childPath, this)); @@ -282,8 +278,7 @@ export class DirectoryNode extends FileNode { } containsDirectory(): Boolean { - for (let i = 0, l = this.children.length; i < l; i++) { - let child = this.children[i]; + for (let child of this.children) { if (child instanceof DirectoryNode) return true; } return false diff --git a/src/ts_source/search.ts b/src/ts_source/search.ts index e19d676..d651f05 100644 --- a/src/ts_source/search.ts +++ b/src/ts_source/search.ts @@ -14,7 +14,7 @@ function register() { search(term); } - }else{ + } else { let term = searchBar.val().toString(); if (!term || 0 === term.length) { reset() @@ -23,7 +23,7 @@ function register() { }); - searchButton.on("click", ()=>{ + searchButton.on("click", () => { let term = searchBar.val().toString(); if (!term || 0 === term.length) { reset() @@ -33,7 +33,7 @@ function register() { }) } -function reset(){ +function reset() { buildUiFromConfig("resources-landing-page.json"); } @@ -47,7 +47,7 @@ function search(term: string) { expandAllContainers(); } -function copyMissingKeys(webCards: object, fileCards: Map){ +function copyMissingKeys(webCards: object, fileCards: Map) { let elementConfig = Configurator.loadAppConfig("resources-landing-page.json"); let containerKeys = Object.keys(elementConfig); for (let containerKey of containerKeys) { @@ -127,8 +127,14 @@ function addToFileMap(map: Map, categoryKey: string, card) { function cardContainsTerm(term: string, card: object): boolean { let titleContains = card["title"].toLowerCase().includes(term.toLowerCase()); let descriptionContains = card["description"].toLowerCase().includes(term.toLowerCase()); + + let keywordContains = false; + if (card["keywords"]) { + keywordContains = card["keywords"].toLowerCase().includes(term.toLowerCase()); + } + //todo: add keywords - return titleContains || descriptionContains; + return titleContains || descriptionContains || keywordContains; } function highlightCardTerm(term: string, card: object): object { @@ -143,9 +149,9 @@ function escapeRegExp(term: string): string { return term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } -function expandAllContainers(){ +function expandAllContainers() { let containers = $('[id$="collapser"]') - for(let container of containers){ + for (let container of containers) { container.click() } From 14db1cd007a4d4ad9c581a5cc7e9ef9ebd521b22 Mon Sep 17 00:00:00 2001 From: dtookey Date: Wed, 20 Jan 2021 13:31:50 -0500 Subject: [PATCH 2/3] modified file cards to place a copy of the employee resource in the my documents folder of the user's home directory and open the directory instead of opening the canonical file --- src/ts_source/fileutils.ts | 33 +++++++++++++++++++++++++++++++-- src/ts_source/viewFactory.ts | 22 +++++++++++++--------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/ts_source/fileutils.ts b/src/ts_source/fileutils.ts index af42c14..a7c3d86 100644 --- a/src/ts_source/fileutils.ts +++ b/src/ts_source/fileutils.ts @@ -1,5 +1,6 @@ let path = require('path') let fs = require('fs'); +let os = require('os'); const shell = require('electron').shell; let fileExtensionToImage: object; @@ -59,6 +60,7 @@ export module FileUtils { export function getPathToView(templateName: string): string { return path.join(getPathToAssets(), "views", templateName + ".mustache") } + export function getPathToPage(pageName: string): string { return path.join(getPathToAssets(), "pages", pageName) } @@ -95,6 +97,34 @@ export module FileUtils { fs.mkdirSync(dirPath); } } + + export function showFileInDir(resourcePath: string) { + let localFile = copyFileToUserDocuments(resourcePath); + shell.showItemInFolder(localFile); + } + + /** + * @param resourcePath pathlike of system resource + * @private + * @returns pathlike of local user resource + */ + function copyFileToUserDocuments(resourcePath: string): string { + let fileName = path.basename(resourcePath); + let userFilePath = getPathToUserDocumentDir(fileName); + if(!fs.existsSync(userFilePath)){ + fs.copyFileSync(resourcePath, userFilePath); + } + return userFilePath; + } + + function getPathToUserDocumentDir(fileName: string): string { + let homeDir = os.homedir(); + let parent = path.join(homeDir, "Documents", "Employee Resources"); + if(!fs.existsSync(parent)){ + fs.mkdirSync(parent); + } + return path.join(parent, fileName); + } } @@ -188,8 +218,7 @@ export class FileNode { private static getImagePathFromDocumentName(name: string): string { let ext = FileUtils.getFileExtension(name); - let thumbnail = Configurator.getFileExtensionToImageMap()[ext]; - return thumbnail; + return Configurator.getFileExtensionToImageMap()[ext]; } open() { diff --git a/src/ts_source/viewFactory.ts b/src/ts_source/viewFactory.ts index f89ef73..4860c48 100644 --- a/src/ts_source/viewFactory.ts +++ b/src/ts_source/viewFactory.ts @@ -37,15 +37,19 @@ export function buildFileCard(elem: JQuery, obj, append: boolean = elem.html(content) } - if (model["show"] !== undefined) { - $(`#${id}`).on("click", () => { - shell.showItemInFolder(model.resourcePath) - }); - } else { - $(`#${id}`).on("click", () => { - shell.openItem(model.resourcePath) - }); - } + $(`#${id}`).on("click", () => { + FileUtils.showFileInDir(model.resourcePath); + }); + + // if (model["show"] !== undefined) { + // $(`#${id}`).on("click", () => { + // shell.showItemInFolder(model.resourcePath) + // }); + // } else { + // $(`#${id}`).on("click", () => { + // shell.openItem(model.resourcePath) + // }); + // } }); } From 0106230d126539a7750f75020e984a26642ce03b Mon Sep 17 00:00:00 2001 From: dtookey Date: Thu, 15 Apr 2021 11:00:58 -0400 Subject: [PATCH 3/3] crude sketch for auto updating --- gulpfile.js | 7 +++++- package-lock.json | 40 ++++++++++++++++----------------- package.json | 8 +++---- src/assets/images/icon.ico | Bin 0 -> 2222 bytes src/assets/images/icon.png | Bin 0 -> 2623 bytes src/index.js | 45 ++++++++++++++++++++++++++++++++----- 6 files changed, 70 insertions(+), 30 deletions(-) create mode 100644 src/assets/images/icon.ico create mode 100644 src/assets/images/icon.png diff --git a/gulpfile.js b/gulpfile.js index 679125c..bd9b8a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,6 +10,7 @@ let tsSource = ts.createProject('tsconfig.json') function clean(cb) { del(['build/*']); + del(['out/*']); cb(); } @@ -45,6 +46,10 @@ function validateConfigSources(cb) { cb(); } +let deploy = () => { + +}; + function conf() { return src(['src/assets/**/*', '!src/assets/**/*.scss'], {base: 'src/assets'}) .pipe(dest('build/assets/')); @@ -112,7 +117,6 @@ let validationRules = { "description": stringLengthRule } } - } @@ -124,3 +128,4 @@ exports.tests = series(validateConfigSources, conf, style, scss, root, pkg, type exports.runFast = series(validateConfigSources, conf, style, scss, root, pkg) +exports.deploy = series(clean, validateConfigSources, conf, style, scss, root, pkg, typescript, dependencies, deploy); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 68fb319..d6b56cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -871,9 +871,9 @@ } }, "base64-js": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "dev": true }, "bcrypt-pbkdf": { @@ -4879,9 +4879,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -5394,9 +5394,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -5864,14 +5864,14 @@ } }, "plist": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.1.tgz", - "integrity": "sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.2.tgz", + "integrity": "sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==", "dev": true, "requires": { - "base64-js": "^1.2.3", + "base64-js": "^1.5.1", "xmlbuilder": "^9.0.7", - "xmldom": "0.1.x" + "xmldom": "^0.5.0" } }, "plugin-error": { @@ -6461,9 +6461,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -7690,9 +7690,9 @@ "dev": true }, "xmldom": { - "version": "0.1.31", - "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.31.tgz", - "integrity": "sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz", + "integrity": "sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==", "dev": true }, "xtend": { diff --git a/package.json b/package.json index 8e6f233..2db982e 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,10 @@ "start-fast": "gulp runFast && electron ./build --debug", "dev": "npm run build && electron ./build --debug", "package": "npm-run-all package:*", - "package:mac": "electron-packager ./build --overwrite --platform=darwin --arch=x64 --out=out --icon=assets/images/app.icns --osx-sign.identity='Developer ID Application: GitHub' --extend-info=assets/mac/info.plist", - "package:win32": "electron-packager ./build --overwrite --platform=win32 --arch=ia32 --out=out --icon=assets/images/app.ico", - "package:win64": "electron-packager ./build --overwrite --platform=win32 --arch=x64 --out=out --icon=assets/images/app.ico", - "package:linux": "electron-packager ./build --overwrite --platform=linux --arch=x64 --out=out", + "package:mac": "electron-packager ./build --overwrite --platform=darwin --arch=x64 --out=out --icon=src/assets/images/icon.ico --osx-sign.identity='Developer ID Application: GitHub' --extend-info=assets/mac/info.plist", + "package:win32": "electron-packager ./build --overwrite --platform=win32 --arch=ia32 --out=out --icon=src/assets/images/icon.ico", + "package:win64": "electron-packager ./build --overwrite --platform=win32 --arch=x64 --out=out --icon=src/assets/images/icon.ico", + "package:linux": "electron-packager ./build --overwrite --platform=linux --arch=x64 --out=out --icon=src/assets/images/icon.ico", "package:installer": "node ./script/installer.js", "release": "node ./script/release.js", "prepack": "check-for-leaks", diff --git a/src/assets/images/icon.ico b/src/assets/images/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..2badb377b41225a05d9caa1b10275c6ae2e5e596 GIT binary patch literal 2222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SdXZ@%Bq%^m087dhrP+BP<>LrLk78>Cym8yUmziu&hJU5qVlLN2yz2S zsZAt1=?@nNcx7a~F!}SJe)8g_=?{V!zN~vp9>^3jZ@;*j$;HLR#l^+N#l^+N#l^+N h#l^+N#pN>r@L%yG$x18@_SgUb002ovPDHLkV1i`u=-~hW literal 0 HcmV?d00001 diff --git a/src/index.js b/src/index.js index 9cd4d7d..e217e45 100644 --- a/src/index.js +++ b/src/index.js @@ -2,19 +2,54 @@ require('update-electron-app')({ logger: require('electron-log') }) +const updateCheckInterval = 1000 * 60 + const path = require('path') -const {app, BrowserWindow} = require('electron') +const {app, BrowserWindow, autoUpdater} = require('electron') + +const server = 'https://update.jdsconsulting.net' +const url = `${server}/update/${process.platform}/${app.getVersion()}` + +autoUpdater.setFeedURL({url}) + +autoUpdater.checkForUpdates(); +setInterval(() => { + console.log("Checking for update..."); + autoUpdater.checkForUpdates(); +}, updateCheckInterval) + +autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { + console.log("Handling updates...") + const dialogOpts = { + type: 'info', + buttons: ['Restart', 'Later'], + title: 'Application Update', + message: process.platform === 'win32' ? releaseNotes : releaseName, + detail: 'A new version has been downloaded. Restart the application to apply the updates.' + } + + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) autoUpdater.quitAndInstall() + }) +}) + +autoUpdater.on('error', message => { + console.error('There was a problem updating the application') + console.error(message) +}) + + const debug = /--debug/.test(process.argv[2]) -if (process.mas) app.setName('JDSfaulkner Portal') +if (process.mas) app.setName('JDS Consulting Portal') let mainWindow = null -function initialize () { +function initialize() { makeSingleInstance() - function createWindow () { + function createWindow() { const windowOptions = { width: 1080, minWidth: 769, @@ -69,7 +104,7 @@ function initialize () { // // Returns true if the current version of the app should quit instead of // launching. -function makeSingleInstance () { +function makeSingleInstance() { if (process.mas) return app.requestSingleInstanceLock()