-
Notifications
You must be signed in to change notification settings - Fork 20
/
appv2.js
187 lines (179 loc) · 6.55 KB
/
appv2.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import {AppContext} from './v2/appcontext.js'
const back = chrome.extension.getBackgroundPage();
class AppLoader{
static get AppHelperMedia(){
return (async()=>(await import("./v2/media/apphelpermedia.js")).AppHelperMedia)();
}
static get AppHelperFiles(){
return (async()=>(await import("./v2/files/apphelperfiles.js")).AppHelperFiles)();
}
static get ControlMediaInfos(){
return (async()=>(await import("./v2/media/controlmediainfo.js")).ControlMediaInfos)();
}
static get MediaInfos(){
return (async()=>(await import("./v2/media/mediainfo.js")).MediaInfos)();
}
static get UtilDOM(){
return (async()=>(await import("./v2/utildom.js")).UtilDOM)();
}
static get Device(){
return (async()=>(await import("./v2/device/device.js")).Device)();
}
static get Devices(){
return (async()=>(await import("./v2/device/device.js")).Devices)();
}
static get EventBus(){
return (async()=>(await import("./v2/eventbus.js")).EventBus)();
}
}
class ControlTop{
set loading(value){
setRefreshing(value);
}
}
class App{
async load(){
self.getAuthTokenPromise = () => back.getAuthTokenPromise();
await (await AppLoader.UtilDOM).addScriptFiles(
"/v2/util.js",
"/v2/utilweb.js",
"/v2/google/drive/googledrive.js",
"/v2/gcm/gcmbase.js",
"/v2/gcm/gcmmulti.js",
"/v2/db.js"
);
back.v2Stuff.EventBus = await AppLoader.EventBus;
const device = (await this.devicesFromDb).find(device=>device.canBrowseFiles() && device.deviceName == "Pixel 2");
const appHelperFiles = new (await AppLoader.AppHelperFiles)({app:new AppForFiles(),device});
await appHelperFiles.load();
(await AppLoader.UtilDOM).show(self.document.querySelector("#tab-filebrowser"));
const appHelperMedia = new (await AppLoader.AppHelperMedia)({app:new AppForMedia()});
appHelperMedia.load();
(await AppLoader.UtilDOM).show(self.document.querySelector("#tab-media"));
/*const codeGcmBase = await (await fetch("http://localhost:8080/v2/gcm/gcmbase.js")).text();
const split = codeGcmBase.split("class");
split.forEach(clazz => {
if(!clazz) return;
clazz = clazz.trim();
const className = clazz.substring(0,clazz.indexOf("{"));
self[className] = eval(`(class ${clazz})`);
});
(await AppLoader.UtilDOM).setCssVhVariableAndListenToWindowChanges();
const utilCode = await (await fetch("http://localhost:8080/v2/util.js")).text();
eval(utilCode);
const utilClassCode = utilCode.substring(utilCode.indexOf("class"));
self.Util = eval(`(${utilClassCode})`);
const utilWebCode = await (await fetch("http://localhost:8080/v2/utilweb.js")).text();
self.UtilWeb = eval(`(${utilWebCode})`);
const appHelperMedia = new AppHelperMedia(this);
await appHelperMedia.load();*/
}
get rootSelector(){}
async addElement(control,parent=null){
const render = await control.render();
if(!parent){
parent = self.document.querySelector(this.rootSelector);
}
parent.appendChild(render);
}
async getAuthToken(){
return await back.getAuthTokenPromise();
}
async getDevice(deviceId){
const devices = await this.devicesFromDb;
return devices.getDevice(deviceId);
}
get devicesFromDb(){
return (async () =>{
const Device = await AppLoader.Device;
const Devices = await AppLoader.Devices;
const array = back.devices.map(deviceRaw => Device.getDevice(deviceRaw))
return new Devices(array);
})();
}
storeObject(key,value){
AppContext.context.localStorage.setObject(key,value);
}
restoreObject(key){
return AppContext.context.localStorage.getObject(key);
}
store(key,value){
AppContext.context.localStorage.set(key,value);
}
restoreString(key){
return AppContext.context.localStorage.get(key);
}
restoreBoolean(key){
return AppContext.context.localStorage.getBoolean(key);
}
loadFcmClient(){
}
get controlTop(){
if(this._controlTop == null){
this._controlTop = new ControlTop();
}
return this._controlTop;
}
get token(){
return self.getAuthTokenPromise();
}
get back(){
return chrome.extension.getBackgroundPage();
}
get db(){
if(!this._db){
this._db = new Dexie("join_app");
this._db.version(6).stores({
devices: 'deviceId,json',
gcm:'gcmId,json',
smsThreads:'key,address,deviceId,json',
contacts:'key,number,deviceId,json',
smsConversations:'key,address,deviceId,json',
mediaInfos:'key,json'
});
}
return this._db;
}
}
class AppForMedia extends App{
get rootSelector(){
return "#media";
}
}
class AppForFiles extends App{
get rootSelector(){
return "#filebrowser";
}
}
// class AppHelperMedia{
// constructor(app){
// this.app = app;
// }
// onMediaButtonPressed(mediaButtonPressed){
// console.log(mediaButtonPressed);
// }
// async load(){
// (await AppLoader.EventBus).register(this);
// const MediaInfos = (await AppLoader.MediaInfos);
// const loader = MediaInfos.loader;
// const Device = (await AppLoader.Device);
// const deviceRaw = this.app.back.devices.find(device=>device.deviceName == "Pixel 3");
// const device = Device.getDevice(deviceRaw);
// device.canContactViaLocalNetwork = UtilsDevices.getLocalNetworkServerAddress(device);
// let mediaInfos = await loader.load({db:this.app.db,refresh:false,dbGoogleDriveArgs:{
// deviceId:device.deviceId,
// device,
// token: await this.app.token
// }});
// if(!mediaInfos){
// mediaInfos = new MediaInfos([],device);
// }
// const control = new (await AppLoader.ControlMediaInfos)([mediaInfos],()=>this.app.token);
// const rendered = await control.render();
// console.log(rendered);
// self.document.querySelector("#media").appendChild(rendered);
// (await AppLoader.UtilDOM).show(self.document.querySelector("#tab-media"));
// }
// }
// const app = new App();
// app.load();