Skip to content

Commit 58145c3

Browse files
committed
Start supporting autoUpdate 😍
1 parent e68ff81 commit 58145c3

File tree

7 files changed

+367
-233
lines changed

7 files changed

+367
-233
lines changed

o-ri/launchy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
2+
#
3+
# This file was generated by RubyGems.
4+
#
5+
# The application 'launchy' is installed as part of a gem, and
6+
# this file is here to facilitate running it.
7+
#
8+
9+
require 'rubygems'
10+
11+
version = ">= 0.a"
12+
13+
if ARGV.first
14+
str = ARGV.first
15+
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16+
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17+
version = $1
18+
ARGV.shift
19+
end
20+
end
21+
22+
if Gem.respond_to?(:activate_bin_path)
23+
load Gem.activate_bin_path('launchy', 'launchy', version)
24+
else
25+
gem "launchy", version
26+
load Gem.bin_path("launchy", "launchy", version)
27+
end

o-ri/travis

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
2+
#
3+
# This file was generated by RubyGems.
4+
#
5+
# The application 'travis' is installed as part of a gem, and
6+
# this file is here to facilitate running it.
7+
#
8+
9+
require 'rubygems'
10+
11+
version = ">= 0.a"
12+
13+
if ARGV.first
14+
str = ARGV.first
15+
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16+
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17+
version = $1
18+
ARGV.shift
19+
end
20+
end
21+
22+
if Gem.respond_to?(:activate_bin_path)
23+
load Gem.activate_bin_path('travis', 'travis', version)
24+
else
25+
gem "travis", version
26+
load Gem.bin_path("travis", "travis", version)
27+
end

src/main/autoUpdater.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { autoUpdater } from "electron-updater";
2+
import log from "electron-log";
3+
4+
export const electronUpdater = win => {
5+
autoUpdater.logger = log;
6+
autoUpdater.logger.transports.file.level = "info";
7+
log.info("App starting...");
8+
9+
function sendStatusToWindow(text) {
10+
log.info(text);
11+
win.webContents.send("message", text);
12+
}
13+
14+
autoUpdater.on("checking-for-update", () => {
15+
sendStatusToWindow("Checking for update...");
16+
});
17+
autoUpdater.on("update-available", info => {
18+
sendStatusToWindow("Update available.");
19+
});
20+
autoUpdater.on("update-not-available", info => {
21+
sendStatusToWindow("Update not available.");
22+
});
23+
autoUpdater.on("error", err => {
24+
sendStatusToWindow("Error in auto-updater. " + err);
25+
});
26+
autoUpdater.on("download-progress", progressObj => {
27+
let log_message = "Download speed: " + progressObj.bytesPerSecond;
28+
log_message = log_message + " - Downloaded " + progressObj.percent + "%";
29+
log_message =
30+
log_message +
31+
" (" +
32+
progressObj.transferred +
33+
"/" +
34+
progressObj.total +
35+
")";
36+
sendStatusToWindow(log_message);
37+
});
38+
autoUpdater.on("update-downloaded", info => {
39+
sendStatusToWindow("Update downloaded");
40+
});
41+
};

src/main/createWindow.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { BrowserWindow } from "electron";
2+
import * as path from "path";
3+
import { format as formatUrl } from "url";
4+
import { callRenderer } from "electron-better-ipc";
5+
const isDevelopment = process.env.NODE_ENV !== "production";
6+
7+
export const createMainWindow = mainWindow => {
8+
const window = new BrowserWindow({
9+
width: 1024,
10+
height: 768,
11+
minWidth: 1024,
12+
minHeight: 768,
13+
/*
14+
only setting minWidth or minHeight doesn't work, have to set width & height too
15+
also setting one of minWidth or minHeight doesn't work, have to set both minWidth & minHeight
16+
*/
17+
title: "WIP Desktop",
18+
frame: false,
19+
icon: path.join(__dirname, "../../build/icon.png")
20+
});
21+
22+
if (isDevelopment) {
23+
window.webContents.openDevTools();
24+
}
25+
26+
if (isDevelopment) {
27+
window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
28+
} else {
29+
window.loadURL(
30+
formatUrl({
31+
pathname: path.join(__dirname, "../renderer/index.html"),
32+
protocol: "file",
33+
slashes: true
34+
})
35+
);
36+
}
37+
38+
window.on("closed", () => {
39+
mainWindow = null;
40+
});
41+
42+
window.webContents.on("devtools-opened", () => {
43+
window.focus();
44+
setImmediate(() => {
45+
window.focus();
46+
});
47+
});
48+
49+
window.on("blur", async () => {
50+
await callRenderer(window, "window-blur", "true");
51+
});
52+
53+
window.on("focus", async () => {
54+
await callRenderer(window, "window-blur", "false");
55+
});
56+
57+
return window;
58+
};

0 commit comments

Comments
 (0)