Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compatibility.js « compatibility - github.com/PhieF/CarnetElectron.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d5f0088d1faed7188d1467b50b1f9a318b2f8b87 (plain)
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
var compatRequire = undefined
class Compatibility {
    constructor() {
        this.isElectron = typeof require === "function" || typeof parent.require === "function";
        console.log("this.isElectron  " + this.isElectron)
        if (this.isElectron) {
            if (typeof require !== "function") {
                compatRequire = parent.require
            }
            else compatRequire = require
        }
        this.isAndroid = typeof app === "object";

        this.isGtk = false;
        console.log("isAndroid" + this.isAndroid)

        if (this.isElectron) {
            RequestBuilder = ElectronRequestBuilder;
            console.log("set resquest builder")
        }
        if (this.isAndroid) {
            $(document).on('ajaxSend', function (elm, xhr, settings) {
                if (settings.crossDomain === false) {
                    xhr.setRequestHeader('requesttoken', app.getRequestToken());
                    xhr.setRequestHeader('OCS-APIREQUEST', 'true');
                }
            });
        }
    }
    addRequestToken(url) {
        if (this.isAndroid) {
            if (url.indexOf("?") > -1)
                url += "&"
            else url += "?"
            url += "requesttoken=" + app.getRequestToken()
        }
        return url;
    }
    openUrl(url) {
        if (compatibility.isElectron) {
            var {
                shell
            } = require('electron');
            shell.openExternal(url);
        } else if (compatibility.isAndroid) {
            app.openUrl(url)
        } else {
            var win = window.open(url, '_blank');
            win.focus();
        }
    }

    loadLang(callback) {
        RequestBuilder.sRequestBuilder.get('settings/lang/json?lang=tot', function (error, data) {
            $.i18n().load(data).done(callback)
        })

    }

    getStore() {
        if (this.isElectron) {
            return ElectronStore;
        }
        else
            return NextcloudStore;
    }

    openElectronSyncDialog() {
        var {
            remote
        } = require('electron');
        const BrowserWindow = remote.BrowserWindow;

        var win = new BrowserWindow({
            width: 500,
            height: 500,
            frame: true,
            webPreferences: {
                nodeIntegration: true,
                webviewTag: true,
                enableRemoteModule: true,
                contextIsolation: false,
            }
        });
        const url = require('url')
        const path = require('path')
        win.loadURL(url.format({
            pathname: path.join(__dirname, 'settings/webdav_dialog.html'),
            protocol: 'file:',
            slashes: true
        }))
        win.setMenu(null)
    }

    sendNextLargeDownload() {
        if (this.largeDownload == undefined) {
            if (currentFrame != undefined) {
                currentFrame.contentWindow.compatibility.sendNextLargeDownload()
                return
            }
            return
        }
        if (this.largeDownload.length <= 0) {
            app.onLargeDownloadEnd()
            this.largeDownload = undefined
        } else {
            var nextSize = this.largeDownload.length > 200000 ? 200000 : this.largeDownload.length
            var next = this.largeDownload.substring(0, nextSize)
            this.largeDownload = this.largeDownload.substring(nextSize)

            app.onNextLargeDownload(next)

        }
    }
}