Skip to content

Commit 52d2195

Browse files
committed
fix: the app wasn't loading html when packaged
1 parent 5cc9747 commit 52d2195

File tree

6 files changed

+83
-79
lines changed

6 files changed

+83
-79
lines changed

main/background.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserWindow, app } from "electron";
1+
import { BrowserWindow, app, dialog } from "electron";
22
import serve from "electron-serve";
33
import createWindow from "./helpers/createWindow";
44
import getPort from "get-port";
@@ -24,8 +24,6 @@ app.name = name;
2424
let win: BrowserWindow;
2525

2626
if (app.isPackaged) {
27-
process.on("uncaughtException", console.log);
28-
2927
serve({ directory: "app" });
3028
} else {
3129
app.setPath("userData", `${app.getPath("userData")} (development)`);
@@ -56,7 +54,6 @@ async function _createWindow() {
5654
x: 10,
5755
y: 30,
5856
});
59-
6057
createServer(apiPort, async () => {
6158
if (app.isPackaged) {
6259
await win.loadURL(`app://./home.html?port=${apiPort}`);

main/helpers/createWindow.ts

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,88 @@
11
import {
2-
screen,
3-
BrowserWindow,
4-
BrowserWindowConstructorOptions,
5-
} from 'electron';
6-
import Store from 'electron-store';
2+
screen,
3+
BrowserWindow,
4+
BrowserWindowConstructorOptions,
5+
} from "electron";
6+
import Store from "electron-store";
7+
import { version } from "../../package.json";
78

8-
export default (windowName: string, options: BrowserWindowConstructorOptions): BrowserWindow => {
9-
const key = 'window-state';
10-
const name = `window-state-${windowName}`;
11-
const store = new Store({ name });
12-
const defaultSize = {
13-
width: options.width,
14-
height: options.height,
15-
};
16-
let state = {};
17-
let win: BrowserWindow;
9+
export default (
10+
windowName: string,
11+
options: BrowserWindowConstructorOptions
12+
): BrowserWindow => {
13+
const key = "window-state";
14+
const name = `window-state-${windowName}`;
15+
// @ts-ignore
16+
const store = new Store({ name, projectVersion: version });
17+
const defaultSize = {
18+
width: options.width,
19+
height: options.height,
20+
};
21+
let state = {};
22+
let win: BrowserWindow;
1823

19-
const restore = () => store.get(key, defaultSize);
24+
const restore = () => store.get(key, defaultSize);
2025

21-
const getCurrentPosition = () => {
22-
const position = win.getPosition();
23-
const size = win.getSize();
24-
return {
25-
x: position[0],
26-
y: position[1],
27-
width: size[0],
28-
height: size[1],
29-
};
30-
};
26+
const getCurrentPosition = () => {
27+
const position = win.getPosition();
28+
const size = win.getSize();
29+
return {
30+
x: position[0],
31+
y: position[1],
32+
width: size[0],
33+
height: size[1],
34+
};
35+
};
3136

32-
const windowWithinBounds = (windowState: any, bounds: any) => {
33-
return (
34-
windowState.x >= bounds.x &&
35-
windowState.y >= bounds.y &&
36-
windowState.x + windowState.width <= bounds.x + bounds.width &&
37-
windowState.y + windowState.height <= bounds.y + bounds.height
38-
);
39-
};
37+
const windowWithinBounds = (windowState: any, bounds: any) => {
38+
return (
39+
windowState.x >= bounds.x &&
40+
windowState.y >= bounds.y &&
41+
windowState.x + windowState.width <= bounds.x + bounds.width &&
42+
windowState.y + windowState.height <= bounds.y + bounds.height
43+
);
44+
};
4045

41-
const resetToDefaults = () => {
42-
const bounds = screen.getPrimaryDisplay().bounds;
43-
return Object.assign({}, defaultSize, {
44-
x: (bounds.width - defaultSize.width) / 2,
45-
y: (bounds.height - defaultSize.height) / 2,
46-
});
47-
};
46+
const resetToDefaults = () => {
47+
const bounds = screen.getPrimaryDisplay().bounds;
48+
return Object.assign({}, defaultSize, {
49+
x: (bounds.width - defaultSize.width) / 2,
50+
y: (bounds.height - defaultSize.height) / 2,
51+
});
52+
};
4853

49-
const ensureVisibleOnSomeDisplay = (windowState: any) => {
50-
const visible = screen.getAllDisplays().some(display => {
51-
return windowWithinBounds(windowState, display.bounds);
52-
});
53-
if (!visible) {
54-
// Window is partially or fully not visible now.
55-
// Reset it to safe defaults.
56-
return resetToDefaults();
57-
}
58-
return windowState;
59-
};
54+
const ensureVisibleOnSomeDisplay = (windowState: any) => {
55+
const visible = screen.getAllDisplays().some((display) => {
56+
return windowWithinBounds(windowState, display.bounds);
57+
});
58+
if (!visible) {
59+
// Window is partially or fully not visible now.
60+
// Reset it to safe defaults.
61+
return resetToDefaults();
62+
}
63+
return windowState;
64+
};
6065

61-
const saveState = () => {
62-
if (!win.isMinimized() && !win.isMaximized()) {
63-
Object.assign(state, getCurrentPosition());
64-
}
65-
store.set(key, state);
66-
};
66+
const saveState = () => {
67+
if (!win.isMinimized() && !win.isMaximized()) {
68+
Object.assign(state, getCurrentPosition());
69+
}
70+
store.set(key, state);
71+
};
6772

68-
state = ensureVisibleOnSomeDisplay(restore());
73+
state = ensureVisibleOnSomeDisplay(restore());
6974

70-
const browserOptions: BrowserWindowConstructorOptions = {
71-
...options,
72-
...state,
73-
webPreferences: {
74-
nodeIntegration: true,
75-
...options.webPreferences,
76-
},
77-
};
78-
win = new BrowserWindow(browserOptions);
75+
const browserOptions: BrowserWindowConstructorOptions = {
76+
...options,
77+
...state,
78+
webPreferences: {
79+
nodeIntegration: true,
80+
...options.webPreferences,
81+
},
82+
};
83+
win = new BrowserWindow(browserOptions);
7984

80-
win.on('close', saveState);
85+
win.on("close", saveState);
8186

82-
return win;
87+
return win;
8388
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "moose",
33
"description": "A torrent client to stream and download torrents. Play music, view images and stream videos.",
4-
"version": "0.4.0",
4+
"version": "0.4.2",
55
"author": {
66
"name": "Ritesh Kumar"
77
},

renderer/utils/store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import Store from "electron-store";
2-
import { name } from "../../package.json";
2+
import { name, version } from "../../package.json";
33
import { sampleMagnets } from "../../sample/results";
44
import { remote, app } from "electron";
55
import { getDefaultColor } from "@utils/theme";
66

77
const store: Store = new Store({
88
name,
9+
// @ts-ignore
10+
projectVersion: version,
911
defaults: {
1012
torrents: sampleMagnets,
1113
descriptions: {},
@@ -14,7 +16,7 @@ const store: Store = new Store({
1416
wasDarkMode: remote.nativeTheme.shouldUseDarkColors,
1517
},
1618
migrations: {
17-
"0.4.1": (store) => store.reset("color"),
19+
"0.4.0": (store) => store.reset("color"),
1820
},
1921
});
2022

scripts/notarize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { notarize } = require("electron-notarize");
33

44
exports.default = async function notarizing(context) {
55
const { electronPlatformName, appOutDir } = context;
6-
if (electronPlatformName !== "darwin") {
6+
if (electronPlatformName !== "darwin" || !process.env.CI) {
77
return;
88
}
99

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moose-www",
3-
"version": "0.4.0",
3+
"version": "0.4.2",
44
"main": "index.js",
55
"author": "Ritesh Kumar",
66
"license": "MIT",

0 commit comments

Comments
 (0)