52
52
</template >
53
53
54
54
<script >
55
- import { computed } from " vue" ;
55
+ import { computed , defineComponent , ref } from " vue" ;
56
56
import {
57
57
IonApp ,
58
58
IonContent ,
@@ -68,10 +68,6 @@ import {
68
68
IonSelect ,
69
69
IonSelectOption ,
70
70
} from " @ionic/vue" ;
71
- /* eslint-disable no-unused-vars */
72
- import { defineComponent , ref } from " vue" ;
73
-
74
- import { useRoute } from " vue-router" ;
75
71
import {
76
72
playCircleOutline ,
77
73
cogOutline ,
@@ -80,11 +76,10 @@ import {
80
76
} from " ionicons/icons" ;
81
77
import { getPlatforms } from " @ionic/vue" ;
82
78
import { App } from " @capacitor/app" ;
83
-
84
79
import { useStore } from " vuex" ;
85
- import { apiInstance } from " ./api" ;
86
- import appInfo from " ./verinfo" ;
80
+
87
81
import { AndroindIntentActions } from " ./enums" ;
82
+ import { apiInstance } from " ./api" ;
88
83
89
84
export default defineComponent ({
90
85
name: " App" ,
@@ -104,18 +99,11 @@ export default defineComponent({
104
99
IonSelectOption,
105
100
},
106
101
setup () {
107
- // // Capacitor SQLite and Jeep init
108
- // // const app = getCurrentInstance();
109
- // // if (app != null) {
110
- // // app.appContext.config.globalProperties.$sqlite = useSQLite();
111
- // // }
112
- // // const sqlite = app?.appContext.config.globalProperties.$sqlite;
113
102
const store = useStore ();
114
- const route = useRoute ();
115
103
const platforms = getPlatforms ();
116
104
const selectedPageIndex = ref (0 );
117
105
118
- /*
106
+ /*
119
107
Side menu handler
120
108
*/
121
109
const appPages = [
@@ -159,15 +147,109 @@ export default defineComponent({
159
147
" settings/setCurrentServer" ,
160
148
store .getters [" settings/currentServerId" ]
161
149
);
162
- // console.log("Get status");
163
- // apiInstance.get("/status").then((response) => {
164
- // store.commit("simpleapi/setPlayerData", response.data);
165
- // console.log(response.data);
166
- // });
167
- // store.dispatch("simpleapi/setPlaybackRefreshInterval");
150
+
151
+ if (platforms .includes (" hybrid" )) {
152
+ console .log (" Registering indent" );
153
+ registerBroadcastReceiver ();
154
+ window .plugins .intentShim .onIntent ((intent ) => {
155
+ handleIntent (intent);
156
+ });
157
+ }
168
158
};
169
159
170
- initApp ();
160
+ /*
161
+ Handling of Android intents.
162
+ */
163
+ const handleSendIntent = async (intent ) => {
164
+ intent .clipItems .forEach ((el ) => {
165
+ apiInstance .post (" playlist" , {
166
+ filename: el .text ,
167
+ flag: " append-play" ,
168
+ });
169
+ });
170
+ };
171
+ const handleViewIntent = async (intent ) => {
172
+ let headerArray = [];
173
+ if (Object .prototype .hasOwnProperty .call (intent .extras , " headers" )) {
174
+ for (var i = 0 ; i < intent .extras .headers .length - 1 ; i += 2 ) {
175
+ headerArray .push (
176
+ ` ${ intent .extras .headers [i]} : ${ intent .extras .headers [i + 1 ]} `
177
+ );
178
+ }
179
+ }
180
+ if (Object .prototype .hasOwnProperty .call (intent, " data" )) {
181
+ let reqData = {
182
+ filename: intent .data ,
183
+ flag: " replace" ,
184
+ };
185
+ reqData[" file-local-options" ] = {};
186
+ if (headerArray .length > 0 )
187
+ reqData[" file-local-options" ][" http-header-fields" ] = headerArray;
188
+ if (Object .prototype .hasOwnProperty .call (intent .extras , " title" ))
189
+ reqData[" file-local-options" ][" force-media-title" ] =
190
+ intent .extras .title ;
191
+ apiInstance .post (" playlist" , reqData);
192
+ }
193
+ };
194
+ const handleIntent = async (intent ) => {
195
+ // console.log("Full intent object" + JSON.stringify(intent));
196
+ if (Object .prototype .hasOwnProperty .call (intent, " action" )) {
197
+ switch (intent .action ) {
198
+ case AndroindIntentActions .SEND :
199
+ handleSendIntent (intent);
200
+ break ;
201
+ case AndroindIntentActions .VIEW :
202
+ handleViewIntent (intent);
203
+ break ;
204
+ default :
205
+ break ;
206
+ }
207
+ }
208
+ };
209
+ const registerBroadcastReceiver = () => {
210
+ window .plugins .intentShim .registerBroadcastReceiver (
211
+ {
212
+ filterActions: [
213
+ " com.darryncampbell.cordova.plugin.broadcastIntent.ACTION" ,
214
+ ],
215
+ },
216
+ (intent ) => {
217
+ // Broadcast received
218
+ handleIntent (intent);
219
+ }
220
+ );
221
+ };
222
+ const unregisterBroadcastReceiver = () => {
223
+ window .plugins .intentShim .unregisterBroadcastReceiver ();
224
+ };
225
+
226
+ // Listeners
227
+ if (! platforms .includes (" hybrid" )) initApp ();
228
+ document .addEventListener (" deviceReady" , () => initApp ());
229
+ window .addEventListener (" orientationchange" , function () {
230
+ store .commit (" app/setScreenOrinetation" , screen .orientation .type );
231
+ });
232
+ App .addListener (" appStateChange" , async ({ isActive }) => {
233
+ if (isActive) {
234
+ // Set screen orientation if active
235
+ store .commit (" app/setScreenOrinetation" , screen .orientation .type );
236
+ apiInstance .get (" /status" ).then ((response ) => {
237
+ store .commit (" simpleapi/setPlayerData" , response .data );
238
+ });
239
+
240
+ if (! store .state .simpleapi .playbackRefreshInterval )
241
+ store .dispatch (" simpleapi/setPlaybackRefreshInterval" );
242
+ if (! store .state .settings .dbSession )
243
+ await store .dispatch (" settings/initDbSession" );
244
+
245
+ if (platforms .includes (" hybrid" )) registerBroadcastReceiver ();
246
+ } else {
247
+ // Battery saving stuff
248
+ store .commit (" simpleapi/clearPlaybackRefreshInterval" );
249
+ await store .dispatch (" settings/closeDbConnection" );
250
+ if (platforms .includes (" hybrid" )) unregisterBroadcastReceiver ();
251
+ }
252
+ });
171
253
return {
172
254
selectedPageIndex,
173
255
appPages,
@@ -178,134 +260,6 @@ export default defineComponent({
178
260
setCurrentServer : (serverId ) =>
179
261
store .dispatch (" settings/setCurrentServer" , serverId),
180
262
};
181
-
182
- // const handleSendIntent = async (intent) => {
183
- // intent.clipItems.forEach((el) => {
184
- // apiInstance.post("playlist", {
185
- // filename: el.text,
186
- // flag: "append-play",
187
- // });
188
- // });
189
- // };
190
- // const handleViewIntent = async (intent) => {
191
- // let headerArray = [];
192
- // if (Object.prototype.hasOwnProperty.call(intent.extras, "headers")) {
193
- // for (var i = 0; i < intent.extras.headers.length - 1; i += 2) {
194
- // headerArray.push(
195
- // `${intent.extras.headers[i]}: ${intent.extras.headers[i + 1]}`
196
- // );
197
- // }
198
- // }
199
- // if (Object.prototype.hasOwnProperty.call(intent, "data")) {
200
- // let reqData = {
201
- // filename: intent.data,
202
- // flag: "replace",
203
- // };
204
- // reqData["file-local-options"] = {};
205
- // if (headerArray.length > 0)
206
- // reqData["file-local-options"]["http-header-fields"] = headerArray;
207
- // if (Object.prototype.hasOwnProperty.call(intent.extras, "title"))
208
- // reqData["file-local-options"]["force-media-title"] =
209
- // intent.extras.title;
210
- // apiInstance.post("playlist", reqData);
211
- // }
212
- // };
213
- // const handleIntent = async (intent) => {
214
- // // console.log("Full intent object" + JSON.stringify(intent));
215
- // if (Object.prototype.hasOwnProperty.call(intent, "action")) {
216
- // switch (intent.action) {
217
- // case AndroindIntentActions.SEND:
218
- // handleSendIntent(intent);
219
- // break;
220
- // case AndroindIntentActions.VIEW:
221
- // handleViewIntent(intent);
222
- // break;
223
- // default:
224
- // break;
225
- // }
226
- // }
227
- // };
228
- // const registerBroadcastReceiver = () => {
229
- // window.plugins.intentShim.registerBroadcastReceiver(
230
- // {
231
- // filterActions: [
232
- // "com.darryncampbell.cordova.plugin.broadcastIntent.ACTION",
233
- // ],
234
- // },
235
- // (intent) => {
236
- // // Broadcast received
237
- // handleIntent(intent);
238
- // }
239
- // );
240
- // };
241
- // const unregisterBroadcastReceiver = () => {
242
- // window.plugins.intentShim.unregisterBroadcastReceiver();
243
- // };
244
- // const setServer = async (item) => {
245
- // console.log("Connecting to server:");
246
- // console.log(item.target);
247
- // // connect(item.detail.value);
248
- // };
249
- // const initApp = () => {
250
- // console.log("Init app");
251
- // store.dispatch("settings/loadSettings").then(async () => {
252
- // // await connect(store.state.settings.settings.currentServerId);
253
- // await store.dispatch(
254
- // "simpleapi/connectToServer",
255
- // store.getters["settings/currentServerId"]
256
- // );
257
- // // Register intent handling
258
- // // Intent handling only for mobile apps!
259
- // if (platforms.includes("hybrid")) {
260
- // console.log("Registering indent");
261
- // registerBroadcastReceiver();
262
- // window.plugins.intentShim.onIntent((intent) => {
263
- // handleIntent(intent);
264
- // });
265
- // }
266
- // apiInstance.get("/status").then((response) => {
267
- // store.commit("simpleapi/setPlayerData", response.data);
268
- // });
269
- // store.dispatch("simpleapi/setPlaybackRefreshInterval");
270
- // });
271
- // window.addEventListener("orientationchange", function () {
272
- // store.commit("app/setScreenOrinetation", screen.orientation.type);
273
- // });
274
- // };
275
- // // we should call initApp also on debug builds
276
- // if (!platforms.includes("hybrid")) initApp();
277
- // document.addEventListener("deviceReady", () => initApp());
278
- // App.addListener("appStateChange", ({ isActive }) => {
279
- // if (isActive) {
280
- // // Set screen orientation if active
281
- // store.commit("app/setScreenOrinetation", screen.orientation.type);
282
- // apiInstance.get("/status").then((response) => {
283
- // store.commit("simpleapi/setPlayerData", response.data);
284
- // });
285
- // if (!store.state.simpleapi.playbackRefreshInterval) {
286
- // store.dispatch("simpleapi/setPlaybackRefreshInterval");
287
- // }
288
- // if (platforms.includes("hybrid")) registerBroadcastReceiver();
289
- // } else {
290
- // // Battery saving stuff
291
- // store.commit("simpleapi/clearPlaybackRefreshInterval");
292
- // if (platforms.includes("hybrid")) unregisterBroadcastReceiver();
293
- // }
294
- // });
295
- // return {
296
- // selectedIndex,
297
- // appPages,
298
- // cogOutline,
299
- // informationCircleOutline,
300
- // listOutline,
301
- // playCircleOutline,
302
- // version: appInfo.version,
303
- // connectionState: store.getters["simpleapi/connectionState"],
304
- // servers: store.getters["settings/servers"],
305
- // currentServerId: store.getters["settings/currentServerId"],
306
- // setServer,
307
- // isSelected: (url) => (url === route.path ? "selected" : ""),
308
- // };
309
263
},
310
264
});
311
265
</script >
0 commit comments