File tree Expand file tree Collapse file tree 4 files changed +23
-17
lines changed
Expand file tree Collapse file tree 4 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use std::ffi::{CStr, CString};
77use std:: os:: raw:: c_char;
88use std:: sync:: Mutex ;
99
10+ use crate :: device_id;
1011use crate :: dirs;
1112
1213use android_logger:: Config ;
@@ -111,6 +112,7 @@ pub mod android {
111112 let server_state = endpoints:: ServerState {
112113 datastore : Mutex :: new ( openDatastore ( ) ) ,
113114 asset_path : PathBuf :: from ( asset_path) ,
115+ device_id : device_id:: get_device_id ( ) ,
114116 } ;
115117
116118 let mut config = AWConfig :: default ( ) ;
Original file line number Diff line number Diff line change 1+ use std:: fs;
2+
3+ use uuid:: Uuid ;
4+
5+ use crate :: dirs;
6+
7+ /// Retrieves the device ID, if none exists it generates one (using UUID v4)
8+ pub fn get_device_id ( ) -> String {
9+ // I chose get_data_dir over get_config_dir since the latter isn't yet supported on Android.
10+ let mut path = dirs:: get_data_dir ( ) . unwrap ( ) ;
11+ path. push ( "device_id" ) ;
12+ if path. exists ( ) {
13+ fs:: read_to_string ( path) . unwrap ( )
14+ } else {
15+ let uuid = Uuid :: new_v4 ( ) . to_hyphenated ( ) . to_string ( ) ;
16+ fs:: write ( path, & uuid) . unwrap ( ) ;
17+ uuid
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ extern crate toml;
3131#[ macro_use]
3232pub mod macros;
3333pub mod config;
34+ pub mod device_id;
3435pub mod dirs;
3536pub mod endpoints;
3637pub mod logging;
Original file line number Diff line number Diff line change @@ -4,10 +4,8 @@ extern crate getopts;
44
55use getopts:: Options ;
66use rocket:: config:: Environment ;
7- use uuid:: Uuid ;
87
98use std:: env;
10- use std:: fs;
119
1210use aw_server:: * ;
1311
@@ -22,20 +20,6 @@ fn print_usage(program: &str, opts: Options) {
2220 print ! ( "{}" , opts. usage( & brief) ) ;
2321}
2422
25- /// Retrieves the device ID, if none exists it generates one (using UUID v4)
26- fn get_device_id ( ) -> String {
27- // I chose get_data_dir over get_config_dir since the latter isn't yet supported on Android.
28- let mut path = dirs:: get_data_dir ( ) . unwrap ( ) ;
29- path. push ( "device_id" ) ;
30- if path. exists ( ) {
31- fs:: read_to_string ( path) . unwrap ( )
32- } else {
33- let uuid = Uuid :: new_v4 ( ) . to_hyphenated ( ) . to_string ( ) ;
34- fs:: write ( path, & uuid) . unwrap ( ) ;
35- uuid
36- }
37- }
38-
3923fn main ( ) {
4024 use std:: sync:: Mutex ;
4125
@@ -84,7 +68,7 @@ fn main() {
8468 // it will not happen there
8569 datastore : Mutex :: new ( aw_datastore:: Datastore :: new ( db_path, true ) ) ,
8670 asset_path,
87- device_id : get_device_id ( ) ,
71+ device_id : device_id :: get_device_id ( ) ,
8872 } ;
8973
9074 endpoints:: build_rocket ( server_state, config) . launch ( ) ;
You can’t perform that action at this time.
0 commit comments