Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e611a36

Browse files
committed
manual auto update
1 parent a33fa3c commit e611a36

2 files changed

Lines changed: 86 additions & 10 deletions

File tree

src/src/modules/update.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import _ from "lodash";
2+
import Utils from "./utils";
23
import Prefix from "./prefix";
34
import FileSystem from "./file-system";
45
import Network from "./network";
56

7+
const child_process = require('child_process');
8+
69
export default class Update {
710

8-
version = '1.4.10';
11+
version = '1.4.11';
912

1013
/**
1114
* @type {string}
@@ -128,4 +131,76 @@ export default class Update {
128131
return _.trimStart(last.tag_name, 'v');
129132
});
130133
}
134+
135+
/**
136+
* @return {Promise<void>}
137+
*/
138+
updateSelf() {
139+
let startFile = this.prefix.getBinDir() + '/start';
140+
let updateFile = this.prefix.getCacheDir() + '/start';
141+
let updateScriptFile = this.prefix.getCacheDir() + '/update.sh';
142+
143+
if (!this.fs.exists(startFile)) {
144+
startFile = this.prefix.getRootDir() + '/start';
145+
}
146+
147+
if (!this.fs.exists(startFile)) {
148+
return Promise.resolve();
149+
}
150+
151+
if (this.fs.exists(updateFile)) {
152+
this.fs.rm(updateFile);
153+
}
154+
155+
const updateScript = `#!/usr/bin/env sh
156+
157+
processPid=${window.process.pid}
158+
startFile="${startFile}"
159+
updateFile="${updateFile}"
160+
iterator=0
161+
162+
while [ "$(ps -p $processPid -o comm=)" != "" ]; do
163+
sleep 1
164+
iterator=$((iterator + 1))
165+
166+
if [ $iterator -gt 120 ]; then
167+
echo "Error update, exit."
168+
exit
169+
fi
170+
171+
echo "Waiting for process to complete"
172+
done
173+
174+
rm -rf "$startFile"
175+
mv "$updateFile" "$startFile"
176+
chmod +x "$startFile"
177+
178+
"$startFile" &
179+
rm -rf "${updateScriptFile}"`;
180+
181+
let promise = this.getRemoteVersion().then(() => this.data);
182+
183+
return promise.then((data) => {
184+
let last = _.head(data);
185+
last = _.head(last.assets);
186+
187+
return this.network.download(last.browser_download_url, updateFile)
188+
.then(() => {
189+
this.fs.filePutContents(updateScriptFile, updateScript);
190+
this.fs.chmod(updateScriptFile);
191+
192+
try {
193+
const child = child_process.spawn(updateScriptFile, [], {
194+
detached: true,
195+
stdio: ['ignore']
196+
});
197+
198+
child.unref();
199+
} catch (e) {
200+
}
201+
202+
return Utils.sleep(1000).then(() => window.app.getSystem().closeApp());
203+
});
204+
});
205+
}
131206
}

src/src/views/Update.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
<div class="panel-body">
55
<h4>Wine Launcher</h4>
66
<template v-if="remote_version">
7-
<p class="text-muted">
8-
<span v-if="(remote_version === version)" class="label label-success">
9-
{{ $t('update.latest') }}
10-
</span>
7+
<ButtonLoading v-if="(remote_version !== version)" :title="$t('labels.update')"
8+
:promiseCallback="updateSelf"/>
9+
10+
<p class="text-muted m-t-10">
11+
<span v-if="(remote_version === version)" class="label label-success">
12+
{{ $t('update.latest') }}
13+
</span>
1114
<span v-else class="label label-warning">{{ $t('update.found') }}</span>
1215
</p>
1316
</template>
@@ -17,11 +20,6 @@
1720

1821
<template v-if="remote_version && (remote_version !== version)">
1922
{{ $t('update.current-version') }}: {{remote_version}}
20-
(
21-
<a class="link" @click.prevent="openUrl('https://github.com/hitman249/wine-launcher/releases')">
22-
{{ $t('update.download-update') }}
23-
</a>
24-
)
2523
</template>
2624
</p>
2725
</div>
@@ -99,6 +97,9 @@
9997
return this.$store.dispatch(action.get('prefix').LOAD);
10098
});
10199
},
100+
updateSelf() {
101+
return window.app.getUpdate().updateSelf();
102+
},
102103
},
103104
computed: {
104105
version() {

0 commit comments

Comments
 (0)