Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
release: 3.15.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Apr 20, 2022
1 parent 2d58b44 commit 89fa631
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 244 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta
http-equiv="Content-Security-Policy"
content="
default-src 'self';
default-src 'self' blob:;
script-src 'self' 'unsafe-eval';
worker-src blob:;
connect-src * data:;
Expand Down
52 changes: 29 additions & 23 deletions app/javascripts/main/extServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,39 @@ export function normalizeFilePath(requestUrl: string, host: string): string {
}
}

async function handleRequest(req: IncomingMessage, res: ServerResponse) {
async function handleRequest(request: IncomingMessage, response: ServerResponse) {
try {
if (!req.url) throw new Error('No url.');
if (!req.headers.host) throw new Error('No `host` header.');
if (!request.url) throw new Error('No url.');
if (!request.headers.host) throw new Error('No `host` header.');

const filePath = normalizeFilePath(request.url, request.headers.host);

const filePath = normalizeFilePath(req.url, req.headers.host);
const stat = await fs.promises.lstat(filePath);

if (!stat.isFile()) {
throw new Error('Client requested something that is not a file.');
}
const ext = path.parse(filePath).ext;
const mimeType = mime.lookup(ext);
res.setHeader('Content-Type', `${mimeType}; charset=utf-8`);
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
});
const stream = fs.createReadStream(filePath);
stream.on('error', (error: Error) => onRequestError(error, res));
stream.on('end', () => {
res.end();
});
stream.pipe(res);

const mimeType = mime.lookup(path.parse(filePath).ext);

response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Cache-Control', 'max-age=604800');
response.setHeader('Content-Type', `${mimeType}; charset=utf-8`);

const data = fs.readFileSync(filePath);

response.writeHead(200);

response.end(data);
} catch (error: any) {
onRequestError(error, res);
onRequestError(error, response);
}
}

function onRequestError(error: Error | { code: string }, res: ServerResponse) {
function onRequestError(error: Error | { code: string }, response: ServerResponse) {
let responseCode: number;
let message: string;

if ('code' in error && error.code === FileDoesNotExist) {
responseCode = 404;
message = str().missingExtension;
Expand All @@ -79,17 +82,20 @@ function onRequestError(error: Error | { code: string }, res: ServerResponse) {
responseCode = 500;
message = str().unableToLoadExtension;
}
res.writeHead(responseCode);
res.write(message);
res.end();

response.writeHead(responseCode);
response.end(message);
}

export function createExtensionsServer(): string {
const port = 45653;
const ip = '127.0.0.1';
const host = `${Protocol}://${ip}:${port}`;
http.createServer(handleRequest).listen(port, ip, () => {
const initCallback = () => {
log(`Server started at ${host}`);
});
};

http.createServer(handleRequest).listen(port, ip, initCallback);

return host;
}
9 changes: 7 additions & 2 deletions app/javascripts/main/networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function downloadFile(url: string, filePath: string): Promise<void>
);
}

export async function getJSON<T>(url: string): Promise<T> {
export async function getJSON<T>(url: string): Promise<T | undefined> {
const response = await get(url);
let data = '';
return new Promise((resolve, reject) => {
Expand All @@ -44,7 +44,12 @@ export async function getJSON<T>(url: string): Promise<T> {
})
.on('error', reject)
.on('end', () => {
resolve(JSON.parse(data));
try {
const parsed = JSON.parse(data);
resolve(parsed);
} catch (error) {
resolve(undefined);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascripts/main/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async function checkForUpdate(
return;
}

const latestJson = (await getJSON(latestUrl)) as PackageInfo;
const latestJson = await getJSON<PackageInfo>(latestUrl);
if (!latestJson) {
return;
}
Expand Down
8 changes: 6 additions & 2 deletions app/javascripts/main/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ export async function checkForUpdate(
if (state.enableAutoUpdate || userTriggered) {
state.setCheckingForUpdate(true);
try {
const { updateInfo } = await autoUpdater.checkForUpdates();
state.checkedForUpdate(updateInfo.version);
const result = await autoUpdater.checkForUpdates();
if (!result) {
return;
}

state.checkedForUpdate(result.updateInfo.version);

if (userTriggered) {
let message;
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Standard Notes",
"description": "An end-to-end encrypted notes app for digitalists and professionals.",
"author": "Standard Notes <[email protected]>",
"version": "3.14.1",
"version": "3.15.0-beta.1",
"main": "./dist/index.js",
"dependencies": {
"keytar": "^7.9.0",
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "standard-notes",
"main": "./app/dist/index.js",
"version": "3.14.1",
"version": "3.15.0-beta.1",
"repository": {
"type": "git",
"url": "git://github.com/standardnotes/desktop"
Expand Down Expand Up @@ -33,36 +33,36 @@
"compare-versions": "^4.1.3",
"decrypt": "github:standardnotes/decrypt#master",
"electron-log": "^4.4.6",
"electron-updater": "^4.6.5",
"fs-extra": "^10.0.1",
"electron-updater": "^5.0.1",
"fs-extra": "^10.1.0",
"mime-types": "^2.1.35",
"mobx": "^6.5.0"
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@commitlint/config-conventional": "^16.2.1",
"@electron/remote": "^2.0.8",
"@standardnotes/electron-clear-data": "1.1.1",
"@types/lodash": "^4.14.180",
"@types/lodash": "^4.14.182",
"@types/mime-types": "^2.1.1",
"@types/node": "^17.0.23",
"@types/node": "^17.0.25",
"@types/proxyquire": "^1.3.28",
"@types/yauzl": "^2.9.2",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"ava": "^4.1.0",
"@types/yauzl": "^2.10.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"ava": "^4.2.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.4",
"babel-loader": "^8.2.5",
"commitlint": "^16.2.3",
"copy-webpack-plugin": "^10.2.4",
"dotenv": "^16.0.0",
"electron": "17.2.0",
"electron-builder": "22.14.13",
"electron": "18.0.4",
"electron-builder": "23.0.3",
"electron-notarize": "^1.2.1",
"eslint": "^8.11.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"file-loader": "^6.2.0",
Expand All @@ -71,14 +71,14 @@
"mime-types": "^2.1.35",
"npm-run-all": "^4.1.5",
"pre-push": "^0.1.2",
"prettier": "^2.6.0",
"prettier": "^2.6.2",
"proxyquire": "^2.1.3",
"rimraf": "^3.0.2",
"terser-webpack-plugin": "^5.3.1",
"ts-loader": "^9.2.8",
"ts-node": "^10.7.0",
"typescript": "^4.6.2",
"webpack": "^5.70.0",
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-merge": "^5.8.0"
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ const TargetGroups = {
Targets.Windows,
],
[MainstreamTargetGroup]: [
Targets.Windows,
Targets.AppimageAll,
Targets.Deb,
Targets.Snap,
Targets.DebArm64,
Targets.MacAll,
Targets.Snap,
Targets.Windows,
],
};

Expand Down
2 changes: 1 addition & 1 deletion web
Submodule web updated from 03f707 to 7dae48
Loading

0 comments on commit 89fa631

Please sign in to comment.