-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
255 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
"use strict" | ||
|
||
let outDir = "dist/Onshape-darwin-x64"; | ||
require("rimraf")(outDir, function (error) { | ||
if (error != null) { | ||
throw new Error(error) | ||
} | ||
|
||
console.log(outDir) | ||
}) | ||
|
||
let packageJson = JSON.parse(require("fs").readFileSync("./package.json")) | ||
|
||
let packager = require("electron-packager") | ||
var version = "0.0.2" | ||
var version = packageJson.version | ||
packager({ | ||
dir: "out", | ||
out: "dist", | ||
name: "Onshape", | ||
platform: "darwin", | ||
arch: "x64", | ||
version: "0.36.0", | ||
version: packageJson.devDependencies["electron-prebuilt"].substring(1), | ||
icon: "build/icon.icns", | ||
asar: true, | ||
"app-version": version, | ||
"build-version": version, | ||
"app-bundle-id": "org.develar.onshape", | ||
"app-category-type": "public.app-category.graphics-design", | ||
}, function done (error, appPath) { if (error != null) throw new Error(error) }) | ||
sign: "Vladimir Krivosheev" | ||
}, function (error, appPath) { | ||
if (error != null) throw new Error(error) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
}, | ||
"win": { | ||
"title": "Onshape", | ||
"version": "0.0.1", | ||
"version": "0.2.0", | ||
"icon": "build/icon.ico" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
(function (): void { | ||
"use strict" | ||
|
||
const SERVICE_NAME = "org.develar.onshape" | ||
const LOCAL_STORAGE_LOGIN_KEY = SERVICE_NAME.replace('.', '_') + ".login" | ||
|
||
let passwordToSave: Credentials = null | ||
let maybeUrlChangedTimerId: any = null | ||
let foundFormElementTimerId: number = -1 | ||
let oldUrl: string = null | ||
|
||
require("electron").ipcRenderer.on("maybeUrlChanged", () => { maybeUrlChanged(true) }) | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
checkLocationAndSignInIfNeed() | ||
}) | ||
|
||
class Credentials { | ||
constructor(public login: string, public password: string) { | ||
} | ||
} | ||
|
||
function getInputElement(name: string) { | ||
return <HTMLInputElement>document.querySelector('input[name="' + name + '"]'); | ||
} | ||
|
||
function isNotEmpty(string: string) { | ||
// yep, get used to strict Java&Kotlin and cannot see code like (foo) | ||
return string != null && string.length != 0 | ||
} | ||
|
||
function setValue(input: HTMLInputElement, value: string) { | ||
input.value = value | ||
// we must trigger "change" event otherwise form is not submitted on click emulate (it seems, because angular (used in Onshape) doesn't detect changes immediately) | ||
input.dispatchEvent(new Event("change", {"bubbles": true})) | ||
} | ||
|
||
function fillAndSubmit(formElement: HTMLFormElement) { | ||
let login: string = localStorage.getItem(LOCAL_STORAGE_LOGIN_KEY) | ||
if (isNotEmpty(login)) { | ||
setValue(getInputElement("email"), login) | ||
|
||
let password = require("keytar").getPassword(SERVICE_NAME, login) | ||
if (isNotEmpty(password)) { | ||
setValue(getInputElement("password"), password); | ||
(<HTMLButtonElement>document.querySelector('div.os-form-btn-container > button[type="submit"')).click() | ||
return | ||
} | ||
} | ||
|
||
var superOnSubmit: any = formElement.onsubmit | ||
formElement.onsubmit = () => { | ||
passwordToSave = null | ||
if (superOnSubmit != null) { | ||
superOnSubmit() | ||
} | ||
|
||
let login = getInputElement("email").value | ||
let password = getInputElement("password").value | ||
if (isNotEmpty(login) && isNotEmpty(password)) { | ||
passwordToSave = new Credentials(login, password) | ||
} | ||
} | ||
} | ||
|
||
function fillOrWait() { | ||
let formElement = <HTMLFormElement>document.querySelector("form[name='osForm']") | ||
if (formElement != null) { | ||
console.log("form element found") | ||
fillAndSubmit(formElement) | ||
} | ||
else { | ||
console.log("form element not found, schedule") | ||
setTimeout(() => { | ||
checkLocationAndSignInIfNeed() | ||
}) | ||
} | ||
} | ||
|
||
function checkLocationAndSignInIfNeed() { | ||
let location = window.location | ||
if (location.host == "cad.onshape.com" && location.pathname == "/signin") { | ||
fillOrWait() | ||
} | ||
} | ||
|
||
function maybeUrlChanged(checkLater: boolean) { | ||
if (maybeUrlChangedTimerId != null) { | ||
clearTimeout(maybeUrlChangedTimerId) | ||
maybeUrlChangedTimerId = null | ||
} | ||
|
||
let newLocation = window.location | ||
let newUrl = newLocation.href | ||
if (oldUrl != newUrl) { | ||
try { | ||
console.log("url changed:", oldUrl, newUrl) | ||
urlChanged(oldUrl, newLocation) | ||
} | ||
finally { | ||
oldUrl = newUrl | ||
} | ||
} | ||
else if (checkLater) { | ||
// let's reschedule | ||
maybeUrlChangedTimerId = setTimeout(() => { maybeUrlChanged(false) }, 100) | ||
} | ||
} | ||
|
||
function urlChanged(oldUrl: string, newLocation: Location) { | ||
if (foundFormElementTimerId != -1) { | ||
clearTimeout(foundFormElementTimerId) | ||
} | ||
|
||
if (passwordToSave != null) { | ||
if (newLocation.host == "cad.onshape.com") | ||
if (oldUrl.endsWith("/signin") && newLocation.pathname != "/signup/forgotpassword") { | ||
localStorage.setItem(LOCAL_STORAGE_LOGIN_KEY, passwordToSave.login) | ||
require("keytar").replacePassword(SERVICE_NAME, passwordToSave.login, passwordToSave.password) | ||
} | ||
passwordToSave = null | ||
} | ||
else if (document.readyState != "loading") { | ||
checkLocationAndSignInIfNeed() | ||
} | ||
} | ||
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ declare module 'configstore' { | |
del(key: string): void; | ||
} | ||
|
||
export = ConfigStore; | ||
export = ConfigStore | ||
} |
Oops, something went wrong.