-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathFeature_AutoUpdate.re
128 lines (111 loc) · 3.02 KB
/
Feature_AutoUpdate.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
open Oni_Core;
type model = {
automaticallyChecksForUpdates: bool,
releaseChannel: string,
};
let initial = {
automaticallyChecksForUpdates: true,
releaseChannel: Oni_Core.BuildInfo.defaultUpdateChannel,
};
[@deriving show({with_path: false})]
type command =
| CheckForUpdates;
[@deriving show({with_path: false})]
type msg =
| Service(Service_AutoUpdate.msg)
| Command(command);
type outmsg =
| Nothing
| Effect(Isolinear.Effect.t(msg));
let platformStr =
switch (Revery.Environment.os) {
| Mac => "macos"
| Linux => "linux"
| Windows => "windows"
| _ => ""
};
module Configuration = {
open Config.Schema;
let automaticallyChecksForUpdates =
setting("oni.app.automaticallyChecksForUpdates", bool, ~default=true);
let releaseChannelCodec =
custom(~decode=Json.Decode.(string), ~encode=Json.Encode.(string));
let releaseChannel =
setting(
"oni.app.updateReleaseChannel",
releaseChannelCodec,
~default=Oni_Core.BuildInfo.defaultUpdateChannel,
);
};
module Commands = {
open Feature_Commands.Schema;
let checkForUpdates =
define(
~category="Auto-Update",
~title="Check for updates",
"oni.app.checkForUpdates",
Command(CheckForUpdates),
);
};
module Contributions = {
let configuration = [
Configuration.automaticallyChecksForUpdates.spec,
Configuration.releaseChannel.spec,
];
let commands = Commands.[checkForUpdates];
};
let sub = (~config) => {
let automaticallyChecksForUpdates =
Configuration.automaticallyChecksForUpdates.get(config);
let releaseChannel = Configuration.releaseChannel.get(config);
Service_AutoUpdate.Sub.autoUpdate(
~uniqueId="autoUpdate",
~releaseChannel,
~automaticallyChecksForUpdates,
)
|> Isolinear.Sub.map(msg => Service(msg));
};
let update = (~getLicenseKey, model, msg) =>
switch (msg) {
| Service(AutoCheckChanged(automaticallyChecksForUpdates)) => (
{...model, automaticallyChecksForUpdates},
Effect(
Service_AutoUpdate.Effect.setAutomaticallyChecksForUpdates(
~updater=Oni2_Sparkle.Updater.getInstance(),
~automaticallyChecksForUpdates,
),
),
)
| Service(ReleaseChannelChanged(releaseChannel)) =>
let newModel = {...model, releaseChannel};
(
newModel,
Effect(
Service_AutoUpdate.Effect.setFeed(
~updater=Oni2_Sparkle.Updater.getInstance(),
~licenseKey=getLicenseKey(),
~releaseChannel=newModel.releaseChannel,
~platform=platformStr,
),
),
);
| Service(LicenseKeyChanged(licenseKey)) => (
model,
Effect(
Service_AutoUpdate.Effect.setFeed(
~updater=Oni2_Sparkle.Updater.getInstance(),
~licenseKey,
~releaseChannel=model.releaseChannel,
~platform=platformStr,
),
),
)
| Command(CheckForUpdates) => (
model,
Effect(
Service_AutoUpdate.Effect.checkForUpdates(
~updater=Oni2_Sparkle.Updater.getInstance(),
),
),
)
};